wip: null safety, removing Expanded widgets

upgrade-2021-project
Stefan Haslinger 2022-03-10 14:58:28 +01:00
parent 6c956982c2
commit 0f4a662890
5 changed files with 34 additions and 40 deletions

File diff suppressed because one or more lines are too long

View File

@ -355,15 +355,15 @@ class Activity {
return cachedTags;
}
Future<double?> get weight async {
Future<double> get weight async {
if (cachedWeight == null) {
final Weight weight = await (Weight.getBy(
final Weight weight = await Weight.getBy(
athletesId: athletesId,
date: timeCreated,
) as Future<Weight>);
);
cachedWeight = weight.value;
}
return cachedWeight;
return cachedWeight!;
}
Future<double?> get ecor async {
@ -726,8 +726,9 @@ class Activity {
date: timeCreated,
);
Future<PowerZone?> get powerZone async {
if (_powerZone == null) {
Future<PowerZone> get powerZone async {
PowerZone? powerZone = _powerZone;
if (powerZone == null) {
final DbPowerZone? dbPowerZone = await DbPowerZone()
.select()
.powerZoneSchemataId
@ -739,13 +740,14 @@ class Activity {
.upperLimit
.greaterThanOrEquals(avgPower)
.toSingle();
_powerZone = PowerZone.exDb(dbPowerZone ?? DbPowerZone());
powerZone = PowerZone.exDb(dbPowerZone!);
}
return _powerZone;
return powerZone;
}
Future<HeartRateZone?> get heartRateZone async {
if (_heartRateZone == null) {
Future<HeartRateZone> get heartRateZone async {
HeartRateZone? heartRateZone = _heartRateZone;
if (heartRateZone == null) {
final DbHeartRateZone? dbHeartRateZone = await DbHeartRateZone()
.select()
.heartRateZoneSchemataId
@ -758,13 +760,13 @@ class Activity {
.greaterThanOrEquals(avgHeartRate)
.toSingle();
_heartRateZone = HeartRateZone.exDb(dbHeartRateZone ?? DbHeartRateZone());
return HeartRateZone.exDb(dbHeartRateZone!);
}
return _heartRateZone;
return heartRateZone;
}
Future<void> autoTagger({required Athlete? athlete}) async {
final PowerZone powerZone = await (this.powerZone as Future<PowerZone>);
final PowerZone powerZone = await this.powerZone;
if (powerZone.id != null) {
final Tag powerTag = await Tag.autoPowerTag(
athlete: athlete!,
@ -780,7 +782,7 @@ class Activity {
}
final HeartRateZone heartRateZone =
await (this.heartRateZone as Future<HeartRateZone>);
await this.heartRateZone ;
if (heartRateZone.id != null) {
final Tag heartRateTag = await Tag.autoHeartRateTag(
athlete: athlete!,

View File

@ -26,7 +26,7 @@ class Weight {
Future<BoolResult> delete() async => await _db!.delete();
Future<int?> save() async => await _db!.save();
static Future<Weight?> getBy({int? athletesId, DateTime? date}) async {
static Future<Weight> getBy({int? athletesId, DateTime? date}) async {
List<DbWeight> dbWeights;
dbWeights = await DbWeight()
@ -50,7 +50,12 @@ class Weight {
.top(1)
.toList();
}
return (dbWeights.isNotEmpty) ? Weight._fromDb(dbWeights.first) : null;
return dbWeights.isNotEmpty
? Weight._fromDb(dbWeights.first)
: Weight._fromDb(DbWeight()
..athletesId = athletesId
..value = 70
..date = DateTime.now());
}
static Weight exDb(DbWeight db) => Weight._fromDb(db);

View File

@ -331,9 +331,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
color: MyColor.add,
textColor: MyColor.textColor(backgroundColor: MyColor.add)),
icon: MyIcon.settings,
label: const Expanded(
child: Text('Rerun Autotagging'),
),
label: const Text('Rerun Autotagging'),
onPressed: () => autoTagger(),
),
if (<String>['new', 'downloaded', 'persisted']
@ -343,9 +341,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
color: MyColor.add,
textColor: MyColor.textColor(backgroundColor: MyColor.add)),
icon: MyIcon.download,
label: const Expanded(
child: Text('Download fit file'),
),
label: const Text('Download fit file'),
onPressed: () => download(),
),
if (<String>['downloaded', 'persisted'].contains(widget.activity.state))
@ -354,9 +350,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
color: MyColor.add,
textColor: MyColor.textColor(backgroundColor: MyColor.add)),
icon: MyIcon.parse,
label: const Expanded(
child: Text('Parse fit file'),
),
label: const Text('Parse fit file'),
onPressed: () => parse(),
),
if (widget.activity.excluded == true)
@ -365,9 +359,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
color: MyColor.include,
textColor: MyColor.textColor(backgroundColor: MyColor.include)),
icon: MyIcon.filter,
label: const Expanded(
child: Text('Include in Analysis'),
),
label: const Text('Include in Analysis'),
onPressed: () => include(),
)
else
@ -376,9 +368,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
color: MyColor.exclude,
textColor: MyColor.textColor(backgroundColor: MyColor.exclude)),
icon: MyIcon.filter,
label: const Expanded(
child: Text('Exclude from Analysis'),
),
label: const Text('Exclude from Analysis'),
onPressed: () => exclude(),
),
navigationButton(
@ -407,9 +397,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
color: MyColor.delete,
textColor: MyColor.textColor(backgroundColor: MyColor.delete)),
icon: MyIcon.delete,
label: const Expanded(
child: Text('Delete Activity'),
),
label: const Text('Delete Activity'),
onPressed: () => delete(),
),
];
@ -456,9 +444,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
style: MyButtonStyle.raisedButtonStyle(
color: color, textColor: MyColor.textColor(backgroundColor: color)),
icon: icon,
label: Expanded(
child: Text(title),
),
label: Text(title),
onPressed: () => Navigator.push(
context,
MaterialPageRoute<BuildContext>(
@ -590,7 +576,8 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
duration: const Duration(seconds: 3),
content: Row(
children: [
CircularProgressIndicator(value: value / 100, color: MyColor.progress),
CircularProgressIndicator(
value: value / 100, color: MyColor.progress),
Text(' storing »${widget.activity.name}«'),
],
),

View File

@ -112,7 +112,7 @@ class _ActivityOverviewWidgetState extends State<ActivityOverviewWidget> {
return GridView.extent(
mainAxisSpacing: 4,
crossAxisSpacing: 4,
maxCrossAxisExtent: 400,
maxCrossAxisExtent: 600,
childAspectRatio: 5,
children: tiles,
);