hide db from HeartRateZone
parent
d6c0ebb869
commit
cf4be37250
|
@ -596,12 +596,12 @@ class Activity {
|
|||
}
|
||||
|
||||
final HeartRateZone heartRateZone = await this.heartRateZone;
|
||||
if (heartRateZone.db != null) {
|
||||
if (heartRateZone.id != null) {
|
||||
final Tag heartRateTag = await Tag.autoHeartRateTag(
|
||||
athlete: athlete,
|
||||
color: heartRateZone.db.color,
|
||||
sortOrder: heartRateZone.db.lowerLimit,
|
||||
name: heartRateZone.db.name,
|
||||
color: heartRateZone.color,
|
||||
sortOrder: heartRateZone.lowerLimit,
|
||||
name: heartRateZone.name,
|
||||
);
|
||||
await ActivityTagging.createBy(
|
||||
activity: this,
|
||||
|
|
|
@ -23,9 +23,9 @@ class BarZone {
|
|||
return <BarZone>[
|
||||
for (final HeartRateZone heartRateZone in heartRateZones)
|
||||
BarZone(
|
||||
lower: heartRateZone.db.lowerLimit.toDouble(),
|
||||
upper: heartRateZone.db.upperLimit.toDouble(),
|
||||
color: heartRateZone.db.color,
|
||||
lower: heartRateZone.lowerLimit.toDouble(),
|
||||
upper: heartRateZone.upperLimit.toDouble(),
|
||||
color: heartRateZone.color,
|
||||
)
|
||||
];
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ class HeartRateZone {
|
|||
int lowerLimit,
|
||||
int upperLimit,
|
||||
int color}) {
|
||||
db = DbHeartRateZone()
|
||||
_db = DbHeartRateZone()
|
||||
..heartRateZoneSchemataId = heartRateZoneSchema.id
|
||||
..name = name ?? 'My Zone'
|
||||
..lowerLimit = lowerLimit ?? 70
|
||||
|
@ -22,18 +22,40 @@ class HeartRateZone {
|
|||
..color = color ?? 0xFFFFc107;
|
||||
|
||||
if (lowerPercentage != null)
|
||||
db.lowerLimit =
|
||||
(lowerPercentage * heartRateZoneSchema.base / 100).round();
|
||||
lowerLimit = (lowerPercentage * heartRateZoneSchema.base / 100).round();
|
||||
if (upperPercentage != null)
|
||||
db.upperLimit =
|
||||
(upperPercentage * heartRateZoneSchema.base / 100).round();
|
||||
upperLimit = (upperPercentage * heartRateZoneSchema.base / 100).round();
|
||||
}
|
||||
HeartRateZone.fromDb(this.db);
|
||||
HeartRateZone.fromDb(this._db);
|
||||
|
||||
DbHeartRateZone db;
|
||||
DbHeartRateZone _db;
|
||||
|
||||
int get id => _db.id;
|
||||
int get color => _db.color;
|
||||
String get name => _db.name;
|
||||
int get lowerLimit => _db.lowerLimit;
|
||||
int get upperLimit => _db.upperLimit;
|
||||
int get lowerPercentage => _db.lowerPercentage;
|
||||
int get upperPercentage => _db.upperPercentage;
|
||||
set color(int value) => _db.color = value;
|
||||
set name(String value) => _db.name = value;
|
||||
set lowerLimit(int value) => _db.lowerLimit = value;
|
||||
set upperLimit(int value) => _db.upperLimit = value;
|
||||
set lowerPercentage(int value) => _db.lowerPercentage = value;
|
||||
set upperPercentage(int value) => _db.upperPercentage = value;
|
||||
set heartRateZoneSchemataId(int value) => _db.heartRateZoneSchemataId = value;
|
||||
set id(int value) => _db.id = value;
|
||||
|
||||
@override
|
||||
String toString() => '< HeartRateZone | ${db.name} | ${db.lowerLimit} >';
|
||||
String toString() => '< HeartRateZone | $name | $lowerLimit >';
|
||||
|
||||
Future<BoolResult> delete() async => await db.delete();
|
||||
Future<BoolResult> delete() async => await _db.delete();
|
||||
Future<int> save() async => await _db.save();
|
||||
|
||||
static Future<BoolCommitResult> upsertAll(
|
||||
List<HeartRateZone> heartRateZones) async {
|
||||
return await DbHeartRateZone().upsertAll(heartRateZones
|
||||
.map((HeartRateZone heartRateZone) => heartRateZone._db)
|
||||
.toList());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,35 +59,35 @@ class HeartRateZoneSchema {
|
|||
lowerPercentage: 50,
|
||||
upperPercentage: 60,
|
||||
color: Colors.grey.value,
|
||||
).db.save();
|
||||
).save();
|
||||
await HeartRateZone(
|
||||
heartRateZoneSchema: this,
|
||||
name: 'Easy',
|
||||
lowerPercentage: 60,
|
||||
upperPercentage: 70,
|
||||
color: Colors.blue.value,
|
||||
).db.save();
|
||||
).save();
|
||||
await HeartRateZone(
|
||||
heartRateZoneSchema: this,
|
||||
name: 'Aerobic',
|
||||
lowerPercentage: 70,
|
||||
upperPercentage: 80,
|
||||
color: Colors.green.value,
|
||||
).db.save();
|
||||
).save();
|
||||
await HeartRateZone(
|
||||
heartRateZoneSchema: this,
|
||||
name: 'Threshold',
|
||||
lowerPercentage: 80,
|
||||
upperPercentage: 90,
|
||||
color: Colors.orange.value,
|
||||
).db.save();
|
||||
).save();
|
||||
await HeartRateZone(
|
||||
heartRateZoneSchema: this,
|
||||
name: 'Maximum',
|
||||
lowerPercentage: 90,
|
||||
upperPercentage: 100,
|
||||
color: Colors.red.value,
|
||||
).db.save();
|
||||
).save();
|
||||
}
|
||||
|
||||
Future<void> addStefanDillingerZones() async {
|
||||
|
@ -97,35 +97,35 @@ class HeartRateZoneSchema {
|
|||
lowerPercentage: 70,
|
||||
upperPercentage: 80,
|
||||
color: Colors.grey.value,
|
||||
).db.save();
|
||||
).save();
|
||||
await HeartRateZone(
|
||||
heartRateZoneSchema: this,
|
||||
name: 'Z2',
|
||||
lowerPercentage: 80,
|
||||
upperPercentage: 88,
|
||||
color: Colors.blue.value,
|
||||
).db.save();
|
||||
).save();
|
||||
await HeartRateZone(
|
||||
heartRateZoneSchema: this,
|
||||
name: 'Z3',
|
||||
lowerPercentage: 88,
|
||||
upperPercentage: 95,
|
||||
color: Colors.green.value,
|
||||
).db.save();
|
||||
).save();
|
||||
await HeartRateZone(
|
||||
heartRateZoneSchema: this,
|
||||
name: 'Z4',
|
||||
lowerPercentage: 95,
|
||||
upperPercentage: 100,
|
||||
color: Colors.orange.value,
|
||||
).db.save();
|
||||
).save();
|
||||
await HeartRateZone(
|
||||
heartRateZoneSchema: this,
|
||||
name: 'Z5/6',
|
||||
lowerPercentage: 100,
|
||||
upperPercentage: 115,
|
||||
color: Colors.red.value,
|
||||
).db.save();
|
||||
).save();
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -326,12 +326,12 @@ class Lap {
|
|||
}
|
||||
|
||||
final HeartRateZone heartRateZone = await this.heartRateZone;
|
||||
if (heartRateZone.db != null) {
|
||||
if (heartRateZone.id != null) {
|
||||
final Tag heartRateTag = await Tag.autoHeartRateTag(
|
||||
athlete: athlete,
|
||||
sortOrder: heartRateZone.db.lowerLimit,
|
||||
color: heartRateZone.db.color,
|
||||
name: heartRateZone.db.name,
|
||||
sortOrder: heartRateZone.lowerLimit,
|
||||
color: heartRateZone.color,
|
||||
name: heartRateZone.name,
|
||||
);
|
||||
await LapTagging.createBy(
|
||||
lap: this,
|
||||
|
|
|
@ -400,13 +400,13 @@ class RecordList<E> extends DelegatingList<E> {
|
|||
for (final HeartRateZone heartRateZone in heartRateZones.reversed) {
|
||||
final int numberInZone = _records
|
||||
.where((Event event) =>
|
||||
(event.db.heartRate >= heartRateZone.db.lowerLimit) &&
|
||||
(event.db.heartRate <= heartRateZone.db.upperLimit))
|
||||
(event.db.heartRate >= heartRateZone.lowerLimit) &&
|
||||
(event.db.heartRate <= heartRateZone.upperLimit))
|
||||
.length;
|
||||
distributions.add(BarZone(
|
||||
lower: counter,
|
||||
upper: counter + numberInZone,
|
||||
color: heartRateZone.db.color,
|
||||
color: heartRateZone.color,
|
||||
));
|
||||
counter = counter + numberInZone;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import 'package:encrateia/models/heart_rate_zone.dart';
|
|||
import 'package:flutter_material_color_picker/flutter_material_color_picker.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';
|
||||
import 'package:encrateia/model/model.dart';
|
||||
import 'add_heart_rate_zone_screen.dart';
|
||||
|
||||
class AddHeartRateZoneSchemaScreen extends StatefulWidget {
|
||||
|
@ -102,16 +101,16 @@ class _AddHeartRateZoneSchemaScreenState
|
|||
],
|
||||
rows: heartRateZones.map((HeartRateZone heartRateZone) {
|
||||
return DataRow(
|
||||
key: ValueKey<int>(heartRateZone.db.id),
|
||||
key: ValueKey<int>(heartRateZone.id),
|
||||
cells: <DataCell>[
|
||||
DataCell(Text(heartRateZone.db.name)),
|
||||
DataCell(Text(heartRateZone.db.lowerLimit.toString() +
|
||||
DataCell(Text(heartRateZone.name)),
|
||||
DataCell(Text(heartRateZone.lowerLimit.toString() +
|
||||
' - ' +
|
||||
heartRateZone.db.upperLimit.toString())),
|
||||
heartRateZone.upperLimit.toString())),
|
||||
DataCell(CircleColor(
|
||||
circleSize: 20,
|
||||
elevation: 0,
|
||||
color: Color(heartRateZone.db.color),
|
||||
color: Color(heartRateZone.color),
|
||||
)),
|
||||
DataCell(
|
||||
MyIcon.edit,
|
||||
|
@ -177,9 +176,7 @@ class _AddHeartRateZoneSchemaScreenState
|
|||
|
||||
Future<void> saveHeartRateZoneSchema(BuildContext context) async {
|
||||
await widget.heartRateZoneSchema.save();
|
||||
await DbHeartRateZone().upsertAll(heartRateZones
|
||||
.map((HeartRateZone heartRateZone) => heartRateZone.db)
|
||||
.toList());
|
||||
await HeartRateZone.upsertAll(heartRateZones);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
|
@ -198,10 +195,10 @@ class _AddHeartRateZoneSchemaScreenState
|
|||
setState(() {
|
||||
widget.heartRateZoneSchema.base = base;
|
||||
for (final HeartRateZone heartRateZone in heartRateZones) {
|
||||
heartRateZone.db.lowerLimit =
|
||||
(heartRateZone.db.lowerPercentage * base / 100).round();
|
||||
heartRateZone.db.upperLimit =
|
||||
(heartRateZone.db.upperPercentage * base / 100).round();
|
||||
heartRateZone.lowerLimit =
|
||||
(heartRateZone.lowerPercentage * base / 100).round();
|
||||
heartRateZone.upperLimit =
|
||||
(heartRateZone.upperPercentage * base / 100).round();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -213,13 +210,11 @@ class _AddHeartRateZoneSchemaScreenState
|
|||
final int heartRateZoneSchemaId =
|
||||
await widget.heartRateZoneSchema.save();
|
||||
for (final HeartRateZone heartRateZone in heartRateZones) {
|
||||
heartRateZone.db
|
||||
heartRateZone
|
||||
..heartRateZoneSchemataId = heartRateZoneSchemaId
|
||||
..id = null;
|
||||
}
|
||||
await DbHeartRateZone().upsertAll(heartRateZones
|
||||
.map((HeartRateZone heartRateZone) => heartRateZone.db)
|
||||
.toList());
|
||||
await HeartRateZone.upsertAll(heartRateZones);
|
||||
await getData();
|
||||
showDialog<BuildContext>(
|
||||
context: context,
|
||||
|
|
|
@ -35,8 +35,8 @@ class _AddHeartRateZoneScreenState extends State<AddHeartRateZoneScreen> {
|
|||
Navigator.of(context).pop();
|
||||
MaterialColorPicker(
|
||||
onColorChange: (Color color) =>
|
||||
widget.heartRateZone.db.color = color.value,
|
||||
selectedColor: Color(widget.heartRateZone.db.color));
|
||||
widget.heartRateZone.color = color.value,
|
||||
selectedColor: Color(widget.heartRateZone.color));
|
||||
},
|
||||
),
|
||||
],
|
||||
|
@ -48,8 +48,8 @@ class _AddHeartRateZoneScreenState extends State<AddHeartRateZoneScreen> {
|
|||
Future<void> openColorPicker() async {
|
||||
_openDialog(
|
||||
MaterialColorPicker(
|
||||
selectedColor: Color(widget.heartRateZone.db.color),
|
||||
onColorChange: (Color color) => setState(() => widget.heartRateZone.db.color = color.value),
|
||||
selectedColor: Color(widget.heartRateZone.color),
|
||||
onColorChange: (Color color) => setState(() => widget.heartRateZone.color = color.value),
|
||||
onBack: () {},
|
||||
),
|
||||
);
|
||||
|
@ -58,13 +58,13 @@ class _AddHeartRateZoneScreenState extends State<AddHeartRateZoneScreen> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final TextEditingController lowerLimitController =
|
||||
TextEditingController(text: widget.heartRateZone.db.lowerLimit.toString());
|
||||
TextEditingController(text: widget.heartRateZone.lowerLimit.toString());
|
||||
final TextEditingController upperLimitController =
|
||||
TextEditingController(text: widget.heartRateZone.db.upperLimit.toString());
|
||||
TextEditingController(text: widget.heartRateZone.upperLimit.toString());
|
||||
final TextEditingController lowerPercentageController = TextEditingController(
|
||||
text: widget.heartRateZone.db.lowerPercentage.toString());
|
||||
text: widget.heartRateZone.lowerPercentage.toString());
|
||||
final TextEditingController upperPercentageController = TextEditingController(
|
||||
text: widget.heartRateZone.db.upperPercentage.toString());
|
||||
text: widget.heartRateZone.upperPercentage.toString());
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
|
@ -76,16 +76,16 @@ class _AddHeartRateZoneScreenState extends State<AddHeartRateZoneScreen> {
|
|||
children: <Widget>[
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(labelText: 'Name'),
|
||||
initialValue: widget.heartRateZone.db.name,
|
||||
onChanged: (String value) => widget.heartRateZone.db.name = value,
|
||||
initialValue: widget.heartRateZone.name,
|
||||
onChanged: (String value) => widget.heartRateZone.name = value,
|
||||
),
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(labelText: 'Lower Limit in bpm'),
|
||||
controller: lowerLimitController,
|
||||
keyboardType: TextInputType.number,
|
||||
onChanged: (String value) {
|
||||
widget.heartRateZone.db.lowerLimit = int.parse(value);
|
||||
widget.heartRateZone.db.lowerPercentage =
|
||||
widget.heartRateZone.lowerLimit = int.parse(value);
|
||||
widget.heartRateZone.lowerPercentage =
|
||||
(int.parse(value) * 100 / widget.base).round();
|
||||
lowerPercentageController.text =
|
||||
(int.parse(value) * 100 / widget.base).round().toString();
|
||||
|
@ -96,8 +96,8 @@ class _AddHeartRateZoneScreenState extends State<AddHeartRateZoneScreen> {
|
|||
controller: upperLimitController,
|
||||
keyboardType: TextInputType.number,
|
||||
onChanged: (String value) {
|
||||
widget.heartRateZone.db.upperLimit = int.parse(value);
|
||||
widget.heartRateZone.db.upperPercentage =
|
||||
widget.heartRateZone.upperLimit = int.parse(value);
|
||||
widget.heartRateZone.upperPercentage =
|
||||
(int.parse(value) * 100 / widget.base).round();
|
||||
upperPercentageController.text =
|
||||
(int.parse(value) * 100 / widget.base).round().toString();
|
||||
|
@ -108,8 +108,8 @@ class _AddHeartRateZoneScreenState extends State<AddHeartRateZoneScreen> {
|
|||
controller: lowerPercentageController,
|
||||
keyboardType: TextInputType.number,
|
||||
onChanged: (String value) {
|
||||
widget.heartRateZone.db.lowerPercentage = int.parse(value);
|
||||
widget.heartRateZone.db.lowerLimit =
|
||||
widget.heartRateZone.lowerPercentage = int.parse(value);
|
||||
widget.heartRateZone.lowerLimit =
|
||||
(int.parse(value) * widget.base / 100).round();
|
||||
lowerLimitController.text =
|
||||
(int.parse(value) * widget.base / 100).round().toString();
|
||||
|
@ -120,8 +120,8 @@ class _AddHeartRateZoneScreenState extends State<AddHeartRateZoneScreen> {
|
|||
controller: upperPercentageController,
|
||||
keyboardType: TextInputType.number,
|
||||
onChanged: (String value) {
|
||||
widget.heartRateZone.db.upperPercentage = int.parse(value);
|
||||
widget.heartRateZone.db.upperLimit =
|
||||
widget.heartRateZone.upperPercentage = int.parse(value);
|
||||
widget.heartRateZone.upperLimit =
|
||||
(int.parse(value) * widget.base / 100).round();
|
||||
upperLimitController.text =
|
||||
(int.parse(value) * widget.base / 100).round().toString();
|
||||
|
@ -132,7 +132,7 @@ class _AddHeartRateZoneScreenState extends State<AddHeartRateZoneScreen> {
|
|||
const Text('Color'),
|
||||
const Spacer(),
|
||||
CircleAvatar(
|
||||
backgroundColor: Color(widget.heartRateZone.db.color),
|
||||
backgroundColor: Color(widget.heartRateZone.color),
|
||||
radius: 20.0,
|
||||
),
|
||||
const Spacer(),
|
||||
|
@ -158,12 +158,12 @@ class _AddHeartRateZoneScreenState extends State<AddHeartRateZoneScreen> {
|
|||
}
|
||||
|
||||
Future<void> saveHeartRateZone(BuildContext context) async {
|
||||
await widget.heartRateZone.db.save();
|
||||
await widget.heartRateZone.save();
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
Future<void> deleteHeartRateZone(BuildContext context) async {
|
||||
await widget.heartRateZone.db.delete();
|
||||
await widget.heartRateZone.delete();
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,11 +90,11 @@ class GraphUtils {
|
|||
rangeAnnotationSegmentList = <RangeAnnotationSegment<int>>[
|
||||
for (HeartRateZone heartRateZone in heartRateZones)
|
||||
RangeAnnotationSegment<int>(
|
||||
heartRateZone.db.lowerLimit,
|
||||
heartRateZone.db.upperLimit,
|
||||
heartRateZone.lowerLimit,
|
||||
heartRateZone.upperLimit,
|
||||
RangeAnnotationAxisType.measure,
|
||||
startLabel: heartRateZone.db.name,
|
||||
color: convertedColor(dbColor: heartRateZone.db.color),
|
||||
startLabel: heartRateZone.name,
|
||||
color: convertedColor(dbColor: heartRateZone.color),
|
||||
)
|
||||
];
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ class MyBarChart extends StatelessWidget {
|
|||
else if (heartRateZones != null)
|
||||
return heartRateZones
|
||||
.map((HeartRateZone heartRateZone) =>
|
||||
heartRateZone.db.upperLimit.toDouble())
|
||||
heartRateZone.upperLimit.toDouble())
|
||||
.reduce(math.max);
|
||||
else
|
||||
return 100.0;
|
||||
|
@ -116,7 +116,7 @@ class MyBarChart extends StatelessWidget {
|
|||
else if (heartRateZones != null)
|
||||
return heartRateZones
|
||||
.map((HeartRateZone heartRateZone) =>
|
||||
heartRateZone.db.lowerLimit.toDouble())
|
||||
heartRateZone.lowerLimit.toDouble())
|
||||
.reduce(math.min);
|
||||
else
|
||||
return 0.0;
|
||||
|
|
|
@ -79,12 +79,12 @@ class MyLineChart extends LineChart {
|
|||
return NumericExtents(
|
||||
heartRateZones
|
||||
.map((HeartRateZone heartRateZone) =>
|
||||
heartRateZone.db.lowerLimit)
|
||||
heartRateZone.lowerLimit)
|
||||
.reduce(min) -
|
||||
5.0,
|
||||
heartRateZones
|
||||
.map((HeartRateZone heartRateZone) =>
|
||||
heartRateZone.db.upperLimit)
|
||||
heartRateZone.upperLimit)
|
||||
.reduce(max) +
|
||||
5.0);
|
||||
else
|
||||
|
|
Reference in New Issue