Commit 67a7abdc authored by Administrator's avatar Administrator

tags on interval level selectable, bugfix: reset interval after saving

parent b1b4056d
{"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":"package_info","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.11/","dependencies":[]},{"name":"shared_preferences","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.8/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.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.5.0/","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":"package_info","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.11/","dependencies":[]},{"name":"shared_preferences","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.8/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.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.5.0/","dependencies":[]}],"macos":[{"name":"package_info","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+3/","dependencies":[]},{"name":"shared_preferences_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+10/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.1/","dependencies":[]},{"name":"url_launcher_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+7/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.0.1+2/","dependencies":[]},{"name":"shared_preferences_linux","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-0.0.2+1/","dependencies":["path_provider_linux"]},{"name":"url_launcher_linux","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-0.0.1+1/","dependencies":[]}],"windows":[],"web":[{"name":"shared_preferences_web","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+7/","dependencies":[]},{"name":"url_launcher_web","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-0.1.2/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":[]},{"name":"package_info","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_linux","shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"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_linux","url_launcher_macos"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2020-09-08 18:19:27.926339","version":"1.20.3"}
\ 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":"package_info","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.11/","dependencies":[]},{"name":"shared_preferences","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.8/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.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.5.0/","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":"package_info","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.11/","dependencies":[]},{"name":"shared_preferences","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.8/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.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.5.0/","dependencies":[]}],"macos":[{"name":"package_info","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+3/","dependencies":[]},{"name":"shared_preferences_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+10/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.1/","dependencies":[]},{"name":"url_launcher_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+7/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.0.1+2/","dependencies":[]},{"name":"shared_preferences_linux","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-0.0.2+1/","dependencies":["path_provider_linux"]},{"name":"url_launcher_linux","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-0.0.1+1/","dependencies":[]}],"windows":[],"web":[{"name":"shared_preferences_web","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+7/","dependencies":[]},{"name":"url_launcher_web","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-0.1.2/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":[]},{"name":"package_info","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_linux","shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"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_linux","url_launcher_macos"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2020-09-09 10:04:16.230041","version":"1.20.3"}
\ No newline at end of file
import 'package:encrateia/models/interval.dart' as encrateia;
import 'package:encrateia/models/tag.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/model/model.dart' show DbIntervalTagging;
import 'package:sqfentity_gen/sqfentity_gen.dart';
class IntervalTagging {
IntervalTagging({
@required encrateia.Interval interval,
@required Tag tag,
bool system,
}) {
_db = DbIntervalTagging()
..intervalsId = interval.id
..tagsId = tag.id
..system = system ?? false;
}
IntervalTagging._fromDb(this._db);
DbIntervalTagging _db;
int get id => _db?.id;
int get intervalsId => _db.intervalsId;
int get tagsId => _db.tagsId;
@override
String toString() =>
'< IntervalTagging | intervalId $intervalsId | tagId $tagsId >';
Future<BoolResult> delete() async => await _db.delete();
Future<int> save() async => await _db.save();
static Future<IntervalTagging> createBy({
@required encrateia.Interval interval,
@required Tag tag,
bool system,
}) async {
final DbIntervalTagging dbIntervalTagging = await DbIntervalTagging()
.select()
.intervalsId
.equals(interval.id)
.and
.tagsId
.equals(tag.id)
.toSingle();
if (dbIntervalTagging != null)
return IntervalTagging._fromDb(dbIntervalTagging);
else {
final IntervalTagging intervalTagging = IntervalTagging(
interval: interval,
tag: tag,
system: system ?? false,
);
await intervalTagging.save();
return intervalTagging;
}
}
static Future<IntervalTagging> getBy({
@required encrateia.Interval interval,
@required Tag tag,
}) async {
final DbIntervalTagging dbIntervalTagging = await DbIntervalTagging()
.select()
.intervalsId
.equals(interval.id)
.and
.tagsId
.equals(tag.id)
.toSingle();
return (dbIntervalTagging != null)
? IntervalTagging._fromDb(dbIntervalTagging)
: null;
}
static Future<void> deleteBy({
@required encrateia.Interval interval,
@required Tag tag,
}) async {
final DbIntervalTagging dbIntervalTagging = await DbIntervalTagging()
.select()
.intervalsId
.equals(interval.id)
.and
.tagsId
.equals(tag.id)
.toSingle();
await dbIntervalTagging.delete();
}
static IntervalTagging exDb(DbIntervalTagging db) =>
IntervalTagging._fromDb(db);
}
......@@ -2,10 +2,11 @@ import 'package:encrateia/models/tag.dart';
import 'package:encrateia/utils/my_color.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/model/model.dart'
show DbActivityTagging, DbLapTagging, DbTag, DbTagGroup;
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/activity.dart';
show DbActivityTagging, DbLapTagging, DbIntervalTagging, DbTag, DbTagGroup;
import 'package:sqfentity_gen/sqfentity_gen.dart' show BoolResult;
import 'activity.dart';
import 'athlete.dart';
import 'interval.dart' as encrateia;
import 'lap.dart';
class TagGroup {
......@@ -175,6 +176,27 @@ class TagGroup {
return tagGroups;
}
static Future<List<TagGroup>> includingIntervalTaggings({
@required Athlete athlete,
@required encrateia.Interval interval,
}) async {
final List<TagGroup> tagGroups = await athlete.tagGroups;
final List<DbIntervalTagging> dbIntervalTaggings =
await DbIntervalTagging().select().intervalsId.equals(interval.id).toList();
final Iterable<int> selectedTagIds =
dbIntervalTaggings.map((DbIntervalTagging dbIntervalTagging) => dbIntervalTagging.tagsId);
for (final TagGroup tagGroup in tagGroups) {
tagGroup.cachedTags = await tagGroup.tags;
for (final Tag tag in tagGroup.cachedTags) {
tag.selected = selectedTagIds.contains(tag.id);
}
}
return tagGroups;
}
static Future<List<TagGroup>> allByAthlete({Athlete athlete}) async
{
final List<DbTagGroup> dbTagGroups = await DbTagGroup()
......
......@@ -15,6 +15,7 @@ import 'package:encrateia/widgets/interval_widgets/interval_power_duration.dart'
import 'package:encrateia/widgets/interval_widgets/interval_power_widget.dart';
import 'package:encrateia/widgets/interval_widgets/interval_speed_widget.dart';
import 'package:encrateia/widgets/interval_widgets/interval_stryd_cadence_widget.dart';
import 'package:encrateia/widgets/interval_widgets/interval_tag_widget.dart';
import 'package:encrateia/widgets/interval_widgets/interval_vertical_oscillation_widget.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/utils/icon_utils.dart';
......@@ -156,13 +157,15 @@ class ShowIntervalScreen extends StatelessWidget {
IntervalAltitudeWidget(interval: interval),
),
navigationButton(
title: 'Tags',
color: MyColor.tag,
icon: MyIcon.tag,
context: context,
nextWidget: ({encrateia.Interval interval}) => const Text(
'') // IntervalTagWidget( interval: interval, athlete: athlete, ),
),
title: 'Tags',
color: MyColor.tag,
icon: MyIcon.tag,
context: context,
nextWidget: ({encrateia.Interval interval}) => IntervalTagWidget(
interval: interval,
athlete: athlete,
),
),
RaisedButton.icon(
color: MyColor.delete,
icon: MyIcon.delete,
......
......@@ -303,11 +303,10 @@ class _ActivityIntervalsChartState extends State<ActivityIntervalsChart> {
record.id <= interval.firstRecordId &&
record.id <= interval.lastRecordId)
.toList());
interval.athletesId = widget.athlete.id;
interval.activitiesId = widget.activity.id;
await interval.calculateAndSave(records: records);
widget.activity.cachedIntervals = <encrateia.Interval>[];
setState(() {});
interval = encrateia.Interval();
getData();
},
),
const SizedBox(width: 20),
......
import 'dart:ui';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/tag.dart';
import 'package:encrateia/models/interval_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/interval.dart' as encrateia;
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
class IntervalTagWidget extends StatefulWidget {
const IntervalTagWidget({
@required this.interval,
@required this.athlete,
});
final encrateia.Interval interval;
final Athlete athlete;
@override
_IntervalTagWidgetState createState() => _IntervalTagWidgetState();
}
class _IntervalTagWidgetState extends State<IntervalTagWidget> {
List<TagGroup> tagGroups;
@override
void initState() {
getData();
super.initState();
}
@override
void didUpdateWidget(IntervalTagWidget oldWidget) {
getData();
super.didUpdateWidget(oldWidget);
}
@override
Widget build(BuildContext context) {
if (tagGroups == null)
return const Center(
child: Text('Loading ...'),
);
else
return StaggeredGridView.countBuilder(
crossAxisCount:
MediaQuery.of(context).orientation == Orientation.portrait ? 2 : 3,
itemCount: tagGroups.length,
itemBuilder: (BuildContext context, int index) => Card(
child: ListTile(
title: Text(tagGroups[index].name + '\n'),
subtitle: Wrap(
spacing: 15,
children: <Widget>[
for (Tag tag in tagGroups[index].cachedTags)
InputChip(
isEnabled: tag.system != true,
label: Text(
tag.name,
style: TextStyle(
color: MyColor.textColor(
selected: tag.selected,
backgroundColor: Color(tag.color),
),
),
),
avatar: CircleAvatar(
backgroundColor: Color(tag.color),
),
onSelected: (bool selected) {
setState(() {
if (selected) {
IntervalTagging.createBy(interval: widget.interval, tag: tag);
} else {
IntervalTagging.deleteBy(interval: widget.interval, tag: tag);
}
tag.selected = selected;
});
},
selected: tag.selected,
selectedColor: Color(tag.color),
backgroundColor: MyColor.white,
elevation: 3,
padding: const EdgeInsets.all(10),
)
],
),
),
),
staggeredTileBuilder: (_) => const StaggeredTile.fit(1),
mainAxisSpacing: 3,
crossAxisSpacing: 3,
);
}
Future<void> getData() async {
tagGroups = await TagGroup.includingIntervalTaggings(
athlete: widget.athlete,
interval: widget.interval,
);
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