Commit 7e5c69bc authored by Administrator's avatar Administrator

weight management

parent 14641da0
import 'package:encrateia/models/athlete.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/weight.dart';
import 'package:intl/intl.dart';
import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';
class AddWeightScreen extends StatelessWidget {
final Athlete athlete;
final Weight weight;
const AddWeightScreen({
Key key,
this.athlete,
this.weight,
}) : super(key: key);
@override
Widget build(BuildContext context) {
weight.db
..athletesId = athlete.db.id
..value = 70
..date = DateTime.now();
return Scaffold(
appBar: AppBar(
title: Text('Add your Weight'),
),
body: ListView(
padding: EdgeInsets.all(20),
children: <Widget>[
DateTimeField(
decoration: InputDecoration(labelText: "Date"),
format: DateFormat("yyyy-MM-dd"),
initialValue: DateTime.now(),
onShowPicker: (context, currentValue) {
return showDatePicker(
context: context,
firstDate: DateTime(1990),
initialDate: currentValue ?? DateTime.now(),
lastDate: DateTime(2100),
);
},
onChanged: (value) => weight.db.date = value,
),
TextFormField(
decoration: InputDecoration(labelText: "Weight in kg"),
initialValue: weight.db.value.toString(),
keyboardType: TextInputType.number,
onChanged: (value) => weight.db.value = double.parse(value),
),
Padding(
padding: EdgeInsets.all(15),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
RaisedButton(
color: Theme.of(context).primaryColorDark,
textColor: Theme.of(context).primaryColorLight,
child: Text('Cancel', textScaleFactor: 1.5),
onPressed: () => Navigator.of(context).pop(),
),
Container(width: 20.0),
RaisedButton(
color: Theme.of(context).primaryColorDark,
textColor: Theme.of(context).primaryColorLight,
child: Text('Save', textScaleFactor: 1.5),
onPressed: () => saveWeight(context),
),
],
),
),
],
),
);
}
saveWeight(BuildContext context) async {
await weight.db.save();
Navigator.of(context).pop();
}
}
import 'dart:convert';
import 'dart:io';
import 'package:encrateia/screens/add_weight_screen.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/weight.dart';
......@@ -43,6 +44,9 @@ class _AthleteBodyWeightWidgetState extends State<AthleteBodyWeightWidget> {
label: Text("Weight\nkg"),
numeric: true,
),
DataColumn(
label: Text("Delete"),
)
],
rows: weights.sublist(offset, offset + 8).map((Weight weight) {
return DataRow(
......@@ -51,12 +55,27 @@ class _AthleteBodyWeightWidgetState extends State<AthleteBodyWeightWidget> {
DataCell(
Text(DateFormat("d MMM yyyy").format(weight.db.date))),
DataCell(Text(weight.db.value.toString())),
DataCell(MyIcon.delete, onTap: () => deleteWeight(weight: weight)),
],
);
}).toList(),
),
Row(
children: <Widget>[
Spacer(),
RaisedButton(
color: Colors.green,
child: Text("New weighting"),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AddWeightScreen(
athlete: widget.athlete,
weight: Weight(),
),
),
).then((_) => getData()()),
),
Spacer(),
RaisedButton(
color: Colors.orange,
......@@ -110,9 +129,7 @@ Put one date and weight per line in the following format:
);
}
} else {
return Center(
child: Text("loading"),
);
return Center(child: Text("loading"));
}
}
......@@ -154,4 +171,9 @@ Put one date and weight per line in the following format:
await getData();
}
}
deleteWeight({Weight weight}) async {
await weight.delete();
await getData();
}
}
......@@ -204,6 +204,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.3"
datetime_picker_formfield:
dependency: "direct main"
description:
name: datetime_picker_formfield
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
dio:
dependency: "direct main"
description:
......
......@@ -27,6 +27,7 @@ dependencies:
path_provider: ^1.6.7
csv: ^4.0.3
datetime_picker_formfield: ^1.0.0
dev_dependencies:
flutter_test:
......
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