Commit 43e4e916 authored by Stefan Haslinger's avatar Stefan Haslinger

refactoring: Tag, TagGroup, LapTagging, ActivityTagging inheriting from Db classes directly

parent 8e26898b
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_secure_storage","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"path_provider","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.7/","dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"path_provider","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.7/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+2/","dependencies":[]},{"name":"shared_preferences_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+8/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"url_launcher_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+5/","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"shared_preferences_web","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+5/","dependencies":[]},{"name":"url_launcher_web","path":"/daten/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-06-07 18:10:44.190546","version":"1.17.0-4.0.pre.7"}
\ 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":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"path_provider","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.7/","dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"path_provider","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.7/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+2/","dependencies":[]},{"name":"shared_preferences_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+8/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"url_launcher_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+5/","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"shared_preferences_web","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+5/","dependencies":[]},{"name":"url_launcher_web","path":"/daten/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-06-08 09:28:56.414973","version":"1.17.0-4.0.pre.7"}
\ No newline at end of file
......@@ -56,7 +56,7 @@ class ActivityList<E> extends DelegatingList<E> {
if (tagGroups != null && athlete.filters.isNotEmpty) {
// get active filters for TagGroup
for (final TagGroup tagGroup in tagGroups) {
tagIds = tagGroup.cachedTags.map((Tag tag) => tag.db.id).toList();
tagIds = tagGroup.cachedTags.map((Tag tag) => tag.id).toList();
tagIds.removeWhere((int tagId) => !athlete.filters.contains(tagId));
// If there are restrictions for this group:
......
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/tag.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/model/model.dart';
import 'package:sqfentity_gen/sqfentity_gen.dart';
import 'package:encrateia/model/model.dart' show DbActivityTagging;
class ActivityTagging extends ChangeNotifier {
ActivityTagging({
class ActivityTagging extends DbActivityTagging {
ActivityTagging();
ActivityTagging.by({
@required Activity activity,
@required Tag tag,
bool system,
}) {
db = DbActivityTagging()
..activitiesId = activity.db.id
..tagsId = tag.db.id
..system = system ?? false;
}
ActivityTagging.fromDb(this.db);
DbActivityTagging db;
bool system = false,
}) : super(
activitiesId: activity.db.id,
tagsId: tag.id,
system: system,
);
static Future<ActivityTagging> createBy({
@required Activity activity,
@required Tag tag,
bool system,
}) async {
final DbActivityTagging dbActivityTagging = await DbActivityTagging()
final ActivityTagging activityTagging = await ActivityTagging()
.select()
.activitiesId
.equals(activity.db.id)
.and
.tagsId
.equals(tag.db.id)
.toSingle();
.equals(tag.id)
.toSingle() as ActivityTagging;
if (dbActivityTagging != null)
return ActivityTagging.fromDb(dbActivityTagging);
if (activityTagging != null)
return activityTagging;
else {
final ActivityTagging activityTagging = ActivityTagging(
activity: activity, tag: tag, system: system ?? false);
await activityTagging.db.save();
final ActivityTagging activityTagging = ActivityTagging.by(
activity: activity,
tag: tag,
system: system ?? false,
);
await activityTagging.save();
return activityTagging;
}
}
......@@ -48,17 +47,15 @@ class ActivityTagging extends ChangeNotifier {
@required Activity activity,
@required Tag tag,
}) async {
final DbActivityTagging dbActivityTagging = await DbActivityTagging()
final ActivityTagging activityTagging = await ActivityTagging()
.select()
.activitiesId
.equals(activity.db.id)
.and
.tagsId
.equals(tag.db.id)
.toSingle();
if (dbActivityTagging != null)
return ActivityTagging.fromDb(dbActivityTagging);
return null;
.equals(tag.id)
.toSingle() as ActivityTagging;
return activityTagging;
}
static Future<void> deleteBy({
......@@ -71,14 +68,12 @@ class ActivityTagging extends ChangeNotifier {
.equals(activity.db.id)
.and
.tagsId
.equals(tag.db.id)
.equals(tag.id)
.toSingle();
await dbActivityTagging.delete();
}
@override
String toString() =>
'< ActivityTagging | actvityId ${db.activitiesId} | tagId ${db.tagsId} >';
Future<BoolResult> delete() async => await db.delete();
'< ActivityTagging | actvityId $activitiesId | tagId $tagsId >';
}
import 'package:encrateia/models/lap.dart';
import 'package:encrateia/models/tag.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/model/model.dart';
import 'package:sqfentity_gen/sqfentity_gen.dart';
import 'package:encrateia/model/model.dart' show DbLapTagging ;
class LapTagging extends ChangeNotifier {
LapTagging({
class LapTagging extends DbLapTagging {
LapTagging();
LapTagging.by({
@required Lap lap,
@required Tag tag,
bool system,
}) {
db = DbLapTagging()
..lapsId = lap.db.id
..tagsId = tag.db.id
..system = system ?? false;
}
LapTagging.fromDb(this.db);
DbLapTagging db;
bool system = false,
}) : super(
lapsId: lap.db.id,
tagsId: tag.id,
system: system,
);
static Future<LapTagging> createBy({
@required Lap lap,
@required Tag tag,
bool system,
}) async {
final DbLapTagging dbLapTagging = await DbLapTagging()
final LapTagging lapTagging = await LapTagging()
.select()
.lapsId
.equals(lap.db.id)
.and
.tagsId
.equals(tag.db.id)
.toSingle();
.equals(tag.id)
.toSingle() as LapTagging;
if (dbLapTagging != null)
return LapTagging.fromDb(dbLapTagging);
if (lapTagging != null)
return lapTagging;
else {
final LapTagging lapTagging = LapTagging(
final LapTagging lapTagging = LapTagging.by(
lap: lap,
tag: tag,
system: system ?? false,
);
await lapTagging.db.save();
await lapTagging.save();
return lapTagging;
}
}
......@@ -51,35 +47,33 @@ class LapTagging extends ChangeNotifier {
@required Lap lap,
@required Tag tag,
}) async {
final DbLapTagging dbLapTagging = await DbLapTagging()
final LapTagging lapTagging = await LapTagging()
.select()
.lapsId
.equals(lap.db.id)
.and
.tagsId
.equals(tag.db.id)
.toSingle();
return (dbLapTagging != null) ? LapTagging.fromDb(dbLapTagging) : null;
.equals(tag.id)
.toSingle() as LapTagging;
return lapTagging;
}
static Future<void> deleteBy({
@required Lap lap,
@required Tag tag,
}) async {
final DbLapTagging dbLapTagging = await DbLapTagging()
final LapTagging lapTagging = await LapTagging()
.select()
.lapsId
.equals(lap.db.id)
.and
.tagsId
.equals(tag.db.id)
.toSingle();
await dbLapTagging.delete();
.equals(tag.id)
.toSingle() as LapTagging;
await lapTagging.delete();
}
@override
String toString() =>
'< LapTagging | lapId ${db.lapsId} | tagId ${db.tagsId} >';
Future<BoolResult> delete() async => await db.delete();
'< LapTagging | lapId $lapsId | tagId $tagsId >';
}
import 'package:flutter/material.dart';
import 'package:encrateia/model/model.dart';
import 'package:encrateia/model/model.dart' show DbTag;
import 'package:encrateia/models/tag_group.dart';
import 'package:sqfentity_gen/sqfentity_gen.dart';
import 'package:encrateia/models/activity_tagging.dart';
import 'activity.dart';
import 'athlete.dart';
class Tag extends ChangeNotifier {
Tag({
class Tag extends DbTag {
Tag();
Tag.minimal({
@required TagGroup tagGroup,
String name,
int color,
int sortOrder,
}) {
db = DbTag()
..tagGroupsId = tagGroup.db.id
..sortOrder = sortOrder ?? 0
..name = name ?? 'my Tag'
..color = color ?? 0xFFFFc107;
}
Tag.fromDb(this.db);
String name = 'my Tag',
int color = 0xFFFFc107,
int sortOrder = 0,
bool system = false,
}) : super(
name: name,
color: color,
sortOrder: sortOrder,
tagGroupsId: tagGroup.id,
system: system,
);
Tag.by({
@required TagGroup tagGroup,
@required String name,
@required int color,
@required int sortOrder,
@required bool system,
}) : super(
name: name,
color: color,
sortOrder: sortOrder,
tagGroupsId: tagGroup.id,
system: system,
);
DbTag db;
bool selected = false;
@override
String toString() => '< Tag | ${db.name} >';
Future<BoolResult> delete() async => await db.delete();
String toString() => '< Tag | $name >';
static Future<List<Tag>> all({@required TagGroup tagGroup}) async {
final List<DbTag> dbTags = await tagGroup.db
final List<Tag> tags = await tagGroup
.getDbTags()
.orderBy('sortOrder')
.orderBy('name')
.toList();
final List<Tag> tags =
dbTags.map((DbTag dbTag) => Tag.fromDb(dbTag)).toList();
.toList() as List<Tag>;
return tags;
}
static Future<List<Tag>> allByActivity({@required Activity activity}) async {
final List<DbActivityTagging> dbActivityTaggings = await DbActivityTagging()
final List<ActivityTagging> activityTaggings = await ActivityTagging()
.select()
.activitiesId
.equals(activity.db.id)
.toList();
if (dbActivityTaggings.isNotEmpty) {
final List<DbTag> dbTags = await DbTag()
.toList() as List<ActivityTagging>;
if (activityTaggings.isNotEmpty) {
final List<Tag> tags = await Tag()
.select()
.id
.inValues(dbActivityTaggings.map(
(DbActivityTagging dbActivityTagging) =>
dbActivityTagging.tagsId).toList())
.toList();
final List<Tag> tags =
dbTags.map((DbTag dbTag) => Tag.fromDb(dbTag)).toList();
.inValues(activityTaggings
.map((ActivityTagging activityTagging) => activityTagging.tagsId)
.toList())
.toList() as List<Tag>;
return tags;
} else {
return <Tag>[];
......@@ -75,7 +83,7 @@ class Tag extends ChangeNotifier {
dbPowerTag = await DbTag()
.select()
.tagGroupsId
.equals(autoPowerTagGroup.db.id)
.equals(autoPowerTagGroup.id)
.and
.name
.equals(name)
......@@ -83,14 +91,14 @@ class Tag extends ChangeNotifier {
if (dbPowerTag == null) {
dbPowerTag = DbTag()
..tagGroupsId = autoPowerTagGroup.db.id
..tagGroupsId = autoPowerTagGroup.id
..color = color
..sortOrder = sortOrder
..name = name
..system = true;
await dbPowerTag.save();
}
return Tag.fromDb(dbPowerTag);
return dbPowerTag as Tag;
}
static Future<Tag> autoHeartRateTag({
......@@ -99,28 +107,29 @@ class Tag extends ChangeNotifier {
@required int sortOrder,
@required int color,
}) async {
DbTag dbHeartRateTag;
Tag heartRateTag;
final TagGroup autoHeartRateTagGroup =
await TagGroup.autoHeartRateTagGroup(athlete: athlete);
dbHeartRateTag = await DbTag()
heartRateTag = await Tag()
.select()
.tagGroupsId
.equals(autoHeartRateTagGroup.db.id)
.equals(autoHeartRateTagGroup.id)
.and
.name
.equals(name)
.toSingle();
.toSingle() as Tag;
if (dbHeartRateTag == null) {
dbHeartRateTag = DbTag()
..tagGroupsId = autoHeartRateTagGroup.db.id
..color = color
..sortOrder = sortOrder
..name = name
..system = true;
await dbHeartRateTag.save();
if (heartRateTag == null) {
heartRateTag = Tag.by(
tagGroup: autoHeartRateTagGroup,
color: color,
sortOrder: sortOrder,
name: name,
system: true,
);
await heartRateTag.save();
}
return Tag.fromDb(dbHeartRateTag);
return heartRateTag;
}
}
import 'package:encrateia/models/tag.dart';
import 'package:encrateia/utils/my_color.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/model/model.dart';
import 'package:encrateia/model/model.dart' show DbTagGroup;
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/activity.dart';
import 'package:sqfentity_gen/sqfentity_gen.dart';
import 'package:encrateia/models/activity_tagging.dart';
import 'lap.dart';
import 'lap_tagging.dart';
class TagGroup extends ChangeNotifier {
TagGroup({@required Athlete athlete}) {
db = DbTagGroup()
..athletesId = athlete.db.id
..color = Colors.lightGreen.value
..system = false
..name = 'My Tag Group';
}
class TagGroup extends DbTagGroup {
TagGroup();
TagGroup.fromDb(this.db);
TagGroup.minimal({@required Athlete athlete})
: super(
athletesId: athlete.db.id,
color: Colors.lightGreen.value,
system: false,
name: 'My Tag Group',
);
TagGroup.by(
{@required Athlete athlete,
@required String name,
@required bool system,
@required int color}) {
db = DbTagGroup()
..athletesId = athlete.db.id
..color = color
..system = system
..name = name;
}
@required int color})
: super(
athletesId: athlete.db.id,
color: color,
system: system,
name: name,
);
DbTagGroup db;
List<Tag> cachedTags;
Future<List<Tag>> get tags async => await Tag.all(tagGroup: this);
@override
String toString() => '< Taggroup | ${db.name} >';
Future<BoolResult> delete() async => await db.delete();
String toString() => '< TagGroup | $name >';
static Future<TagGroup> autoPowerTagGroup({@required Athlete athlete}) async {
final DbTagGroup dbTagGroup = await DbTagGroup()
final TagGroup tagGroup = await TagGroup()
.select()
.system
.equals(true)
......@@ -51,9 +49,9 @@ class TagGroup extends ChangeNotifier {
.and
.name
.equals('Auto Power Zones')
.toSingle();
if (dbTagGroup != null)
return TagGroup.fromDb(dbTagGroup);
.toSingle() as TagGroup;
if (tagGroup != null)
return tagGroup;
else {
final TagGroup autoPowerTagGroup = TagGroup.by(
name: 'Auto Power Zones',
......@@ -61,14 +59,14 @@ class TagGroup extends ChangeNotifier {
system: true,
color: MyColor.bitterSweet.value,
);
await autoPowerTagGroup.db.save();
await autoPowerTagGroup.save();
return autoPowerTagGroup;
}
}
static Future<TagGroup> autoHeartRateTagGroup(
{@required Athlete athlete}) async {
final DbTagGroup dbTagGroup = await DbTagGroup()
final TagGroup tagGroup = await TagGroup()
.select()
.system
.equals(true)
......@@ -78,9 +76,9 @@ class TagGroup extends ChangeNotifier {
.and
.name
.equals('Auto Heart Rate Zones')
.toSingle();
if (dbTagGroup != null)
return TagGroup.fromDb(dbTagGroup);
.toSingle() as TagGroup;
if (tagGroup != null)
return tagGroup;
else {
final TagGroup autoHeartRateTagGroup = TagGroup.by(
name: 'Auto Heart Rate Zones',
......@@ -88,7 +86,7 @@ class TagGroup extends ChangeNotifier {
system: true,
color: MyColor.grapeFruit.value,
);
await autoHeartRateTagGroup.db.save();
await autoHeartRateTagGroup.save();
return autoHeartRateTagGroup;
}
}
......@@ -99,18 +97,18 @@ class TagGroup extends ChangeNotifier {
}) async {
final List<TagGroup> tagGroups = await all(athlete: athlete);
final List<DbActivityTagging> dbActivityTaggings = await DbActivityTagging()
final List<ActivityTagging> activityTaggings = await ActivityTagging()
.select()
.activitiesId
.equals(activity.db.id)
.toList();
final Iterable<int> selectedTagIds = dbActivityTaggings
.map((DbActivityTagging dbActivityTagging) => dbActivityTagging.tagsId);
.toList() as List<ActivityTagging>;
final Iterable<int> selectedTagIds = activityTaggings
.map((ActivityTagging activityTagging) => activityTagging.tagsId);
for (final TagGroup tagGroup in tagGroups) {
tagGroup.cachedTags = await tagGroup.tags;
for (final Tag tag in tagGroup.cachedTags) {
tag.selected = selectedTagIds.contains(tag.db.id);
tag.selected = selectedTagIds.contains(tag.id);
}
}
return tagGroups;
......@@ -122,27 +120,29 @@ class TagGroup extends ChangeNotifier {
}) async {
final List<TagGroup> tagGroups = await all(athlete: athlete);
final List<DbLapTagging> dbLapTaggings =
await DbLapTagging().select().lapsId.equals(lap.db.id).toList();
final List<LapTagging> lapTaggings = await LapTagging()
.select()
.lapsId
.equals(lap.db.id)
.toList() as List<LapTagging>;
final Iterable<int> selectedTagIds =
dbLapTaggings.map((DbLapTagging dbLapTagging) => dbLapTagging.tagsId);
lapTaggings.map((LapTagging lapTagging) => lapTagging.tagsId);
for (final TagGroup tagGroup in tagGroups) {
tagGroup.cachedTags = await tagGroup.tags;
for (final Tag tag in tagGroup.cachedTags) {
tag.selected = selectedTagIds.contains(tag.db.id);
tag.selected = selectedTagIds.contains(tag.id);
}
}
return tagGroups;
}
static Future<List<TagGroup>> all({@required Athlete athlete}) async {
final List<DbTagGroup> dbTagGroupList =
await athlete.db.getDbTagGroups().orderBy('name').toList();
final List<TagGroup> tagGroups = dbTagGroupList
.map((DbTagGroup dbTagGroup) => TagGroup.fromDb(dbTagGroup))
.toList();
final List<TagGroup> tagGroups = await athlete.db
.getDbTagGroups()
.orderBy('name')
.toList() as List<TagGroup>;
for (final TagGroup tagGroup in tagGroups) {
tagGroup.cachedTags = await tagGroup.tags;
......@@ -153,10 +153,10 @@ class TagGroup extends ChangeNotifier {
static Future<void> deleteAllAutoTags({Athlete athlete}) async {
final TagGroup autoPowerTagGroup =
await TagGroup.autoPowerTagGroup(athlete: athlete);
await autoPowerTagGroup.db.getDbTags().delete();
await autoPowerTagGroup.getDbTags().delete();
final TagGroup autoHeartRateTagGroup =
await TagGroup.autoHeartRateTagGroup(athlete: athlete);
await autoHeartRateTagGroup.db.getDbTags().delete();
await autoHeartRateTagGroup.getDbTags().delete();
}
}
......@@ -55,36 +55,36 @@ class _AddFilterScreenState extends State<AddFilterScreen> {
itemCount: tagGroups == null ? 0 : tagGroups.length,
itemBuilder: (BuildContext context, int index) => Card(
child: ListTile(
title: Text(tagGroups[index].db.name),
title: Text(tagGroups[index].name),
subtitle: Wrap(
spacing: 10,
children: <Widget>[
for (Tag tag in tagGroups[index].cachedTags)
FilterChip(
label: Text(
tag.db.name,
tag.name,
style: TextStyle(
color: MyColor.textColor(
selected:
widget.athlete.filters.contains(tag.db.id),
backgroundColor: Color(tag.db.color ?? 99999),
widget.athlete.filters.contains(tag.id),
backgroundColor: Color(tag.color ?? 99999),
),
),
),
avatar: CircleAvatar(
backgroundColor: Color(tag.db.color ?? 99999),
backgroundColor: Color(tag.color ?? 99999),
),
onSelected: (bool selected) {
setState(() {
if (selected)