Commit 2d40c87d authored by Stefan Haslinger's avatar Stefan Haslinger

hide db from Weight

parent f8919876
......@@ -23,6 +23,13 @@ class LapTagging {
int get lapsId => _db.lapsId;
int get tagsId => _db.tagsId;
@override
String toString() =>
'< LapTagging | lapId $lapsId | tagId $tagsId >';
Future<BoolResult> delete() async => await _db.delete();
Future<int> save() async => await _db.save();
static Future<LapTagging> createBy({
@required Lap lap,
@required Tag tag,
......@@ -79,11 +86,4 @@ class LapTagging {
.toSingle();
await dbLapTagging.delete();
}
@override
String toString() =>
'< LapTagging | lapId $lapsId | tagId $tagsId >';
Future<BoolResult> delete() async => await _db.delete();
Future<int> save() async => await _db.save();
}
......@@ -5,19 +5,26 @@ import 'package:sqfentity_gen/sqfentity_gen.dart';
class Weight {
Weight({@required Athlete athlete}) {
db = DbWeight()
_db = DbWeight()
..athletesId = athlete.db.id
..value = 70
..date = DateTime.now();
}
Weight.fromDb(this.db);
Weight.fromDb(this._db);
DbWeight db;
DbWeight _db;
int get id => _db.id;
DateTime get date => _db.date;
double get value => _db.value;
set date(DateTime value) => _db.date = value;
set value(double value) => _db.value = value;
@override
String toString() => '< Weight | ${db.date} | ${db.value} >';
String toString() => '< Weight | $date | $value >';
Future<BoolResult> delete() async => await db.delete();
Future<BoolResult> delete() async => await _db.delete();
Future<int> save() async => await _db.save();
static Future<List<Weight>> all({@required Athlete athlete}) async {
final List<DbWeight> dbWeightList =
......
......@@ -26,7 +26,7 @@ class AddWeightScreen extends StatelessWidget {
DateTimeField(
decoration: const InputDecoration(labelText: 'Date'),
format: DateFormat('yyyy-MM-dd'),
initialValue: weight.db.date,
initialValue: weight.date,
onShowPicker: (BuildContext context, DateTime currentValue) {
return showDatePicker(
context: context,
......@@ -35,13 +35,13 @@ class AddWeightScreen extends StatelessWidget {
lastDate: DateTime(2100),
);
},
onChanged: (DateTime value) => weight.db.date = value,
onChanged: (DateTime value) => weight.date = value,
),
TextFormField(
decoration: const InputDecoration(labelText: 'Weight in kg'),
initialValue: weight.db.value.toString(),
initialValue: weight.value.toString(),
keyboardType: const TextInputType.numberWithOptions(decimal: true),
onChanged: (String value) => weight.db.value = double.parse(value),
onChanged: (String value) => weight.value = double.parse(value),
),
const SizedBox(height: 20),
Row(
......@@ -62,7 +62,7 @@ class AddWeightScreen extends StatelessWidget {
}
Future<void> saveWeight(BuildContext context) async {
await weight.db.save();
await weight.save();
Navigator.of(context).pop();
}
......
......@@ -54,7 +54,7 @@ class _ActivityEcorWidgetState extends State<ActivityEcorWidget> {
records: RecordList<Event>(ecorRecords),
activity: widget.activity,
athlete: widget.athlete,
weight: weight.db.value,
weight: weight.value,
),
Text('${widget.athlete.db.recordAggregationCount} records are '
'aggregated into one point in the plot. Only records where '
......@@ -101,8 +101,8 @@ class _ActivityEcorWidgetState extends State<ActivityEcorWidget> {
athletesId: widget.athlete.db.id,
date: widget.activity.db.timeCreated,
);
widget.activity.weight = weight.db.value;
weightString = weight.db.value.toStringOrDashes(2) + ' kg';
widget.activity.weight = weight.value;
weightString = weight.value.toStringOrDashes(2) + ' kg';
setState(() {});
}
}
......@@ -121,7 +121,7 @@ class _ActivityOverviewWidgetState extends State<ActivityOverviewWidget> {
date: widget.activity.db.timeCreated,
);
setState(() {
widget.activity.weight = weight?.db?.value;
widget.activity.weight = weight?.value;
});
}
}
......@@ -49,11 +49,11 @@ class _AthleteBodyWeightWidgetState extends State<AthleteBodyWeightWidget> {
],
rows: weights.sublist(offset, offset + rows).map((Weight weight) {
return DataRow(
key: ValueKey<int>(weight.db.id),
key: ValueKey<int>(weight.id),
cells: <DataCell>[
DataCell(
Text(DateFormat('d MMM yyyy').format(weight.db.date))),
DataCell(Text(weight.db.value.toString())),
Text(DateFormat('d MMM yyyy').format(weight.date))),
DataCell(Text(weight.value.toString())),
DataCell(MyIcon.edit, onTap: () async {
await Navigator.push(
context,
......@@ -197,13 +197,13 @@ Or you can simply enter your current weight using the New Weighting button.
.toList();
for (final List<dynamic> weighting in weightings) {
weight = Weight(athlete: widget.athlete);
weight.db.date = DateTime.utc(
weight.date = DateTime.utc(
int.parse((weighting[0] as String).split('-')[0]),
int.parse((weighting[0] as String).split('-')[1]),
int.parse((weighting[0] as String).split('-')[2]),
);
weight.db.value = double.parse(weighting[1] as String);
await weight.db.save();
weight.value = double.parse(weighting[1] as String);
await weight.save();
}
await getData();
}
......
......@@ -102,7 +102,7 @@ class _AthleteEcorWidgetState extends State<AthleteEcorWidget> {
athletesId: activity.db.athletesId,
date: activity.db.timeCreated,
);
activity.weight = weight?.db?.value;
activity.weight = weight?.value;
}
setState(() {});
}
......
......@@ -57,7 +57,7 @@ class _LapEcorWidgetState extends State<LapEcorWidget> {
children: <Widget>[
LapEcorChart(
records: RecordList<Event>(powerRecords),
weight: weight.db.value,
weight: weight.value,
),
Text('${widget.athlete.db.recordAggregationCount} records are '
'aggregated into one point in the plot. Only records where '
......@@ -94,7 +94,7 @@ class _LapEcorWidgetState extends State<LapEcorWidget> {
athletesId: widget.athlete.db.id,
date: widget.lap.db.startTime,
);
weightString = weight.db.value.toStringOrDashes(2) + ' kg';
weightString = weight.value.toStringOrDashes(2) + ' kg';
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