mirror of
https://github.com/wger-project/flutter.git
synced 2026-11-28 17:08:29 +01:00
Add chart to weight screen
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<BodyWeight>(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<BodyWeight>(context, listen: false).deleteEntry(currentEntry.id);
|
||||
return Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.all(15),
|
||||
height: 220,
|
||||
child: charts.TimeSeriesChart(
|
||||
[
|
||||
charts.Series<WeightEntry, DateTime>(
|
||||
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<BodyWeight>(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'),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
14
pubspec.lock
14
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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user