diff --git a/lib/theme/theme.dart b/lib/theme/theme.dart index ca41f5395..b57687f09 100644 --- a/lib/theme/theme.dart +++ b/lib/theme/theme.dart @@ -1,9 +1,14 @@ +import 'package:charts_flutter/flutter.dart' as charts; import 'package:flutter/material.dart'; const Color wgerPrimaryColor = Color(0xff2a4c7d); const Color wgerPrimaryButtonColor = Color(0xff266dd3); const Color wgerSecondaryColor = Color(0xffe63946); +// Chart colors +const charts.Color wgerChartPrimaryColor = charts.Color(r: 0x2a, g: 0x4c, b: 0x7d); +const charts.Color wgerChartSecondaryColor = charts.Color(r: 0xe6, g: 0x39, b: 0x46); + final ThemeData wgerTheme = ThemeData( /* * General stuff diff --git a/lib/widgets/weight/entries_list.dart b/lib/widgets/weight/entries_list.dart index 75a3e986b..67c25c465 100644 --- a/lib/widgets/weight/entries_list.dart +++ b/lib/widgets/weight/entries_list.dart @@ -1,62 +1,87 @@ +import 'package:charts_flutter/flutter.dart' as charts; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; +import 'package:wger/models/body_weight/weight_entry.dart'; import 'package:wger/providers/body_weight.dart'; +import 'package:wger/theme/theme.dart'; class WeightEntriesList extends StatelessWidget { @override Widget build(BuildContext context) { final weightEntriesData = Provider.of(context); - return ListView.builder( - padding: const EdgeInsets.all(10.0), - itemCount: weightEntriesData.items.length, - itemBuilder: (context, index) { - final currentEntry = weightEntriesData.items[index]; - return Dismissible( - key: Key(currentEntry.id.toString()), - onDismissed: (direction) { - // Delete workout from DB - Provider.of(context, listen: false).deleteEntry(currentEntry.id); + return Column( + children: [ + Container( + padding: EdgeInsets.all(15), + height: 220, + child: charts.TimeSeriesChart( + [ + charts.Series( + id: 'Weight', + colorFn: (_, __) => wgerChartSecondaryColor, + domainFn: (WeightEntry weightEntry, _) => weightEntry.date, + measureFn: (WeightEntry weightEntry, _) => weightEntry.weight, + data: weightEntriesData.items, + ) + ], + defaultRenderer: new charts.LineRendererConfig(includePoints: true), + ), + ), + Expanded( + child: ListView.builder( + padding: const EdgeInsets.all(10.0), + itemCount: weightEntriesData.items.length, + itemBuilder: (context, index) { + final currentEntry = weightEntriesData.items[index]; + return Dismissible( + key: Key(currentEntry.id.toString()), + onDismissed: (direction) { + // Delete workout from DB + Provider.of(context, listen: false).deleteEntry(currentEntry.id); - // and inform the user - Scaffold.of(context).showSnackBar( - SnackBar( - content: Text( - "Weight entry for the ${currentEntry.date}", - textAlign: TextAlign.center, + // and inform the user + Scaffold.of(context).showSnackBar( + SnackBar( + content: Text( + "Weight entry for the ${currentEntry.date}", + textAlign: TextAlign.center, + ), + ), + ); + }, + background: Container( + color: Theme.of(context).errorColor, + alignment: Alignment.centerRight, + padding: EdgeInsets.only(right: 20), + margin: EdgeInsets.symmetric( + horizontal: 4, + vertical: 4, + ), + child: Icon( + Icons.delete, + color: Colors.white, + ), ), - ), - ); - }, - background: Container( - color: Theme.of(context).errorColor, - alignment: Alignment.centerRight, - padding: EdgeInsets.only(right: 20), - margin: EdgeInsets.symmetric( - horizontal: 4, - vertical: 4, - ), - child: Icon( - Icons.delete, - color: Colors.white, - ), + direction: DismissDirection.endToStart, + child: Card( + child: ListTile( + //onTap: () => Navigator.of(context).pushNamed( + // WorkoutPlanScreen.routeName, + // arguments: currentPlan, + //), + onTap: () {}, + title: Text( + DateFormat('dd.MM.yyyy').format(currentEntry.date).toString(), + ), + subtitle: Text('${currentEntry.weight} kg'), + ), + ), + ); + }, ), - direction: DismissDirection.endToStart, - child: Card( - child: ListTile( - //onTap: () => Navigator.of(context).pushNamed( - // WorkoutPlanScreen.routeName, - // arguments: currentPlan, - //), - onTap: () {}, - title: Text( - DateFormat('dd.MM.yyyy').format(currentEntry.date).toString(), - ), - subtitle: Text('${currentEntry.weight} kg'), - ), - ), - ); - }, + ), + ], ); } } diff --git a/pubspec.lock b/pubspec.lock index c6dd21097..60cb90c94 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -113,6 +113,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.2.0-nullsafety.1" + charts_common: + dependency: transitive + description: + name: charts_common + url: "https://pub.dartlang.org" + source: hosted + version: "0.9.0" + charts_flutter: + dependency: "direct main" + description: + name: charts_flutter + url: "https://pub.dartlang.org" + source: hosted + version: "0.9.0" checked_yaml: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 158ed02ce..3fedc9510 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -34,6 +34,7 @@ dependencies: cupertino_icons: ^1.0.0 json_serializable: ^3.5.0 url_launcher: ^5.7.10 + charts_flutter: ^0.9.0 dev_dependencies: flutter_test: