Commit 3e8fbd5f authored by Stefan Haslinger's avatar Stefan Haslinger

refactoring PQ to PQText

parent 9ed675ce
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_secure_storage","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"package_info","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.11/","dependencies":[]},{"name":"shared_preferences","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.8/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.1/","dependencies":[]},{"name":"uni_links","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.5.0/","dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"package_info","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.11/","dependencies":[]},{"name":"shared_preferences","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.8/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.1/","dependencies":[]},{"name":"uni_links","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.5.0/","dependencies":[]}],"macos":[{"name":"package_info","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+3/","dependencies":[]},{"name":"shared_preferences_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+10/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.1/","dependencies":[]},{"name":"url_launcher_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+7/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.0.1+2/","dependencies":[]},{"name":"shared_preferences_linux","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-0.0.2+1/","dependencies":["path_provider_linux"]},{"name":"url_launcher_linux","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-0.0.1+1/","dependencies":[]}],"windows":[],"web":[{"name":"shared_preferences_web","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+7/","dependencies":[]},{"name":"url_launcher_web","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-0.1.2/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":[]},{"name":"package_info","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_linux","shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]},{"name":"uni_links","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_web","url_launcher_linux","url_launcher_macos"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2020-08-13 15:27:28.466381","version":"1.20.1"}
\ No newline at end of file
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_secure_storage","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"package_info","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.11/","dependencies":[]},{"name":"shared_preferences","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.8/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.1/","dependencies":[]},{"name":"uni_links","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.5.0/","dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"package_info","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.11/","dependencies":[]},{"name":"shared_preferences","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.8/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.1/","dependencies":[]},{"name":"uni_links","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.5.0/","dependencies":[]}],"macos":[{"name":"package_info","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+3/","dependencies":[]},{"name":"shared_preferences_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+10/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.1/","dependencies":[]},{"name":"url_launcher_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+7/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.0.1+2/","dependencies":[]},{"name":"shared_preferences_linux","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-0.0.2+1/","dependencies":["path_provider_linux"]},{"name":"url_launcher_linux","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-0.0.1+1/","dependencies":[]}],"windows":[],"web":[{"name":"shared_preferences_web","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+7/","dependencies":[]},{"name":"url_launcher_web","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-0.1.2/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":[]},{"name":"package_info","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_linux","shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]},{"name":"uni_links","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_web","url_launcher_linux","url_launcher_macos"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2020-08-13 17:59:29.431277","version":"1.20.1"}
\ No newline at end of file
......@@ -237,14 +237,6 @@ class Activity {
await save();
}
String heartRateString() {
return (avgHeartRate == null || avgHeartRate == 255)
? '- - -'
: avgHeartRate.toString() + ' bpm';
}
String paceString() => avgSpeed.toPace() + '/km';
Future<List<Event>> get records async {
if (cachedRecords.isEmpty) {
final List<DbEvent> dbEventList = await _db.getDbEvents().toList();
......
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'enums.dart';
@immutable
class PQ extends StatelessWidget {
const PQ({
this.value,
this.unit,
this.text,
this.dateTime,
this.format,
this.distance,
});
final num value;
final String unit;
final String text;
final DateTime dateTime;
final DateTimeFormat format;
final int distance;
@override
Widget build(BuildContext context) {
if (text != null) {
return (unit != null) ? Text(text + ' ' + unit) : Text(text);
} else if (value != null) {
return (unit != null)
? Text(value.toString() + ' ' + unit)
: Text(value.toString());
} else if (dateTime != null) {
switch (format) {
case DateTimeFormat.longDate:
return Text(DateFormat('d MMM yy').format(dateTime));
case DateTimeFormat.shortDate:
return Text(DateFormat('d.M.').format(dateTime));
case DateTimeFormat.shortTime:
return Text(DateFormat('H:mm').format(dateTime));
case DateTimeFormat.shortDateTime:
return Text(DateFormat('d.MM H:mm').format(dateTime));
case DateTimeFormat.longDateTime:
default:
return Text(DateFormat('E d MMM yy, H:mm:ss').format(dateTime));
}
} else if (distance != null) {
return Text((distance / 1000).toStringAsFixed(2) + ' km');
} else
return const Text('n.a.');
}
}
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'enums.dart';
@immutable
class PQText extends StatelessWidget {
const PQText({
@required this.pq,
this.value,
this.unit,
this.format,
this.naList,
});
final dynamic value;
final String unit;
final DateTimeFormat format;
final PQ pq;
final List<num> naList;
@override
Widget build(BuildContext context) {
String formatString;
if (!validValue)
return const Text('n.a.');
switch (pq) {
case PQ.dateTime:
return Text(DateFormat(formatString).format(value as DateTime));
case PQ.distance:
return Text(((value as double) / 1000).toStringAsFixed(2) + ' km');
case PQ.power:
return Text((value as double).toStringAsFixed(1) + ' W');
case PQ.pace:
final double totalSeconds = 1000 / (value as double);
final int minutes = (totalSeconds / 60).floor();
final String seconds =
(totalSeconds - minutes * 60).round().toString().padLeft(2, '0');
return Text('$minutes:$seconds /km');
case PQ.heartRate:
return Text('$value bpm');
}
return const Text('This is an error!'); // just to silence the dart analyzer
}
String get paddedUnit {
if (unit != null)
return ' ' + unit;
else
return '';
}
String get formatString {
switch (format) {
case DateTimeFormat.longDate:
return 'd MMM yy';
case DateTimeFormat.shortDate:
return 'd.M.';
case DateTimeFormat.shortTime:
return 'H:mm';
case DateTimeFormat.shortDateTime:
return 'd.MM H:mm';
case DateTimeFormat.longDateTime:
return 'E d MMM yy, H:mm:ss';
}
return 'E d MMM yy, H:mm:ss';
}
bool get validValue {
switch (pq) {
case PQ.distance:
case PQ.dateTime:
return value != null;
case PQ.power:
case PQ.pace:
return value != null && value != -1;
case PQ.heartRate:
return value != null && value != 255;
}
return false; // just to silence the dart analyzer
}
}
......@@ -44,3 +44,11 @@ enum DateTimeFormat {
shortDateTime,
longDateTime,
}
enum PQ {
dateTime,
distance,
power,
pace,
heartRate,
}
......@@ -3,7 +3,7 @@ import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/tag.dart';
import 'package:encrateia/models/tag_group.dart';
import 'package:encrateia/utils/PQ.dart';
import 'package:encrateia/utils/PQText.dart';
import 'package:encrateia/utils/enums.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/screens/show_activity_screen.dart';
......@@ -54,72 +54,89 @@ class _ActivitiesFeedWidgetState extends State<ActivitiesFeedWidget> {
itemCount: activities.length,
itemBuilder: (BuildContext context, int index) {
final Activity activity = activities[index];
return Column(crossAxisAlignment: CrossAxisAlignment.start, children: <
Widget>[
ListTile(
leading: sportsIcon(sport: activity.sport),
title: Text(activity.name ?? 'Activity'),
subtitle: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Column(children: <Widget>[
PQ(
dateTime: activity.timeCreated,
format: DateTimeFormat.longDate,
),
PQ(distance: activity.totalDistance),
]),
const SizedBox(width: 20),
Text(activity.paceString() + '\n' + activity.heartRateString()),
const SizedBox(width: 20),
Text((activity.avgPower == null || activity.avgPower == -1)
? '-'
: activity.avgPower.toStringAsFixed(1) + ' W' + '\n'),
],
),
onTap: () async {
if (activity.state == 'persisted') {
await Navigator.push(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext context) => ShowActivityScreen(
activity: activity,
athlete: widget.athlete,
),
),
);
getData();
}
},
),
Padding(
padding: const EdgeInsets.only(left: 20),
child: Wrap(
spacing: 10,
children: <Widget>[
for (Tag tag in activity.cachedTags)
Chip(
avatar: CircleAvatar(
foregroundColor: MyColor.textColor(
backgroundColor: Color(tagGroup(tag).color)),
backgroundColor: Color(tagGroup(tag).color),
child: Text(capitals(tag))),
label: Text(
tag.name,
style: TextStyle(
color: MyColor.textColor(
selected: true,
backgroundColor: Color(tag.color ?? 99999),
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
ListTile(
leading: sportsIcon(sport: activity.sport),
title: Text(activity.name ?? 'Activity'),
subtitle: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Column(children: <Widget>[
PQText(
pq: PQ.dateTime,
value: activity.timeCreated,
format: DateTimeFormat.longDate,
),
PQText(
pq: PQ.distance,
value: activity.totalDistance,
),
]),
const SizedBox(width: 20),
Column(children: <Widget>[
PQText(pq: PQ.pace, value: activity.avgSpeed),
PQText(
pq: PQ.heartRate,
value: activity.avgHeartRate,
),
]),
const SizedBox(width: 20),
Column(
children: <Widget>[
PQText(
pq: PQ.power,
value: activity.avgPower,
),
const Text('')
],
)
],
),
onTap: () async {
if (activity.state == 'persisted') {
await Navigator.push(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext context) => ShowActivityScreen(
activity: activity,
athlete: widget.athlete,
),
),
);
getData();
}
},
),
Padding(
padding: const EdgeInsets.only(left: 20),
child: Wrap(
spacing: 10,
children: <Widget>[
for (Tag tag in activity.cachedTags)
Chip(
avatar: CircleAvatar(
foregroundColor: MyColor.textColor(
backgroundColor: Color(tagGroup(tag).color)),
backgroundColor: Color(tagGroup(tag).color),
child: Text(capitals(tag))),
label: Text(
tag.name,
style: TextStyle(
color: MyColor.textColor(
selected: true,
backgroundColor: Color(tag.color ?? 99999),
),
),
),
backgroundColor: Color(tag.color ?? 99999),
elevation: 3,
),
),
backgroundColor: Color(tag.color ?? 99999),
elevation: 3,
),
],
),
)
]);
],
),
)
]);
},
);
}
......
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/utils/PQ.dart';
import 'package:encrateia/utils/PQText.dart';
import 'package:encrateia/utils/enums.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/screens/show_activity_screen.dart';
......@@ -41,8 +41,9 @@ class _ActivitiesListWidgetState extends State<ActivitiesListWidget> {
dense: true,
leading: sportsIcon(sport: activity.sport),
title: Text(activity.name ?? 'Activity'),
subtitle: PQ(
dateTime: activity.timeCreated,
subtitle: PQText(
pq: PQ.dateTime,
value: activity.timeCreated,
format: DateTimeFormat.longDateTime,
),
onTap: () {
......
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