Commit 2d3369c2 authored by Administrator's avatar Administrator

tags on lap level, including bug: new taggroup contains all tags

parent 0b162356
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_secure_storage","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"path_provider","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.7/","dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"path_provider","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.7/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+2/","dependencies":[]},{"name":"shared_preferences_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+8/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"url_launcher_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+5/","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"shared_preferences_web","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+5/","dependencies":[]},{"name":"url_launcher_web","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-0.1.1+5/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]},{"name":"uni_links","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_web","url_launcher_macos"]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2020-05-15 14:29:11.956456","version":"1.17.1"}
\ No newline at end of file
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_secure_storage","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"path_provider","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.7/","dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"path_provider","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.7/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+2/","dependencies":[]},{"name":"shared_preferences_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+8/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"url_launcher_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+5/","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"shared_preferences_web","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+5/","dependencies":[]},{"name":"url_launcher_web","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-0.1.1+5/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]},{"name":"uni_links","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_web","url_launcher_macos"]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2020-05-15 19:03:35.227067","version":"1.17.1"}
\ No newline at end of file
import 'package:encrateia/models/lap.dart';
import 'package:encrateia/models/tag.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/model/model.dart';
class LapTagging extends ChangeNotifier {
DbLapTagging db;
LapTagging({
@required Lap lap,
@required Tag tag,
}) {
db = DbLapTagging()
..lapsId = lap.db.id
..tagsId = tag.db.id
..system = false;
}
LapTagging.fromDb(this.db);
static createBy({
@required Lap lap,
@required Tag tag,
}) async {
var dbLapTagging = await DbLapTagging()
.select()
.lapsId
.equals(lap.db.id)
.and
.tagsId
.equals(tag.db.id)
.toSingle();
if (dbLapTagging != null)
return LapTagging.fromDb(dbLapTagging);
else {
var lapTagging = LapTagging(
lap: lap,
tag: tag,
);
await lapTagging.db.save();
return lapTagging;
}
}
static getBy({
@required Lap lap,
@required Tag tag,
}) async {
var dbLapTagging = await DbLapTagging()
.select()
.lapsId
.equals(lap.db.id)
.and
.tagsId
.equals(tag.db.id)
.toSingle();
if (dbLapTagging != null)
return LapTagging.fromDb(dbLapTagging);
}
static deleteBy({
@required Lap lap,
@required Tag tag,
}) async {
var dbLapTagging = await DbLapTagging()
.select()
.lapsId
.equals(lap.db.id)
.and
.tagsId
.equals(tag.db.id)
.toSingle();
await dbLapTagging.delete();
}
String toString() =>
'< LapTagging | lapId ${db.lapsId} | tagId ${db.tagsId} >';
delete() async {
await this.db.delete();
}
}
......@@ -25,7 +25,9 @@ class Tag extends ChangeNotifier {
}
static Future<List<Tag>> all({@required TagGroup tagGroup}) async {
print(tagGroup.db.id);
var dbTagList = await tagGroup.db.getDbTags().orderBy('name').toList();
print(dbTagList.length);
var tags = dbTagList.map((dbTag) => Tag.fromDb(dbTag)).toList();
return tags;
}
......
......@@ -5,6 +5,8 @@ import 'package:encrateia/model/model.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/activity.dart';
import 'lap.dart';
class TagGroup extends ChangeNotifier {
DbTagGroup db;
List<Tag> cachedTags;
......@@ -16,13 +18,12 @@ class TagGroup extends ChangeNotifier {
..system = false
..name = "My Tag Group";
}
TagGroup.fromDb(this.db);
Future<List<Tag>> get tags async {
if (cachedTags == null) {
cachedTags = await Tag.all(tagGroup: this);
}
return cachedTags;
var tags = await Tag.all(tagGroup: this);
return tags;
}
TagGroup.by(
......@@ -81,7 +82,29 @@ class TagGroup extends ChangeNotifier {
tag.selected = selectedTagIds.contains(tag.db.id) ? true : false;
}
}
return tagGroups;
}
static includingLapTaggings({
@required Athlete athlete,
@required Lap lap,
}) async {
var tagGroups = await all(athlete: athlete);
var dbLapTaggings = await DbLapTagging()
.select()
.lapsId
.equals(lap.db.id)
.toList();
var selectedTagIds = dbLapTaggings
.map((DbLapTagging dbLapTagging) => dbLapTagging.id);
for (TagGroup tagGroup in tagGroups) {
var tags = await tagGroup.tags;
for (Tag tag in tags) {
tag.selected = selectedTagIds.contains(tag.db.id) ? true : false;
}
}
return tagGroups;
}
......@@ -92,6 +115,9 @@ class TagGroup extends ChangeNotifier {
.map((dbTagGroup) => TagGroup.fromDb(dbTagGroup))
.toList();
for (TagGroup tagGroup in tagGroups) {
tagGroup.cachedTags = await tagGroup.tags;
}
return tagGroups;
}
}
......@@ -11,6 +11,7 @@ import 'package:encrateia/widgets/lap_widgets/lap_ground_time_widget.dart';
import 'package:encrateia/widgets/lap_widgets/lap_leg_spring_stiffness_widget.dart';
import 'package:encrateia/widgets/lap_widgets/lap_form_power_widget.dart';
import 'package:encrateia/widgets/lap_widgets/lap_stryd_cadence_widget.dart';
import 'package:encrateia/widgets/lap_widgets/lap_tag_widget.dart';
import 'package:encrateia/widgets/lap_widgets/lap_vertical_oscillation_widget.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/lap.dart';
......@@ -126,6 +127,17 @@ class ShowLapScreen extends StatelessWidget {
context: context,
nextWidget: ({lap}) => LapMetadataWidget(lap: lap),
),
navigationButton(
title: "Tags",
color: MyColor.tag,
icon: MyIcon.tag,
context: context,
nextWidget: ({lap}) => LapTagWidget(
lap: lap,
athlete: athlete,
),
),
],
);
}),
......
import 'dart:ui';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/tag.dart';
import 'package:encrateia/models/activityTagging.dart';
import 'package:encrateia/models/activity_tagging.dart';
import 'package:encrateia/models/tag_group.dart';
import 'package:encrateia/utils/my_color.dart';
import 'package:flutter/material.dart';
......
import 'dart:ui';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/tag.dart';
import 'package:encrateia/models/lap_tagging.dart';
import 'package:encrateia/models/tag_group.dart';
import 'package:encrateia/utils/my_color.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/lap.dart';
class LapTagWidget extends StatefulWidget {
final Lap lap;
final Athlete athlete;
LapTagWidget({
@required this.lap,
@required this.athlete,
});
@override
_LapTagWidgetState createState() => _LapTagWidgetState();
}
class _LapTagWidgetState extends State<LapTagWidget> {
List<TagGroup> tagGroups;
@override
void initState() {
getData();
super.initState();
}
@override
Widget build(context) {
if (tagGroups == null)
return Center(child: Text("Loading ..."));
else
return ListTileTheme(
iconColor: MyColor.tag,
child: ListView.builder(
itemCount: tagGroups?.length ?? 0,
itemBuilder: (context, index) {
TagGroup tagGroup = tagGroups[index];
return Card(
child: ListTile(
contentPadding: EdgeInsets.all(20),
subtitle: Wrap(
spacing: 15,
children: [
for (Tag tag in tagGroup.cachedTags)
InputChip(
label: Text(
tag.db.name,
style: TextStyle(
color: MyColor.textColor(
selected: tag.selected,
backgroundColor: Color(tag.db.color),
),
),
),
avatar: CircleAvatar(
backgroundColor: Color(tag.db.color),
),
onSelected: (selected) {
setState(() {
if (selected) {
LapTagging.createBy(
lap: widget.lap,
tag: tag,
);
} else {
LapTagging.deleteBy(
lap: widget.lap,
tag: tag,
);
}
tag.selected = selected;
});
},
selected: tag.selected,
selectedColor: Color(tag.db.color),
backgroundColor: MyColor.white,
elevation: 3,
padding: EdgeInsets.all(10),
)
],
),
title: Text(tagGroup.db.name + "\n"),
),
);
},
),
);
}
getData() async {
tagGroups = await TagGroup.includingLapTaggings(
athlete: widget.athlete,
lap: widget.lap,
);
setState(() {});
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment