fix all build context warnings

master
Haslinger Stefan (extern) 2023-05-02 08:15:49 +02:00
parent 9382fc9ef9
commit e6352a33bc
32 changed files with 560 additions and 409 deletions

File diff suppressed because one or more lines are too long

View File

@ -26,8 +26,6 @@ linter:
# `// ignore_for_file: name_of_lint` syntax on the line or in the file # `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint. # producing the lint.
rules: rules:
# FIXME: HAS20230406: At least as long as https://github.com/dart-lang/linter/issues/3943 is open
use_build_context_synchronously: false
# avoid_print: false # Uncomment to disable the `avoid_print` rule # avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

View File

@ -13,44 +13,55 @@ Future<void> analyseActivities({
int index = 0; int index = 0;
int percent; int percent;
ScaffoldMessenger.of(context).showSnackBar( if (context.mounted) {
SnackBar(
duration: const Duration(seconds: 5),
content: Row(
children: [
MyIcon.finishedWhite,
const Text(' Calculating...'),
],
),
),
);
for (final Activity activity in activities) {
index += 1;
await activity.setAverages();
ScaffoldMessenger.of(context).removeCurrentSnackBar();
percent = 100 * index ~/ activities.length;
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
duration: const Duration(seconds: 2), duration: const Duration(seconds: 5),
content: Row(children: [ content: Row(
CircularProgressIndicator(value: percent / 100, color: MyColor.progress), children: [
Text(' recalculating »${activity.name}«') MyIcon.finishedWhite,
]), const Text(' Calculating...'),
],
),
), ),
); );
} }
ScaffoldMessenger.of(context).removeCurrentSnackBar(); for (final Activity activity in activities) {
ScaffoldMessenger.of(context).showSnackBar( index += 1;
SnackBar( await activity.setAverages();
duration: const Duration(seconds: 5), if (context.mounted) {
content: Row( ScaffoldMessenger.of(context).removeCurrentSnackBar();
children: [ }
MyIcon.finishedWhite, percent = 100 * index ~/ activities.length;
const Text(' Averages are now up to date.') if (context.mounted) {
], ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
duration: const Duration(seconds: 2),
content: Row(children: [
CircularProgressIndicator(
value: percent / 100, color: MyColor.progress),
Text(' recalculating »${activity.name}«')
]),
),
);
}
}
if (context.mounted) {
ScaffoldMessenger.of(context).removeCurrentSnackBar();
}
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
duration: const Duration(seconds: 5),
content: Row(
children: [
MyIcon.finishedWhite,
const Text(' Averages are now up to date.')
],
),
), ),
), );
); }
} }

View File

@ -10,17 +10,19 @@ Future<void> autoTagging({
required Athlete athlete, required Athlete athlete,
}) async { }) async {
if (await athlete.checkForSchemas()) { if (await athlete.checkForSchemas()) {
ScaffoldMessenger.of(context).showSnackBar( if (context.mounted) {
SnackBar( ScaffoldMessenger.of(context).showSnackBar(
duration: const Duration(seconds: 5), SnackBar(
content: Row( duration: const Duration(seconds: 5),
children: [ content: Row(
MyIcon.finishedWhite, children: [
const Text('Started cleaning up...'), MyIcon.finishedWhite,
], const Text('Started cleaning up...'),
],
),
), ),
), );
); }
List<Activity> activities; List<Activity> activities;
activities = await athlete.activities; activities = await athlete.activities;
@ -28,61 +30,74 @@ Future<void> autoTagging({
int percent; int percent;
await TagGroup.deleteAllAutoTags(athlete: athlete); await TagGroup.deleteAllAutoTags(athlete: athlete);
ScaffoldMessenger.of(context).showSnackBar( if (context.mounted) {
SnackBar(
duration: const Duration(seconds: 2),
content: Row(
children: [
MyIcon.finishedWhite,
const Text('All existing autotaggings have been deleted.'),
],
),
),
);
for (final Activity activity in activities) {
index += 1;
await activity.autoTagger(athlete: athlete);
ScaffoldMessenger.of(context).removeCurrentSnackBar();
percent = 100 * index ~/ activities.length;
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
content: Row( content: Row(
children: [ children: [
CircularProgressIndicator(value: percent / 100, color: MyColor.progress), MyIcon.finishedWhite,
Text(' $percent% done (autotagging »${activity.name}« )'), const Text('All existing autotaggings have been deleted.'),
], ],
), ),
), ),
); );
} }
ScaffoldMessenger.of(context).removeCurrentSnackBar(); for (final Activity activity in activities) {
ScaffoldMessenger.of(context).showSnackBar( index += 1;
SnackBar( await activity.autoTagger(athlete: athlete);
duration: const Duration(seconds: 5), if (context.mounted) {
content: Row( ScaffoldMessenger.of(context).removeCurrentSnackBar();
children: [ }
MyIcon.finishedWhite, percent = 100 * index ~/ activities.length;
const Text(' Autotaggings are now up to date.'),
], if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
duration: const Duration(seconds: 2),
content: Row(
children: [
CircularProgressIndicator(
value: percent / 100, color: MyColor.progress),
Text(' $percent% done (autotagging »${activity.name}« )'),
],
),
),
);
}
}
if (context.mounted) {
ScaffoldMessenger.of(context).removeCurrentSnackBar();
}
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
duration: const Duration(seconds: 5),
content: Row(
children: [
MyIcon.finishedWhite,
const Text(' Autotaggings are now up to date.'),
],
),
), ),
), );
); }
} else { } else {
ScaffoldMessenger.of(context).showSnackBar( if (context.mounted) {
SnackBar( ScaffoldMessenger.of(context).showSnackBar(
duration: const Duration(seconds: 5), SnackBar(
content: Row( duration: const Duration(seconds: 5),
children: [ content: Row(
MyIcon.finishedWhite, children: [
const Text(' Please set up Power Zone Schema and ' MyIcon.finishedWhite,
'Heart Rate Zone Schema first!'), const Text(' Please set up Power Zone Schema and '
], 'Heart Rate Zone Schema first!'),
],
),
), ),
), );
); }
} }
} }

View File

@ -21,16 +21,18 @@ Future<void> downloadActivity({
await activity.download(athlete: athlete); await activity.download(athlete: athlete);
ScaffoldMessenger.of(context).removeCurrentSnackBar(); if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).removeCurrentSnackBar();
SnackBar( ScaffoldMessenger.of(context).showSnackBar(
duration: const Duration(seconds: 2), SnackBar(
content: Row( duration: const Duration(seconds: 2),
children: [ content: Row(
MyIcon.finishedWhite, children: [
const Text(' Download finished'), MyIcon.finishedWhite,
], const Text(' Download finished'),
],
),
), ),
), );
); }
} }

View File

@ -24,17 +24,19 @@ Future<void> downloadDemoData({
'upper_palatinate_winter_challenge_half_marathon.fit', 'upper_palatinate_winter_challenge_half_marathon.fit',
]; ];
ScaffoldMessenger.of(context).removeCurrentSnackBar(); if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).removeCurrentSnackBar();
SnackBar( ScaffoldMessenger.of(context).showSnackBar(
content: Row( SnackBar(
children: [ content: Row(
MyIcon.stravaDownloadWhite, children: [
const Text(' Downloading Demo data ...'), MyIcon.stravaDownloadWhite,
], const Text(' Downloading Demo data ...'),
],
),
), ),
), );
); }
for (final String filename in fileNames) { for (final String filename in fileNames) {
final Activity activity = Activity.fromLocalDirectory(athlete: athlete); final Activity activity = Activity.fromLocalDirectory(athlete: athlete);
@ -52,37 +54,44 @@ Future<void> downloadDemoData({
activity.excluded != true) activity.excluded != true)
.toList(); .toList();
for (final Activity activity in downloadedActivities) { for (final Activity activity in downloadedActivities) {
await parseActivity( if (context.mounted) {
context: context, await parseActivity(
activity: activity, context: context,
athlete: athlete, activity: activity,
); athlete: athlete,
ScaffoldMessenger.of(context).removeCurrentSnackBar(); );
}
ScaffoldMessenger.of(context).showSnackBar( if (context.mounted) {
SnackBar(content: Text(' Tagging »${activity.name}«')), ScaffoldMessenger.of(context).removeCurrentSnackBar();
);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(' Tagging »${activity.name}«')),
);
}
await activity.autoTagger(athlete: athlete); await activity.autoTagger(athlete: athlete);
} }
ScaffoldMessenger.of(context).removeCurrentSnackBar(); if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).removeCurrentSnackBar();
SnackBar( ScaffoldMessenger.of(context).showSnackBar(
content: Row( SnackBar(
children: [ content: Row(
MyIcon.finishedWhite, children: [
const Text(' Activities imported!'), MyIcon.finishedWhite,
], const Text(' Activities imported!'),
],
),
), ),
), );
); }
} else { } else {
ScaffoldMessenger.of(context).removeCurrentSnackBar(); if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).removeCurrentSnackBar();
const SnackBar( ScaffoldMessenger.of(context).showSnackBar(
content: Text(' Please set up Power Zone Schema and Heart' const SnackBar(
' Rate Zone Schema first!'), content: Text(' Please set up Power Zone Schema and Heart'
), ' Rate Zone Schema first!'),
); ),
);
}
} }
} }

View File

@ -23,17 +23,19 @@ Future<void> importActivitiesLocally({
); );
await Activity.importFromLocalDirectory(athlete: athlete); await Activity.importFromLocalDirectory(athlete: athlete);
ScaffoldMessenger.of(context).showSnackBar( if (context.mounted) {
SnackBar( ScaffoldMessenger.of(context).showSnackBar(
duration: const Duration(seconds: 1), SnackBar(
content: Row( duration: const Duration(seconds: 1),
children: [ content: Row(
MyIcon.finishedWhite, children: [
const Text(' Activities moved into application'), MyIcon.finishedWhite,
], const Text(' Activities moved into application'),
],
),
), ),
), );
); }
activities = await athlete.activities; activities = await athlete.activities;
final List<Activity> downloadedActivities = activities final List<Activity> downloadedActivities = activities
@ -44,23 +46,28 @@ Future<void> importActivitiesLocally({
activity.excluded != true) activity.excluded != true)
.toList(); .toList();
for (final Activity activity in downloadedActivities) { for (final Activity activity in downloadedActivities) {
await parseActivity( if (context.mounted) {
context: context, await parseActivity(
activity: activity, context: context,
athlete: athlete, activity: activity,
); athlete: athlete,
);
}
await activity.autoTagger(athlete: athlete); await activity.autoTagger(athlete: athlete);
} }
ScaffoldMessenger.of(context).removeCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar( if (context.mounted) {
SnackBar( ScaffoldMessenger.of(context).removeCurrentSnackBar();
duration: const Duration(seconds: 5), ScaffoldMessenger.of(context).showSnackBar(
content: Row( SnackBar(
children: [ duration: const Duration(seconds: 5),
MyIcon.finishedWhite, content: Row(
const Text(' Activities imported!'), children: [
], MyIcon.finishedWhite,
const Text(' Activities imported!'),
],
),
), ),
), );
); }
} }

View File

@ -60,12 +60,14 @@ Future<void> parseActivity({
await log.save(); await log.save();
activity.nonParsable = true; activity.nonParsable = true;
await activity.save(); await activity.save();
ScaffoldMessenger.of(context).removeCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar( if (context.mounted) {
const SnackBar( ScaffoldMessenger.of(context).removeCurrentSnackBar();
duration: Duration(seconds: 2), ScaffoldMessenger.of(context).showSnackBar(
content: Text('Error, see log on home screen for details')), const SnackBar(
); duration: Duration(seconds: 2),
content: Text('Error, see log on home screen for details')),
);
}
} }
} }

View File

@ -19,16 +19,18 @@ Future<void> queryStrava({
); );
await athlete.queryStrava(); await athlete.queryStrava();
ScaffoldMessenger.of(context).removeCurrentSnackBar(); if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).removeCurrentSnackBar();
SnackBar( ScaffoldMessenger.of(context).showSnackBar(
duration: const Duration(seconds: 1), SnackBar(
content: Row( duration: const Duration(seconds: 1),
children: [ content: Row(
MyIcon.finishedWhite, children: [
const Text('Download finished'), MyIcon.finishedWhite,
], const Text('Download finished'),
],
),
), ),
), );
); }
} }

View File

@ -25,10 +25,13 @@ Future<void> setupDemoAthlete({
weight.date = DateTime(2015); weight.date = DateTime(2015);
await weight.save(); await weight.save();
await downloadDemoData( if (context.mounted) {
context: context, await downloadDemoData(
athlete: athlete, context: context,
); athlete: athlete,
);
ScaffoldMessenger.of(context).removeCurrentSnackBar(); }
if (context.mounted) {
ScaffoldMessenger.of(context).removeCurrentSnackBar();
}
} }

View File

@ -13,20 +13,24 @@ Future<void> updateJob({
List<Activity> activities; List<Activity> activities;
if (await athlete.checkForSchemas()) { if (await athlete.checkForSchemas()) {
await queryStrava( if (context.mounted) {
context: context, await queryStrava(
athlete: athlete, context: context,
); athlete: athlete,
);
}
activities = await athlete.activities; activities = await athlete.activities;
final Iterable<Activity> newActivities = final Iterable<Activity> newActivities =
activities.where((Activity activity) => activity.state == 'new'); activities.where((Activity activity) => activity.state == 'new');
for (final Activity activity in newActivities) { for (final Activity activity in newActivities) {
await downloadActivity( if (context.mounted) {
context: context, await downloadActivity(
activity: activity, context: context,
athlete: athlete, activity: activity,
); athlete: athlete,
);
}
} }
final Iterable<Activity> downloadedActivities = activities.where( final Iterable<Activity> downloadedActivities = activities.where(
@ -36,37 +40,44 @@ Future<void> updateJob({
activity.nonParsable != true && activity.nonParsable != true &&
activity.excluded != true); activity.excluded != true);
for (final Activity activity in downloadedActivities) { for (final Activity activity in downloadedActivities) {
await parseActivity( if (context.mounted) {
context: context, await parseActivity(
activity: activity, context: context,
athlete: athlete, activity: activity,
); athlete: athlete,
);
}
await activity.autoTagger(athlete: athlete); await activity.autoTagger(athlete: athlete);
} }
ScaffoldMessenger.of(context).removeCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar( if (context.mounted) {
SnackBar( ScaffoldMessenger.of(context).removeCurrentSnackBar();
duration: const Duration(seconds: 5), ScaffoldMessenger.of(context).showSnackBar(
content: Row( SnackBar(
children: [ duration: const Duration(seconds: 5),
MyIcon.finishedWhite, content: Row(
const Text(' You are now up to date!'), children: [
], MyIcon.finishedWhite,
const Text(' You are now up to date!'),
],
),
), ),
), );
); }
} else { } else {
ScaffoldMessenger.of(context).showSnackBar( if (context.mounted) {
SnackBar( ScaffoldMessenger.of(context).showSnackBar(
duration: const Duration(seconds: 5), SnackBar(
content: Row( duration: const Duration(seconds: 5),
children: [ content: Row(
MyIcon.finishedWhite, children: [
const Text(' Please set up Power Zone Schema and ' MyIcon.finishedWhite,
'Heart Rate Zone Schema first!'), const Text(' Please set up Power Zone Schema and '
], 'Heart Rate Zone Schema first!'),
],
),
), ),
), );
); }
} }
} }

View File

@ -189,7 +189,9 @@ class AddHeartRateZoneSchemaScreenState
Future<void> saveHeartRateZoneSchema(BuildContext context) async { Future<void> saveHeartRateZoneSchema(BuildContext context) async {
await widget.heartRateZoneSchema.save(); await widget.heartRateZoneSchema.save();
await HeartRateZone.upsertAll(heartRateZones); await HeartRateZone.upsertAll(heartRateZones);
Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pop();
}
} }
Future<void> getData() async { Future<void> getData() async {
@ -200,7 +202,9 @@ class AddHeartRateZoneSchemaScreenState
Future<void> deleteHeartRateZoneSchema( Future<void> deleteHeartRateZoneSchema(
{required HeartRateZoneSchema heartRateZoneSchema}) async { {required HeartRateZoneSchema heartRateZoneSchema}) async {
await heartRateZoneSchema.delete(); await heartRateZoneSchema.delete();
Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pop();
}
} }
void updateHeartRateZoneBase({int? base}) { void updateHeartRateZoneBase({int? base}) {
@ -227,21 +231,25 @@ class AddHeartRateZoneSchemaScreenState
} }
await HeartRateZone.upsertAll(heartRateZones); await HeartRateZone.upsertAll(heartRateZones);
await getData(); await getData();
showDialog<BuildContext>( if (context.mounted) {
context: context, showDialog<BuildContext>(
builder: (_) => AlertDialog( context: context,
title: const Text('Heart Rate Zone Schema has been copied'), builder: (_) =>
content: const Text( AlertDialog(
'If you only wanted to fix the date you need to delete the old heart' title: const Text('Heart Rate Zone Schema has been copied'),
' rate zone schema manually.'), content: const Text(
actions: <Widget>[ 'If you only wanted to fix the date you need to delete the old heart'
ElevatedButton( ' rate zone schema manually.'),
style: MyButtonStyle.raisedButtonStyle(color: MyColor.primary), actions: <Widget>[
child: const Text('OK'), ElevatedButton(
onPressed: () => Navigator.of(context).pop(), style: MyButtonStyle.raisedButtonStyle(
), color: MyColor.primary),
], child: const Text('OK'),
), onPressed: () => Navigator.of(context).pop(),
); ),
],
),
);
}
} }
} }

View File

@ -169,11 +169,15 @@ class AddHeartRateZoneScreenState extends State<AddHeartRateZoneScreen> {
Future<void> saveHeartRateZone(BuildContext context) async { Future<void> saveHeartRateZone(BuildContext context) async {
await widget.heartRateZone!.save(); await widget.heartRateZone!.save();
Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pop();
}
} }
Future<void> deleteHeartRateZone(BuildContext context) async { Future<void> deleteHeartRateZone(BuildContext context) async {
await widget.heartRateZone!.delete(); await widget.heartRateZone!.delete();
Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pop();
}
} }
} }

View File

@ -182,7 +182,9 @@ class AddPowerZoneSchemaScreenState extends State<AddPowerZoneSchemaScreen> {
Future<void> savePowerZoneSchema(BuildContext context) async { Future<void> savePowerZoneSchema(BuildContext context) async {
await widget.powerZoneSchema.save(); await widget.powerZoneSchema.save();
await PowerZone.upsertAll(powerZones); await PowerZone.upsertAll(powerZones);
Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pop();
}
} }
Future<void> getData() async { Future<void> getData() async {
@ -193,7 +195,9 @@ class AddPowerZoneSchemaScreenState extends State<AddPowerZoneSchemaScreen> {
Future<void> deletePowerZoneSchema( Future<void> deletePowerZoneSchema(
{required PowerZoneSchema powerZoneSchema}) async { {required PowerZoneSchema powerZoneSchema}) async {
await powerZoneSchema.delete(); await powerZoneSchema.delete();
Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pop();
}
} }
Future<void>? updatePowerZoneBase({int? base}) { Future<void>? updatePowerZoneBase({int? base}) {
@ -221,21 +225,26 @@ class AddPowerZoneSchemaScreenState extends State<AddPowerZoneSchemaScreen> {
} }
await PowerZone.upsertAll(powerZones); await PowerZone.upsertAll(powerZones);
await getData(); await getData();
showDialog<BuildContext>(
context: context, if (context.mounted) {
builder: (_) => AlertDialog( showDialog<BuildContext>(
title: const Text('Power Zone Schema has been copied'), context: context,
content: const Text( builder: (_) =>
'If you only wanted to fix the date you need to delete the old ' AlertDialog(
'power zone schema manually.'), title: const Text('Power Zone Schema has been copied'),
actions: <Widget>[ content: const Text(
ElevatedButton( 'If you only wanted to fix the date you need to delete the old '
style: MyButtonStyle.raisedButtonStyle(color: MyColor.primary), 'power zone schema manually.'),
child: const Text('OK'), actions: <Widget>[
onPressed: () => Navigator.of(context).pop(), ElevatedButton(
), style: MyButtonStyle.raisedButtonStyle(
], color: MyColor.primary),
), child: const Text('OK'),
); onPressed: () => Navigator.of(context).pop(),
),
],
),
);
}
} }
} }

View File

@ -166,11 +166,15 @@ class AddPowerZoneScreenState extends State<AddPowerZoneScreen> {
Future<void> savePowerZone(BuildContext context) async { Future<void> savePowerZone(BuildContext context) async {
await widget.powerZone!.save(); await widget.powerZone!.save();
Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pop();
}
} }
Future<void> deletePowerZone(BuildContext context) async { Future<void> deletePowerZone(BuildContext context) async {
await widget.powerZone!.delete(); await widget.powerZone!.delete();
Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pop();
}
} }
} }

View File

@ -180,7 +180,9 @@ class AddTagGroupScreenState extends State<AddTagGroupScreen> {
Future<void> saveTagGroup(BuildContext context) async { Future<void> saveTagGroup(BuildContext context) async {
await widget.tagGroup!.save(); await widget.tagGroup!.save();
await Tag.upsertAll(tags); await Tag.upsertAll(tags);
Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pop();
}
} }
Future<void> getData() async { Future<void> getData() async {
@ -190,6 +192,8 @@ class AddTagGroupScreenState extends State<AddTagGroupScreen> {
Future<void> deleteTagGroup({required TagGroup tagGroup}) async { Future<void> deleteTagGroup({required TagGroup tagGroup}) async {
await tagGroup.delete(); await tagGroup.delete();
Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pop();
}
} }
} }

View File

@ -105,11 +105,15 @@ class AddTagScreenState extends State<AddTagScreen> {
Future<void> saveTag(BuildContext context) async { Future<void> saveTag(BuildContext context) async {
await widget.tag!.save(); await widget.tag!.save();
Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pop();
}
} }
Future<void> deleteTag(BuildContext context) async { Future<void> deleteTag(BuildContext context) async {
await widget.tag!.delete(); await widget.tag!.delete();
Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pop();
}
} }
} }

View File

@ -66,11 +66,15 @@ class AddWeightScreen extends StatelessWidget {
Future<void> saveWeight(BuildContext context) async { Future<void> saveWeight(BuildContext context) async {
await weight!.save(); await weight!.save();
Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pop();
}
} }
Future<void> deleteWeight(BuildContext context) async { Future<void> deleteWeight(BuildContext context) async {
await weight!.delete(); await weight!.delete();
Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pop();
}
} }
} }

View File

@ -52,13 +52,15 @@ class DashboardState extends State<Dashboard> {
title: Text('${athlete.firstName} ${athlete.lastName}'), title: Text('${athlete.firstName} ${athlete.lastName}'),
onTap: () async { onTap: () async {
await athlete.readCredentials(); await athlete.readCredentials();
await Navigator.push( if (context.mounted) {
context, await Navigator.push(
MaterialPageRoute<BuildContext>( context,
builder: (BuildContext context) => MaterialPageRoute<BuildContext>(
ShowAthleteScreen(athlete: athlete), builder: (BuildContext context) =>
), ShowAthleteScreen(athlete: athlete),
); ),
);
}
await getData(); await getData();
}, },
), ),
@ -107,13 +109,15 @@ class DashboardState extends State<Dashboard> {
athletes = await Athlete.all(); athletes = await Athlete.all();
logs = await Log.one(); logs = await Log.one();
if (athletes.isEmpty) { if (athletes.isEmpty) {
await Navigator.pushReplacement( if (context.mounted) {
context, await Navigator.pushReplacement(
MaterialPageRoute<BuildContext>( context,
builder: (BuildContext context) => MaterialPageRoute<BuildContext>(
const OnboardingIntroductionScreen(), builder: (BuildContext context) =>
), const OnboardingIntroductionScreen(),
); ),
);
}
} else { } else {
final PackageInfo packageInfo = await PackageInfo.fromPlatform(); final PackageInfo packageInfo = await PackageInfo.fromPlatform();
version = packageInfo.version; version = packageInfo.version;

View File

@ -74,13 +74,17 @@ class EditEventScreenState extends State<EditEventScreen> {
firstDate: DateTime(1969), firstDate: DateTime(1969),
initialDate: currentValue ?? DateTime.now(), initialDate: currentValue ?? DateTime.now(),
lastDate: DateTime(2100)); lastDate: DateTime(2100));
if (date != null) { if (context.mounted) {
final TimeOfDay? time = await showTimePicker( if (date != null) {
context: context, final TimeOfDay? time = await showTimePicker(
initialTime: TimeOfDay.fromDateTime( context: context,
currentValue ?? DateTime.now()), initialTime: TimeOfDay.fromDateTime(
); currentValue ?? DateTime.now()),
return DateTimeField.combine(date, time); );
return DateTimeField.combine(date, time);
} else {
return currentValue;
}
} else { } else {
return currentValue; return currentValue;
} }
@ -270,7 +274,9 @@ class EditEventScreenState extends State<EditEventScreen> {
child: MyButton.save( child: MyButton.save(
onPressed: () async { onPressed: () async {
await widget.record!.save(); await widget.record!.save();
Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pop();
}
}, },
), ),
), ),

View File

@ -71,11 +71,13 @@ class OnBoardingBodyWeightScreenState
Future<void> nextButton() async { Future<void> nextButton() async {
await widget.athlete!.save(); await widget.athlete!.save();
debugPrint('OK'); debugPrint('OK');
Navigator.pushReplacement( if (context.mounted) {
context, Navigator.pushReplacement(
MaterialPageRoute<BuildContext>( context,
builder: (BuildContext _) => const OnboardingFinishedScreen(), MaterialPageRoute<BuildContext>(
), builder: (BuildContext _) => const OnboardingFinishedScreen(),
); ),
);
}
} }
} }

View File

@ -55,13 +55,15 @@ class OnboardingCreateUserScreenState
child: const Text('Create Demo User'), child: const Text('Create Demo User'),
onPressed: () async { onPressed: () async {
await setupDemoAthlete(context: context); await setupDemoAthlete(context: context);
await Navigator.pushReplacement( if (context.mounted) {
context, await Navigator.pushReplacement(
MaterialPageRoute<BuildContext>( context,
builder: (BuildContext _) => MaterialPageRoute<BuildContext>(
const OnboardingFinishedScreen(), builder: (BuildContext _) =>
), const OnboardingFinishedScreen(),
); ),
);
}
}, },
) )
], ],
@ -95,14 +97,16 @@ class OnboardingCreateUserScreenState
StravaGetUser(athlete: athlete), StravaGetUser(athlete: athlete),
), ),
); );
Navigator.pushReplacement( if (context.mounted) {
context, Navigator.pushReplacement(
MaterialPageRoute<BuildContext>( context,
builder: (BuildContext _) => MaterialPageRoute<BuildContext>(
OnBoardingStravaCredentialsScreen( builder: (BuildContext _) =>
athlete: athlete), OnBoardingStravaCredentialsScreen(
), athlete: athlete),
); ),
);
}
}, },
) )
], ],

View File

@ -77,13 +77,16 @@ class OnBoardingHeartRateZoneSchemaScreenState
Future<void> nextButton() async { Future<void> nextButton() async {
await widget.athlete!.save(); await widget.athlete!.save();
Navigator.pushReplacement( if (context.mounted) {
context, Navigator.pushReplacement(
MaterialPageRoute<BuildContext>( context,
builder: (BuildContext _) => OnBoardingBodyWeightScreen( MaterialPageRoute<BuildContext>(
athlete: widget.athlete, builder: (BuildContext _) =>
OnBoardingBodyWeightScreen(
athlete: widget.athlete,
),
), ),
), );
); }
} }
} }

View File

@ -75,13 +75,16 @@ class OnBoardingPowerZoneSchemaScreenState
Future<void> nextButton() async { Future<void> nextButton() async {
await widget.athlete!.save(); await widget.athlete!.save();
Navigator.pushReplacement( if (context.mounted) {
context, Navigator.pushReplacement(
MaterialPageRoute<BuildContext>( context,
builder: (BuildContext _) => OnBoardingHeartRateZoneSchemaScreen( MaterialPageRoute<BuildContext>(
athlete: widget.athlete, builder: (BuildContext _) =>
OnBoardingHeartRateZoneSchemaScreen(
athlete: widget.athlete,
),
), ),
), );
); }
} }
} }

View File

@ -474,18 +474,20 @@ class ShowActivityScreenState extends State<ShowActivityScreen> {
await widget.activity.autoTagger(athlete: widget.athlete); await widget.activity.autoTagger(athlete: widget.athlete);
ScaffoldMessenger.of(context).removeCurrentSnackBar(); if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).removeCurrentSnackBar();
SnackBar( ScaffoldMessenger.of(context).showSnackBar(
duration: const Duration(seconds: 2), SnackBar(
content: Row( duration: const Duration(seconds: 2),
children: [ content: Row(
MyIcon.finishedWhite, children: [
const Text(' Autotagging finished'), MyIcon.finishedWhite,
], const Text(' Autotagging finished'),
],
),
), ),
), );
); }
setState(() {}); setState(() {});
} }
@ -503,7 +505,9 @@ class ShowActivityScreenState extends State<ShowActivityScreen> {
Future<void> delete() async { Future<void> delete() async {
await widget.activity.delete(); await widget.activity.delete();
Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pop();
}
} }
Future<void> download() async { Future<void> download() async {
@ -521,26 +525,30 @@ class ShowActivityScreenState extends State<ShowActivityScreen> {
await widget.activity.download(athlete: widget.athlete); await widget.activity.download(athlete: widget.athlete);
ScaffoldMessenger.of(context).removeCurrentSnackBar(); if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).removeCurrentSnackBar();
SnackBar( ScaffoldMessenger.of(context).showSnackBar(
duration: const Duration(seconds: 1), SnackBar(
content: Row( duration: const Duration(seconds: 1),
children: [ content: Row(
MyIcon.finishedWhite, children: [
const Text(' Download finished'), MyIcon.finishedWhite,
], const Text(' Download finished'),
],
),
), ),
), );
); }
await parse(); await parse();
ScaffoldMessenger.of(context).showSnackBar( if (context.mounted) {
SnackBar( ScaffoldMessenger.of(context).showSnackBar(
duration: const Duration(seconds: 2), SnackBar(
content: Text('Analysis finished for »${widget.activity.name}«'), duration: const Duration(seconds: 2),
), content: Text('Analysis finished for »${widget.activity.name}«'),
); ),
);
}
} }
Future<void> parse() async { Future<void> parse() async {

View File

@ -332,12 +332,15 @@ class ShowAthleteScreenState extends State<ShowAthleteScreen> {
Future<void> goToEditAthleteScreen({required Athlete athlete}) async { Future<void> goToEditAthleteScreen({required Athlete athlete}) async {
await athlete.readCredentials(); await athlete.readCredentials();
await Navigator.push( if (context.mounted) {
context, await Navigator.push(
MaterialPageRoute<BuildContext>( context,
builder: (BuildContext context) => EditAthleteScreen(athlete: athlete), MaterialPageRoute<BuildContext>(
), builder: (BuildContext context) =>
); EditAthleteScreen(athlete: athlete),
),
);
}
} }
Future<void> goToEditActivityScreen({required Athlete athlete}) async { Future<void> goToEditActivityScreen({required Athlete athlete}) async {

View File

@ -177,7 +177,9 @@ class ShowIntervalScreen extends StatelessWidget {
onPressed: () async { onPressed: () async {
await interval.delete(); await interval.delete();
activity!.cachedIntervals = <encrateia.Interval>[]; activity!.cachedIntervals = <encrateia.Interval>[];
Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pop();
}
}, },
), ),
]; ];
@ -215,8 +217,7 @@ class ShowIntervalScreen extends StatelessWidget {
}) { }) {
return ElevatedButton.icon( return ElevatedButton.icon(
style: MyButtonStyle.raisedButtonStyle( style: MyButtonStyle.raisedButtonStyle(
color: color, color: color, textColor: MyColor.textColor(backgroundColor: color)),
textColor: MyColor.textColor(backgroundColor: color)),
icon: icon, icon: icon,
label: Expanded( label: Expanded(
child: Text(title), child: Text(title),

View File

@ -64,7 +64,9 @@ class StravaGetUserState extends State<StravaGetUser> {
setState(() {}); setState(() {});
} }
if (widget.athlete.state == 'fromStrava') { if (widget.athlete.state == 'fromStrava') {
Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pop();
}
} }
} }
} }

View File

@ -113,17 +113,19 @@ class ActivitiesListWidgetState extends State<ActivitiesListWidget> {
); );
await activity.download(athlete: widget.athlete); await activity.download(athlete: widget.athlete);
ScaffoldMessenger.of(context).showSnackBar( if (context.mounted) {
SnackBar( ScaffoldMessenger.of(context).showSnackBar(
duration: const Duration(seconds: 3), SnackBar(
content: Row( duration: const Duration(seconds: 3),
children: [ content: Row(
MyIcon.finishedWhite, children: [
const Text(' Download finished'), MyIcon.finishedWhite,
], const Text(' Download finished'),
],
),
), ),
), );
); }
setState(() {}); setState(() {});
} }

View File

@ -60,13 +60,17 @@ class EditActivityWidgetState extends State<EditActivityWidget> {
firstDate: DateTime(1969), firstDate: DateTime(1969),
initialDate: currentValue ?? DateTime.now(), initialDate: currentValue ?? DateTime.now(),
lastDate: DateTime(2100)); lastDate: DateTime(2100));
if (date != null) { if (context.mounted) {
final TimeOfDay? time = await showTimePicker( if (date != null) {
context: context, final TimeOfDay? time = await showTimePicker(
initialTime: TimeOfDay.fromDateTime( context: context,
currentValue ?? DateTime.now()), initialTime: TimeOfDay.fromDateTime(
); currentValue ?? DateTime.now()),
return DateTimeField.combine(date, time); );
return DateTimeField.combine(date, time);
} else {
return currentValue;
}
} else { } else {
return currentValue; return currentValue;
} }
@ -194,7 +198,9 @@ class EditActivityWidgetState extends State<EditActivityWidget> {
child: MyButton.save( child: MyButton.save(
onPressed: () async { onPressed: () async {
await widget.activity!.save(); await widget.activity!.save();
Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pop();
}
}, },
), ),
), ),

View File

@ -72,15 +72,19 @@ class EditStandaloneAthleteWidgetState
final List<PowerZoneSchema> powerZoneSchemas = final List<PowerZoneSchema> powerZoneSchemas =
await widget.athlete!.powerZoneSchemas; await widget.athlete!.powerZoneSchemas;
if (powerZoneSchemas.isEmpty) { if (powerZoneSchemas.isEmpty) {
Navigator.pushReplacement( if (context.mounted) {
context, Navigator.pushReplacement(
MaterialPageRoute<BuildContext>( context,
builder: (BuildContext _) => MaterialPageRoute<BuildContext>(
OnBoardingPowerZoneSchemaScreen(athlete: widget.athlete), builder: (BuildContext _) =>
), OnBoardingPowerZoneSchemaScreen(athlete: widget.athlete),
); ),
);
}
} else { } else {
Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pop();
}
} }
} }
} }

View File

@ -81,21 +81,24 @@ class EditStravaAthleteWidgetState extends State<EditStravaAthleteWidget> {
Future<void> saveStravaUser(BuildContext context) async { Future<void> saveStravaUser(BuildContext context) async {
await widget.athlete!.save(); await widget.athlete!.save();
await widget.athlete!.storeCredentials(); await widget.athlete!.storeCredentials();
ScaffoldMessenger.of(context).showSnackBar( if (context.mounted) {
SnackBar( ScaffoldMessenger.of(context).showSnackBar(
duration: const Duration(seconds: 10), SnackBar(
content: Row( duration: const Duration(seconds: 10),
children: [ content: Row(
MyIcon.information, children: [
const Text(' checking credentials...'), MyIcon.information,
], const Text(' checking credentials...'),
],
),
), ),
), );
); }
if (await StravaFitDownload.credentialsAreValid(athlete: widget.athlete!)) { if (await StravaFitDownload.credentialsAreValid(athlete: widget.athlete!)) {
final List<PowerZoneSchema> powerZoneSchemas = final List<PowerZoneSchema> powerZoneSchemas =
await widget.athlete!.powerZoneSchemas; await widget.athlete!.powerZoneSchemas;
if (context.mounted) {
ScaffoldMessenger.of(context).removeCurrentSnackBar(); ScaffoldMessenger.of(context).removeCurrentSnackBar();
if (powerZoneSchemas.isEmpty) { if (powerZoneSchemas.isEmpty) {
Navigator.pushReplacement( Navigator.pushReplacement(
@ -105,21 +108,24 @@ class EditStravaAthleteWidgetState extends State<EditStravaAthleteWidget> {
OnBoardingPowerZoneSchemaScreen(athlete: widget.athlete), OnBoardingPowerZoneSchemaScreen(athlete: widget.athlete),
), ),
); );
}
} else { } else {
Navigator.of(context).pop(); Navigator.of(context).pop();
} }
} else { } else {
ScaffoldMessenger.of(context).showSnackBar( if (context.mounted) {
SnackBar( ScaffoldMessenger.of(context).showSnackBar(
duration: const Duration(seconds: 5), SnackBar(
content: Row( duration: const Duration(seconds: 5),
children: [ content: Row(
MyIcon.error, children: [
const Text(' The credentials provided are invalid!'), MyIcon.error,
], const Text(' The credentials provided are invalid!'),
],
),
), ),
), );
); }
} }
} }
} }