diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 1fff293..77c2309 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_secure_storage","path":"/home/stefan/.pub-cache/hosted/pub.dev/flutter_secure_storage-8.0.0/","native_build":true,"dependencies":[]},{"name":"flutter_web_auth","path":"/home/stefan/.pub-cache/hosted/pub.dev/flutter_web_auth-0.5.0/","native_build":true,"dependencies":[]},{"name":"package_info","path":"/home/stefan/.pub-cache/hosted/pub.dev/package_info-2.0.2/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/home/stefan/.pub-cache/hosted/pub.dev/path_provider_foundation-2.2.1/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/home/stefan/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.2.0/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/home/stefan/.pub-cache/hosted/pub.dev/sqflite-2.2.6/","native_build":true,"dependencies":[]},{"name":"sqflite_sqlcipher","path":"/home/stefan/.pub-cache/hosted/pub.dev/sqflite_sqlcipher-2.1.1+1/","native_build":true,"dependencies":[]},{"name":"url_launcher_ios","path":"/home/stefan/.pub-cache/hosted/pub.dev/url_launcher_ios-6.1.3/","native_build":true,"dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"/home/stefan/.pub-cache/hosted/pub.dev/flutter_secure_storage-8.0.0/","native_build":true,"dependencies":[]},{"name":"flutter_web_auth","path":"/home/stefan/.pub-cache/hosted/pub.dev/flutter_web_auth-0.5.0/","native_build":true,"dependencies":[]},{"name":"package_info","path":"/home/stefan/.pub-cache/hosted/pub.dev/package_info-2.0.2/","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"/home/stefan/.pub-cache/hosted/pub.dev/path_provider_android-2.0.24/","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"/home/stefan/.pub-cache/hosted/pub.dev/shared_preferences_android-2.1.0/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/home/stefan/.pub-cache/hosted/pub.dev/sqflite-2.2.6/","native_build":true,"dependencies":[]},{"name":"sqflite_sqlcipher","path":"/home/stefan/.pub-cache/hosted/pub.dev/sqflite_sqlcipher-2.1.1+1/","native_build":true,"dependencies":[]},{"name":"url_launcher_android","path":"/home/stefan/.pub-cache/hosted/pub.dev/url_launcher_android-6.0.26/","native_build":true,"dependencies":[]}],"macos":[{"name":"flutter_secure_storage_macos","path":"/home/stefan/.pub-cache/hosted/pub.dev/flutter_secure_storage_macos-3.0.0/","native_build":true,"dependencies":[]},{"name":"flutter_web_auth","path":"/home/stefan/.pub-cache/hosted/pub.dev/flutter_web_auth-0.5.0/","native_build":true,"dependencies":[]},{"name":"package_info","path":"/home/stefan/.pub-cache/hosted/pub.dev/package_info-2.0.2/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/home/stefan/.pub-cache/hosted/pub.dev/path_provider_foundation-2.2.1/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/home/stefan/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.2.0/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/home/stefan/.pub-cache/hosted/pub.dev/sqflite-2.2.6/","native_build":true,"dependencies":[]},{"name":"sqflite_sqlcipher","path":"/home/stefan/.pub-cache/hosted/pub.dev/sqflite_sqlcipher-2.1.1+1/","native_build":true,"dependencies":[]},{"name":"url_launcher_macos","path":"/home/stefan/.pub-cache/hosted/pub.dev/url_launcher_macos-3.0.4/","native_build":true,"dependencies":[]}],"linux":[{"name":"flutter_secure_storage_linux","path":"/home/stefan/.pub-cache/hosted/pub.dev/flutter_secure_storage_linux-1.1.3/","native_build":true,"dependencies":[]},{"name":"path_provider_linux","path":"/home/stefan/.pub-cache/hosted/pub.dev/path_provider_linux-2.1.10/","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"/home/stefan/.pub-cache/hosted/pub.dev/shared_preferences_linux-2.2.0/","native_build":false,"dependencies":["path_provider_linux"]},{"name":"url_launcher_linux","path":"/home/stefan/.pub-cache/hosted/pub.dev/url_launcher_linux-3.0.4/","native_build":true,"dependencies":[]}],"windows":[{"name":"flutter_secure_storage_windows","path":"/home/stefan/.pub-cache/hosted/pub.dev/flutter_secure_storage_windows-2.0.0/","native_build":true,"dependencies":[]},{"name":"path_provider_windows","path":"/home/stefan/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.5/","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"/home/stefan/.pub-cache/hosted/pub.dev/shared_preferences_windows-2.2.0/","native_build":false,"dependencies":["path_provider_windows"]},{"name":"url_launcher_windows","path":"/home/stefan/.pub-cache/hosted/pub.dev/url_launcher_windows-3.0.5/","native_build":true,"dependencies":[]}],"web":[{"name":"flutter_secure_storage_web","path":"/home/stefan/.pub-cache/hosted/pub.dev/flutter_secure_storage_web-1.1.1/","dependencies":[]},{"name":"flutter_web_auth","path":"/home/stefan/.pub-cache/hosted/pub.dev/flutter_web_auth-0.5.0/","dependencies":[]},{"name":"shared_preferences_web","path":"/home/stefan/.pub-cache/hosted/pub.dev/shared_preferences_web-2.1.0/","dependencies":[]},{"name":"url_launcher_web","path":"/home/stefan/.pub-cache/hosted/pub.dev/url_launcher_web-2.0.16/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":["flutter_secure_storage_linux","flutter_secure_storage_macos","flutter_secure_storage_web","flutter_secure_storage_windows"]},{"name":"flutter_secure_storage_linux","dependencies":[]},{"name":"flutter_secure_storage_macos","dependencies":[]},{"name":"flutter_secure_storage_web","dependencies":[]},{"name":"flutter_secure_storage_windows","dependencies":[]},{"name":"flutter_web_auth","dependencies":[]},{"name":"package_info","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_foundation","shared_preferences_linux","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_foundation","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]},{"name":"sqflite","dependencies":[]},{"name":"sqflite_sqlcipher","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_android","url_launcher_ios","url_launcher_linux","url_launcher_macos","url_launcher_web","url_launcher_windows"]},{"name":"url_launcher_android","dependencies":[]},{"name":"url_launcher_ios","dependencies":[]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2023-04-06 09:58:43.861205","version":"3.7.9"} \ 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":"/home/stefan/.pub-cache/hosted/pub.dev/flutter_secure_storage-8.0.0/","native_build":true,"dependencies":[]},{"name":"flutter_web_auth","path":"/home/stefan/.pub-cache/hosted/pub.dev/flutter_web_auth-0.5.0/","native_build":true,"dependencies":[]},{"name":"package_info","path":"/home/stefan/.pub-cache/hosted/pub.dev/package_info-2.0.2/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/home/stefan/.pub-cache/hosted/pub.dev/path_provider_foundation-2.2.1/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/home/stefan/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.2.0/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/home/stefan/.pub-cache/hosted/pub.dev/sqflite-2.2.6/","native_build":true,"dependencies":[]},{"name":"sqflite_sqlcipher","path":"/home/stefan/.pub-cache/hosted/pub.dev/sqflite_sqlcipher-2.1.1+1/","native_build":true,"dependencies":[]},{"name":"url_launcher_ios","path":"/home/stefan/.pub-cache/hosted/pub.dev/url_launcher_ios-6.1.3/","native_build":true,"dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"/home/stefan/.pub-cache/hosted/pub.dev/flutter_secure_storage-8.0.0/","native_build":true,"dependencies":[]},{"name":"flutter_web_auth","path":"/home/stefan/.pub-cache/hosted/pub.dev/flutter_web_auth-0.5.0/","native_build":true,"dependencies":[]},{"name":"package_info","path":"/home/stefan/.pub-cache/hosted/pub.dev/package_info-2.0.2/","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"/home/stefan/.pub-cache/hosted/pub.dev/path_provider_android-2.0.24/","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"/home/stefan/.pub-cache/hosted/pub.dev/shared_preferences_android-2.1.0/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/home/stefan/.pub-cache/hosted/pub.dev/sqflite-2.2.6/","native_build":true,"dependencies":[]},{"name":"sqflite_sqlcipher","path":"/home/stefan/.pub-cache/hosted/pub.dev/sqflite_sqlcipher-2.1.1+1/","native_build":true,"dependencies":[]},{"name":"url_launcher_android","path":"/home/stefan/.pub-cache/hosted/pub.dev/url_launcher_android-6.0.26/","native_build":true,"dependencies":[]}],"macos":[{"name":"flutter_secure_storage_macos","path":"/home/stefan/.pub-cache/hosted/pub.dev/flutter_secure_storage_macos-3.0.0/","native_build":true,"dependencies":[]},{"name":"flutter_web_auth","path":"/home/stefan/.pub-cache/hosted/pub.dev/flutter_web_auth-0.5.0/","native_build":true,"dependencies":[]},{"name":"package_info","path":"/home/stefan/.pub-cache/hosted/pub.dev/package_info-2.0.2/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/home/stefan/.pub-cache/hosted/pub.dev/path_provider_foundation-2.2.1/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/home/stefan/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.2.0/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/home/stefan/.pub-cache/hosted/pub.dev/sqflite-2.2.6/","native_build":true,"dependencies":[]},{"name":"sqflite_sqlcipher","path":"/home/stefan/.pub-cache/hosted/pub.dev/sqflite_sqlcipher-2.1.1+1/","native_build":true,"dependencies":[]},{"name":"url_launcher_macos","path":"/home/stefan/.pub-cache/hosted/pub.dev/url_launcher_macos-3.0.4/","native_build":true,"dependencies":[]}],"linux":[{"name":"flutter_secure_storage_linux","path":"/home/stefan/.pub-cache/hosted/pub.dev/flutter_secure_storage_linux-1.1.3/","native_build":true,"dependencies":[]},{"name":"path_provider_linux","path":"/home/stefan/.pub-cache/hosted/pub.dev/path_provider_linux-2.1.10/","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"/home/stefan/.pub-cache/hosted/pub.dev/shared_preferences_linux-2.2.0/","native_build":false,"dependencies":["path_provider_linux"]},{"name":"url_launcher_linux","path":"/home/stefan/.pub-cache/hosted/pub.dev/url_launcher_linux-3.0.4/","native_build":true,"dependencies":[]}],"windows":[{"name":"flutter_secure_storage_windows","path":"/home/stefan/.pub-cache/hosted/pub.dev/flutter_secure_storage_windows-2.0.0/","native_build":true,"dependencies":[]},{"name":"path_provider_windows","path":"/home/stefan/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.5/","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"/home/stefan/.pub-cache/hosted/pub.dev/shared_preferences_windows-2.2.0/","native_build":false,"dependencies":["path_provider_windows"]},{"name":"url_launcher_windows","path":"/home/stefan/.pub-cache/hosted/pub.dev/url_launcher_windows-3.0.5/","native_build":true,"dependencies":[]}],"web":[{"name":"flutter_secure_storage_web","path":"/home/stefan/.pub-cache/hosted/pub.dev/flutter_secure_storage_web-1.1.1/","dependencies":[]},{"name":"flutter_web_auth","path":"/home/stefan/.pub-cache/hosted/pub.dev/flutter_web_auth-0.5.0/","dependencies":[]},{"name":"shared_preferences_web","path":"/home/stefan/.pub-cache/hosted/pub.dev/shared_preferences_web-2.1.0/","dependencies":[]},{"name":"url_launcher_web","path":"/home/stefan/.pub-cache/hosted/pub.dev/url_launcher_web-2.0.16/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":["flutter_secure_storage_linux","flutter_secure_storage_macos","flutter_secure_storage_web","flutter_secure_storage_windows"]},{"name":"flutter_secure_storage_linux","dependencies":[]},{"name":"flutter_secure_storage_macos","dependencies":[]},{"name":"flutter_secure_storage_web","dependencies":[]},{"name":"flutter_secure_storage_windows","dependencies":[]},{"name":"flutter_web_auth","dependencies":[]},{"name":"package_info","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_foundation","shared_preferences_linux","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_foundation","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]},{"name":"sqflite","dependencies":[]},{"name":"sqflite_sqlcipher","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_android","url_launcher_ios","url_launcher_linux","url_launcher_macos","url_launcher_web","url_launcher_windows"]},{"name":"url_launcher_android","dependencies":[]},{"name":"url_launcher_ios","dependencies":[]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2023-05-02 07:53:09.811533","version":"3.7.9"} \ No newline at end of file diff --git a/analysis_options.yaml b/analysis_options.yaml index fa91086..4dc9b9d 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -26,8 +26,6 @@ linter: # `// ignore_for_file: name_of_lint` syntax on the line or in the file # producing the lint. 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 # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule diff --git a/lib/actions/analyse_activities.dart b/lib/actions/analyse_activities.dart index 2563a16..41246fd 100644 --- a/lib/actions/analyse_activities.dart +++ b/lib/actions/analyse_activities.dart @@ -13,44 +13,55 @@ Future analyseActivities({ int index = 0; int percent; - ScaffoldMessenger.of(context).showSnackBar( - 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; + 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}«') - ]), + duration: const Duration(seconds: 5), + content: Row( + children: [ + MyIcon.finishedWhite, + const Text(' Calculating...'), + ], + ), ), ); } - ScaffoldMessenger.of(context).removeCurrentSnackBar(); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - duration: const Duration(seconds: 5), - content: Row( - children: [ - MyIcon.finishedWhite, - const Text(' Averages are now up to date.') - ], + for (final Activity activity in activities) { + index += 1; + await activity.setAverages(); + if (context.mounted) { + ScaffoldMessenger.of(context).removeCurrentSnackBar(); + } + percent = 100 * index ~/ activities.length; + 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.') + ], + ), ), - ), - ); + ); + } } diff --git a/lib/actions/auto_tagging.dart b/lib/actions/auto_tagging.dart index 87db03f..d96451c 100644 --- a/lib/actions/auto_tagging.dart +++ b/lib/actions/auto_tagging.dart @@ -10,17 +10,19 @@ Future autoTagging({ required Athlete athlete, }) async { if (await athlete.checkForSchemas()) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - duration: const Duration(seconds: 5), - content: Row( - children: [ - MyIcon.finishedWhite, - const Text('Started cleaning up...'), - ], + if (context.mounted) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + duration: const Duration(seconds: 5), + content: Row( + children: [ + MyIcon.finishedWhite, + const Text('Started cleaning up...'), + ], + ), ), - ), - ); + ); + } List activities; activities = await athlete.activities; @@ -28,61 +30,74 @@ Future autoTagging({ int percent; await TagGroup.deleteAllAutoTags(athlete: athlete); - ScaffoldMessenger.of(context).showSnackBar( - 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; - + 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}« )'), + MyIcon.finishedWhite, + const Text('All existing autotaggings have been deleted.'), ], ), ), ); } - ScaffoldMessenger.of(context).removeCurrentSnackBar(); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - duration: const Duration(seconds: 5), - content: Row( - children: [ - MyIcon.finishedWhite, - const Text(' Autotaggings are now up to date.'), - ], + for (final Activity activity in activities) { + index += 1; + await activity.autoTagger(athlete: athlete); + if (context.mounted) { + ScaffoldMessenger.of(context).removeCurrentSnackBar(); + } + percent = 100 * index ~/ activities.length; + + 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 { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - duration: const Duration(seconds: 5), - content: Row( - children: [ - MyIcon.finishedWhite, - const Text(' Please set up Power Zone Schema and ' - 'Heart Rate Zone Schema first!'), - ], + if (context.mounted) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + duration: const Duration(seconds: 5), + content: Row( + children: [ + MyIcon.finishedWhite, + const Text(' Please set up Power Zone Schema and ' + 'Heart Rate Zone Schema first!'), + ], + ), ), - ), - ); + ); + } } } diff --git a/lib/actions/download_activity.dart b/lib/actions/download_activity.dart index d793300..6a34042 100644 --- a/lib/actions/download_activity.dart +++ b/lib/actions/download_activity.dart @@ -21,16 +21,18 @@ Future downloadActivity({ await activity.download(athlete: athlete); - ScaffoldMessenger.of(context).removeCurrentSnackBar(); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - duration: const Duration(seconds: 2), - content: Row( - children: [ - MyIcon.finishedWhite, - const Text(' Download finished'), - ], + if (context.mounted) { + ScaffoldMessenger.of(context).removeCurrentSnackBar(); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + duration: const Duration(seconds: 2), + content: Row( + children: [ + MyIcon.finishedWhite, + const Text(' Download finished'), + ], + ), ), - ), - ); + ); + } } diff --git a/lib/actions/download_demo_data.dart b/lib/actions/download_demo_data.dart index 936030e..179d806 100644 --- a/lib/actions/download_demo_data.dart +++ b/lib/actions/download_demo_data.dart @@ -24,17 +24,19 @@ Future downloadDemoData({ 'upper_palatinate_winter_challenge_half_marathon.fit', ]; - ScaffoldMessenger.of(context).removeCurrentSnackBar(); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Row( - children: [ - MyIcon.stravaDownloadWhite, - const Text(' Downloading Demo data ...'), - ], + if (context.mounted) { + ScaffoldMessenger.of(context).removeCurrentSnackBar(); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Row( + children: [ + MyIcon.stravaDownloadWhite, + const Text(' Downloading Demo data ...'), + ], + ), ), - ), - ); + ); + } for (final String filename in fileNames) { final Activity activity = Activity.fromLocalDirectory(athlete: athlete); @@ -52,37 +54,44 @@ Future downloadDemoData({ activity.excluded != true) .toList(); for (final Activity activity in downloadedActivities) { - await parseActivity( - context: context, - activity: activity, - athlete: athlete, - ); - ScaffoldMessenger.of(context).removeCurrentSnackBar(); - - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(' Tagging »${activity.name}«')), - ); + if (context.mounted) { + await parseActivity( + context: context, + activity: activity, + athlete: athlete, + ); + } + if (context.mounted) { + ScaffoldMessenger.of(context).removeCurrentSnackBar(); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text(' Tagging »${activity.name}«')), + ); + } await activity.autoTagger(athlete: athlete); } - ScaffoldMessenger.of(context).removeCurrentSnackBar(); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Row( - children: [ - MyIcon.finishedWhite, - const Text(' Activities imported!'), - ], + if (context.mounted) { + ScaffoldMessenger.of(context).removeCurrentSnackBar(); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Row( + children: [ + MyIcon.finishedWhite, + const Text(' Activities imported!'), + ], + ), ), - ), - ); + ); + } } else { - ScaffoldMessenger.of(context).removeCurrentSnackBar(); - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text(' Please set up Power Zone Schema and Heart' - ' Rate Zone Schema first!'), - ), - ); + if (context.mounted) { + ScaffoldMessenger.of(context).removeCurrentSnackBar(); + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text(' Please set up Power Zone Schema and Heart' + ' Rate Zone Schema first!'), + ), + ); + } } } diff --git a/lib/actions/import_activities_locally.dart b/lib/actions/import_activities_locally.dart index ee0c0f3..afdcecf 100644 --- a/lib/actions/import_activities_locally.dart +++ b/lib/actions/import_activities_locally.dart @@ -23,17 +23,19 @@ Future importActivitiesLocally({ ); await Activity.importFromLocalDirectory(athlete: athlete); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - duration: const Duration(seconds: 1), - content: Row( - children: [ - MyIcon.finishedWhite, - const Text(' Activities moved into application'), - ], + if (context.mounted) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + duration: const Duration(seconds: 1), + content: Row( + children: [ + MyIcon.finishedWhite, + const Text(' Activities moved into application'), + ], + ), ), - ), - ); + ); + } activities = await athlete.activities; final List downloadedActivities = activities @@ -44,23 +46,28 @@ Future importActivitiesLocally({ activity.excluded != true) .toList(); for (final Activity activity in downloadedActivities) { - await parseActivity( - context: context, - activity: activity, - athlete: athlete, - ); + if (context.mounted) { + await parseActivity( + context: context, + activity: activity, + athlete: athlete, + ); + } await activity.autoTagger(athlete: athlete); } - ScaffoldMessenger.of(context).removeCurrentSnackBar(); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - duration: const Duration(seconds: 5), - content: Row( - children: [ - MyIcon.finishedWhite, - const Text(' Activities imported!'), - ], + + if (context.mounted) { + ScaffoldMessenger.of(context).removeCurrentSnackBar(); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + duration: const Duration(seconds: 5), + content: Row( + children: [ + MyIcon.finishedWhite, + const Text(' Activities imported!'), + ], + ), ), - ), - ); + ); + } } diff --git a/lib/actions/parse_activity.dart b/lib/actions/parse_activity.dart index 703842e..8c752dc 100644 --- a/lib/actions/parse_activity.dart +++ b/lib/actions/parse_activity.dart @@ -60,12 +60,14 @@ Future parseActivity({ await log.save(); activity.nonParsable = true; await activity.save(); - ScaffoldMessenger.of(context).removeCurrentSnackBar(); - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - duration: Duration(seconds: 2), - content: Text('Error, see log on home screen for details')), - ); + if (context.mounted) { + ScaffoldMessenger.of(context).removeCurrentSnackBar(); + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + duration: Duration(seconds: 2), + content: Text('Error, see log on home screen for details')), + ); + } } } diff --git a/lib/actions/query_strava.dart b/lib/actions/query_strava.dart index da6afaf..bb9d748 100644 --- a/lib/actions/query_strava.dart +++ b/lib/actions/query_strava.dart @@ -19,16 +19,18 @@ Future queryStrava({ ); await athlete.queryStrava(); - ScaffoldMessenger.of(context).removeCurrentSnackBar(); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - duration: const Duration(seconds: 1), - content: Row( - children: [ - MyIcon.finishedWhite, - const Text('Download finished'), - ], + if (context.mounted) { + ScaffoldMessenger.of(context).removeCurrentSnackBar(); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + duration: const Duration(seconds: 1), + content: Row( + children: [ + MyIcon.finishedWhite, + const Text('Download finished'), + ], + ), ), - ), - ); + ); + } } diff --git a/lib/actions/setup_demo_athlete.dart b/lib/actions/setup_demo_athlete.dart index ba7e79d..440c1fa 100644 --- a/lib/actions/setup_demo_athlete.dart +++ b/lib/actions/setup_demo_athlete.dart @@ -25,10 +25,13 @@ Future setupDemoAthlete({ weight.date = DateTime(2015); await weight.save(); - await downloadDemoData( - context: context, - athlete: athlete, - ); - - ScaffoldMessenger.of(context).removeCurrentSnackBar(); + if (context.mounted) { + await downloadDemoData( + context: context, + athlete: athlete, + ); + } + if (context.mounted) { + ScaffoldMessenger.of(context).removeCurrentSnackBar(); + } } diff --git a/lib/actions/update_job.dart b/lib/actions/update_job.dart index df4a004..86394cd 100644 --- a/lib/actions/update_job.dart +++ b/lib/actions/update_job.dart @@ -13,20 +13,24 @@ Future updateJob({ List activities; if (await athlete.checkForSchemas()) { - await queryStrava( - context: context, - athlete: athlete, - ); + if (context.mounted) { + await queryStrava( + context: context, + athlete: athlete, + ); + } activities = await athlete.activities; final Iterable newActivities = activities.where((Activity activity) => activity.state == 'new'); for (final Activity activity in newActivities) { - await downloadActivity( - context: context, - activity: activity, - athlete: athlete, - ); + if (context.mounted) { + await downloadActivity( + context: context, + activity: activity, + athlete: athlete, + ); + } } final Iterable downloadedActivities = activities.where( @@ -36,37 +40,44 @@ Future updateJob({ activity.nonParsable != true && activity.excluded != true); for (final Activity activity in downloadedActivities) { - await parseActivity( - context: context, - activity: activity, - athlete: athlete, - ); + if (context.mounted) { + await parseActivity( + context: context, + activity: activity, + athlete: athlete, + ); + } await activity.autoTagger(athlete: athlete); } - ScaffoldMessenger.of(context).removeCurrentSnackBar(); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - duration: const Duration(seconds: 5), - content: Row( - children: [ - MyIcon.finishedWhite, - const Text(' You are now up to date!'), - ], + + if (context.mounted) { + ScaffoldMessenger.of(context).removeCurrentSnackBar(); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + duration: const Duration(seconds: 5), + content: Row( + children: [ + MyIcon.finishedWhite, + const Text(' You are now up to date!'), + ], + ), ), - ), - ); + ); + } } else { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - duration: const Duration(seconds: 5), - content: Row( - children: [ - MyIcon.finishedWhite, - const Text(' Please set up Power Zone Schema and ' - 'Heart Rate Zone Schema first!'), - ], + if (context.mounted) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + duration: const Duration(seconds: 5), + content: Row( + children: [ + MyIcon.finishedWhite, + const Text(' Please set up Power Zone Schema and ' + 'Heart Rate Zone Schema first!'), + ], + ), ), - ), - ); + ); + } } } diff --git a/lib/screens/add_heart_rate_zone_schema_screen.dart b/lib/screens/add_heart_rate_zone_schema_screen.dart index 012b350..6eb4cc0 100644 --- a/lib/screens/add_heart_rate_zone_schema_screen.dart +++ b/lib/screens/add_heart_rate_zone_schema_screen.dart @@ -189,7 +189,9 @@ class AddHeartRateZoneSchemaScreenState Future saveHeartRateZoneSchema(BuildContext context) async { await widget.heartRateZoneSchema.save(); await HeartRateZone.upsertAll(heartRateZones); - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } } Future getData() async { @@ -200,7 +202,9 @@ class AddHeartRateZoneSchemaScreenState Future deleteHeartRateZoneSchema( {required HeartRateZoneSchema heartRateZoneSchema}) async { await heartRateZoneSchema.delete(); - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } } void updateHeartRateZoneBase({int? base}) { @@ -227,21 +231,25 @@ class AddHeartRateZoneSchemaScreenState } await HeartRateZone.upsertAll(heartRateZones); await getData(); - showDialog( - context: context, - builder: (_) => AlertDialog( - title: const Text('Heart Rate Zone Schema has been copied'), - content: const Text( - 'If you only wanted to fix the date you need to delete the old heart' - ' rate zone schema manually.'), - actions: [ - ElevatedButton( - style: MyButtonStyle.raisedButtonStyle(color: MyColor.primary), - child: const Text('OK'), - onPressed: () => Navigator.of(context).pop(), - ), - ], - ), - ); + if (context.mounted) { + showDialog( + context: context, + builder: (_) => + AlertDialog( + title: const Text('Heart Rate Zone Schema has been copied'), + content: const Text( + 'If you only wanted to fix the date you need to delete the old heart' + ' rate zone schema manually.'), + actions: [ + ElevatedButton( + style: MyButtonStyle.raisedButtonStyle( + color: MyColor.primary), + child: const Text('OK'), + onPressed: () => Navigator.of(context).pop(), + ), + ], + ), + ); + } } } diff --git a/lib/screens/add_heart_rate_zone_screen.dart b/lib/screens/add_heart_rate_zone_screen.dart index 74a7572..122b5ee 100644 --- a/lib/screens/add_heart_rate_zone_screen.dart +++ b/lib/screens/add_heart_rate_zone_screen.dart @@ -169,11 +169,15 @@ class AddHeartRateZoneScreenState extends State { Future saveHeartRateZone(BuildContext context) async { await widget.heartRateZone!.save(); - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } } Future deleteHeartRateZone(BuildContext context) async { await widget.heartRateZone!.delete(); - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } } } diff --git a/lib/screens/add_power_zone_schema_screen.dart b/lib/screens/add_power_zone_schema_screen.dart index 1c6e9a4..8d334c6 100644 --- a/lib/screens/add_power_zone_schema_screen.dart +++ b/lib/screens/add_power_zone_schema_screen.dart @@ -182,7 +182,9 @@ class AddPowerZoneSchemaScreenState extends State { Future savePowerZoneSchema(BuildContext context) async { await widget.powerZoneSchema.save(); await PowerZone.upsertAll(powerZones); - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } } Future getData() async { @@ -193,7 +195,9 @@ class AddPowerZoneSchemaScreenState extends State { Future deletePowerZoneSchema( {required PowerZoneSchema powerZoneSchema}) async { await powerZoneSchema.delete(); - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } } Future? updatePowerZoneBase({int? base}) { @@ -221,21 +225,26 @@ class AddPowerZoneSchemaScreenState extends State { } await PowerZone.upsertAll(powerZones); await getData(); - showDialog( - context: context, - builder: (_) => AlertDialog( - title: const Text('Power Zone Schema has been copied'), - content: const Text( - 'If you only wanted to fix the date you need to delete the old ' - 'power zone schema manually.'), - actions: [ - ElevatedButton( - style: MyButtonStyle.raisedButtonStyle(color: MyColor.primary), - child: const Text('OK'), - onPressed: () => Navigator.of(context).pop(), - ), - ], - ), - ); + + if (context.mounted) { + showDialog( + context: context, + builder: (_) => + AlertDialog( + title: const Text('Power Zone Schema has been copied'), + content: const Text( + 'If you only wanted to fix the date you need to delete the old ' + 'power zone schema manually.'), + actions: [ + ElevatedButton( + style: MyButtonStyle.raisedButtonStyle( + color: MyColor.primary), + child: const Text('OK'), + onPressed: () => Navigator.of(context).pop(), + ), + ], + ), + ); + } } } diff --git a/lib/screens/add_power_zone_screen.dart b/lib/screens/add_power_zone_screen.dart index 864940f..6772429 100644 --- a/lib/screens/add_power_zone_screen.dart +++ b/lib/screens/add_power_zone_screen.dart @@ -166,11 +166,15 @@ class AddPowerZoneScreenState extends State { Future savePowerZone(BuildContext context) async { await widget.powerZone!.save(); - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } } Future deletePowerZone(BuildContext context) async { await widget.powerZone!.delete(); - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } } } diff --git a/lib/screens/add_tag_group_screen.dart b/lib/screens/add_tag_group_screen.dart index ad0eac1..97c8c58 100644 --- a/lib/screens/add_tag_group_screen.dart +++ b/lib/screens/add_tag_group_screen.dart @@ -180,7 +180,9 @@ class AddTagGroupScreenState extends State { Future saveTagGroup(BuildContext context) async { await widget.tagGroup!.save(); await Tag.upsertAll(tags); - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } } Future getData() async { @@ -190,6 +192,8 @@ class AddTagGroupScreenState extends State { Future deleteTagGroup({required TagGroup tagGroup}) async { await tagGroup.delete(); - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } } } diff --git a/lib/screens/add_tag_screen.dart b/lib/screens/add_tag_screen.dart index eaa8d90..19dc2dc 100644 --- a/lib/screens/add_tag_screen.dart +++ b/lib/screens/add_tag_screen.dart @@ -105,11 +105,15 @@ class AddTagScreenState extends State { Future saveTag(BuildContext context) async { await widget.tag!.save(); - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } } Future deleteTag(BuildContext context) async { await widget.tag!.delete(); - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } } } diff --git a/lib/screens/add_weight_screen.dart b/lib/screens/add_weight_screen.dart index 82004f8..567d065 100644 --- a/lib/screens/add_weight_screen.dart +++ b/lib/screens/add_weight_screen.dart @@ -66,11 +66,15 @@ class AddWeightScreen extends StatelessWidget { Future saveWeight(BuildContext context) async { await weight!.save(); - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } } Future deleteWeight(BuildContext context) async { await weight!.delete(); - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } } } diff --git a/lib/screens/dashboard.dart b/lib/screens/dashboard.dart index 8871cf0..f497fcd 100644 --- a/lib/screens/dashboard.dart +++ b/lib/screens/dashboard.dart @@ -52,13 +52,15 @@ class DashboardState extends State { title: Text('${athlete.firstName} ${athlete.lastName}'), onTap: () async { await athlete.readCredentials(); - await Navigator.push( - context, - MaterialPageRoute( - builder: (BuildContext context) => - ShowAthleteScreen(athlete: athlete), - ), - ); + if (context.mounted) { + await Navigator.push( + context, + MaterialPageRoute( + builder: (BuildContext context) => + ShowAthleteScreen(athlete: athlete), + ), + ); + } await getData(); }, ), @@ -107,13 +109,15 @@ class DashboardState extends State { athletes = await Athlete.all(); logs = await Log.one(); if (athletes.isEmpty) { - await Navigator.pushReplacement( - context, - MaterialPageRoute( - builder: (BuildContext context) => - const OnboardingIntroductionScreen(), - ), - ); + if (context.mounted) { + await Navigator.pushReplacement( + context, + MaterialPageRoute( + builder: (BuildContext context) => + const OnboardingIntroductionScreen(), + ), + ); + } } else { final PackageInfo packageInfo = await PackageInfo.fromPlatform(); version = packageInfo.version; diff --git a/lib/screens/edit_event_screen.dart b/lib/screens/edit_event_screen.dart index 4b4297f..2a5679d 100644 --- a/lib/screens/edit_event_screen.dart +++ b/lib/screens/edit_event_screen.dart @@ -74,13 +74,17 @@ class EditEventScreenState extends State { firstDate: DateTime(1969), initialDate: currentValue ?? DateTime.now(), lastDate: DateTime(2100)); - if (date != null) { - final TimeOfDay? time = await showTimePicker( - context: context, - initialTime: TimeOfDay.fromDateTime( - currentValue ?? DateTime.now()), - ); - return DateTimeField.combine(date, time); + if (context.mounted) { + if (date != null) { + final TimeOfDay? time = await showTimePicker( + context: context, + initialTime: TimeOfDay.fromDateTime( + currentValue ?? DateTime.now()), + ); + return DateTimeField.combine(date, time); + } else { + return currentValue; + } } else { return currentValue; } @@ -270,7 +274,9 @@ class EditEventScreenState extends State { child: MyButton.save( onPressed: () async { await widget.record!.save(); - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } }, ), ), diff --git a/lib/screens/onboarding_screens/onboarding_body_weight_screen.dart b/lib/screens/onboarding_screens/onboarding_body_weight_screen.dart index 1e6d24c..339c989 100644 --- a/lib/screens/onboarding_screens/onboarding_body_weight_screen.dart +++ b/lib/screens/onboarding_screens/onboarding_body_weight_screen.dart @@ -71,11 +71,13 @@ class OnBoardingBodyWeightScreenState Future nextButton() async { await widget.athlete!.save(); debugPrint('OK'); - Navigator.pushReplacement( - context, - MaterialPageRoute( - builder: (BuildContext _) => const OnboardingFinishedScreen(), - ), - ); + if (context.mounted) { + Navigator.pushReplacement( + context, + MaterialPageRoute( + builder: (BuildContext _) => const OnboardingFinishedScreen(), + ), + ); + } } } diff --git a/lib/screens/onboarding_screens/onboarding_create_user.dart b/lib/screens/onboarding_screens/onboarding_create_user.dart index ed8915c..2e4529c 100644 --- a/lib/screens/onboarding_screens/onboarding_create_user.dart +++ b/lib/screens/onboarding_screens/onboarding_create_user.dart @@ -55,13 +55,15 @@ class OnboardingCreateUserScreenState child: const Text('Create Demo User'), onPressed: () async { await setupDemoAthlete(context: context); - await Navigator.pushReplacement( - context, - MaterialPageRoute( - builder: (BuildContext _) => - const OnboardingFinishedScreen(), - ), - ); + if (context.mounted) { + await Navigator.pushReplacement( + context, + MaterialPageRoute( + builder: (BuildContext _) => + const OnboardingFinishedScreen(), + ), + ); + } }, ) ], @@ -95,14 +97,16 @@ class OnboardingCreateUserScreenState StravaGetUser(athlete: athlete), ), ); - Navigator.pushReplacement( - context, - MaterialPageRoute( - builder: (BuildContext _) => - OnBoardingStravaCredentialsScreen( - athlete: athlete), - ), - ); + if (context.mounted) { + Navigator.pushReplacement( + context, + MaterialPageRoute( + builder: (BuildContext _) => + OnBoardingStravaCredentialsScreen( + athlete: athlete), + ), + ); + } }, ) ], diff --git a/lib/screens/onboarding_screens/onboarding_heart_rate_zone_schema_screen.dart b/lib/screens/onboarding_screens/onboarding_heart_rate_zone_schema_screen.dart index 0b35a07..2eed92e 100644 --- a/lib/screens/onboarding_screens/onboarding_heart_rate_zone_schema_screen.dart +++ b/lib/screens/onboarding_screens/onboarding_heart_rate_zone_schema_screen.dart @@ -77,13 +77,16 @@ class OnBoardingHeartRateZoneSchemaScreenState Future nextButton() async { await widget.athlete!.save(); - Navigator.pushReplacement( - context, - MaterialPageRoute( - builder: (BuildContext _) => OnBoardingBodyWeightScreen( - athlete: widget.athlete, + if (context.mounted) { + Navigator.pushReplacement( + context, + MaterialPageRoute( + builder: (BuildContext _) => + OnBoardingBodyWeightScreen( + athlete: widget.athlete, + ), ), - ), - ); + ); + } } } diff --git a/lib/screens/onboarding_screens/onboarding_power_zone_schema_screen.dart b/lib/screens/onboarding_screens/onboarding_power_zone_schema_screen.dart index 4d0a88a..7ad6a2e 100644 --- a/lib/screens/onboarding_screens/onboarding_power_zone_schema_screen.dart +++ b/lib/screens/onboarding_screens/onboarding_power_zone_schema_screen.dart @@ -75,13 +75,16 @@ class OnBoardingPowerZoneSchemaScreenState Future nextButton() async { await widget.athlete!.save(); - Navigator.pushReplacement( - context, - MaterialPageRoute( - builder: (BuildContext _) => OnBoardingHeartRateZoneSchemaScreen( - athlete: widget.athlete, + if (context.mounted) { + Navigator.pushReplacement( + context, + MaterialPageRoute( + builder: (BuildContext _) => + OnBoardingHeartRateZoneSchemaScreen( + athlete: widget.athlete, + ), ), - ), - ); + ); + } } } diff --git a/lib/screens/show_activity_screen.dart b/lib/screens/show_activity_screen.dart index 025acba..557cf98 100644 --- a/lib/screens/show_activity_screen.dart +++ b/lib/screens/show_activity_screen.dart @@ -474,18 +474,20 @@ class ShowActivityScreenState extends State { await widget.activity.autoTagger(athlete: widget.athlete); - ScaffoldMessenger.of(context).removeCurrentSnackBar(); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - duration: const Duration(seconds: 2), - content: Row( - children: [ - MyIcon.finishedWhite, - const Text(' Autotagging finished'), - ], + if (context.mounted) { + ScaffoldMessenger.of(context).removeCurrentSnackBar(); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + duration: const Duration(seconds: 2), + content: Row( + children: [ + MyIcon.finishedWhite, + const Text(' Autotagging finished'), + ], + ), ), - ), - ); + ); + } setState(() {}); } @@ -503,7 +505,9 @@ class ShowActivityScreenState extends State { Future delete() async { await widget.activity.delete(); - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } } Future download() async { @@ -521,26 +525,30 @@ class ShowActivityScreenState extends State { await widget.activity.download(athlete: widget.athlete); - ScaffoldMessenger.of(context).removeCurrentSnackBar(); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - duration: const Duration(seconds: 1), - content: Row( - children: [ - MyIcon.finishedWhite, - const Text(' Download finished'), - ], + if (context.mounted) { + ScaffoldMessenger.of(context).removeCurrentSnackBar(); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + duration: const Duration(seconds: 1), + content: Row( + children: [ + MyIcon.finishedWhite, + const Text(' Download finished'), + ], + ), ), - ), - ); + ); + } await parse(); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - duration: const Duration(seconds: 2), - content: Text('Analysis finished for »${widget.activity.name}«'), - ), - ); + if (context.mounted) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + duration: const Duration(seconds: 2), + content: Text('Analysis finished for »${widget.activity.name}«'), + ), + ); + } } Future parse() async { diff --git a/lib/screens/show_athlete_screen.dart b/lib/screens/show_athlete_screen.dart index 52175f4..1b85bdc 100644 --- a/lib/screens/show_athlete_screen.dart +++ b/lib/screens/show_athlete_screen.dart @@ -332,12 +332,15 @@ class ShowAthleteScreenState extends State { Future goToEditAthleteScreen({required Athlete athlete}) async { await athlete.readCredentials(); - await Navigator.push( - context, - MaterialPageRoute( - builder: (BuildContext context) => EditAthleteScreen(athlete: athlete), - ), - ); + if (context.mounted) { + await Navigator.push( + context, + MaterialPageRoute( + builder: (BuildContext context) => + EditAthleteScreen(athlete: athlete), + ), + ); + } } Future goToEditActivityScreen({required Athlete athlete}) async { diff --git a/lib/screens/show_interval_screen.dart b/lib/screens/show_interval_screen.dart index 893c9f5..825f80e 100644 --- a/lib/screens/show_interval_screen.dart +++ b/lib/screens/show_interval_screen.dart @@ -177,7 +177,9 @@ class ShowIntervalScreen extends StatelessWidget { onPressed: () async { await interval.delete(); activity!.cachedIntervals = []; - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } }, ), ]; @@ -215,8 +217,7 @@ class ShowIntervalScreen extends StatelessWidget { }) { return ElevatedButton.icon( style: MyButtonStyle.raisedButtonStyle( - color: color, - textColor: MyColor.textColor(backgroundColor: color)), + color: color, textColor: MyColor.textColor(backgroundColor: color)), icon: icon, label: Expanded( child: Text(title), diff --git a/lib/screens/strava_get_user.dart b/lib/screens/strava_get_user.dart index f058585..45b19a7 100644 --- a/lib/screens/strava_get_user.dart +++ b/lib/screens/strava_get_user.dart @@ -64,7 +64,9 @@ class StravaGetUserState extends State { setState(() {}); } if (widget.athlete.state == 'fromStrava') { - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } } } } diff --git a/lib/widgets/activities_list_widget.dart b/lib/widgets/activities_list_widget.dart index 7839836..9328c58 100644 --- a/lib/widgets/activities_list_widget.dart +++ b/lib/widgets/activities_list_widget.dart @@ -113,17 +113,19 @@ class ActivitiesListWidgetState extends State { ); await activity.download(athlete: widget.athlete); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - duration: const Duration(seconds: 3), - content: Row( - children: [ - MyIcon.finishedWhite, - const Text(' Download finished'), - ], + if (context.mounted) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + duration: const Duration(seconds: 3), + content: Row( + children: [ + MyIcon.finishedWhite, + const Text(' Download finished'), + ], + ), ), - ), - ); + ); + } setState(() {}); } diff --git a/lib/widgets/activity_widgets/edit_activity_widget.dart b/lib/widgets/activity_widgets/edit_activity_widget.dart index 0c2af50..0177244 100644 --- a/lib/widgets/activity_widgets/edit_activity_widget.dart +++ b/lib/widgets/activity_widgets/edit_activity_widget.dart @@ -60,13 +60,17 @@ class EditActivityWidgetState extends State { firstDate: DateTime(1969), initialDate: currentValue ?? DateTime.now(), lastDate: DateTime(2100)); - if (date != null) { - final TimeOfDay? time = await showTimePicker( - context: context, - initialTime: TimeOfDay.fromDateTime( - currentValue ?? DateTime.now()), - ); - return DateTimeField.combine(date, time); + if (context.mounted) { + if (date != null) { + final TimeOfDay? time = await showTimePicker( + context: context, + initialTime: TimeOfDay.fromDateTime( + currentValue ?? DateTime.now()), + ); + return DateTimeField.combine(date, time); + } else { + return currentValue; + } } else { return currentValue; } @@ -194,7 +198,9 @@ class EditActivityWidgetState extends State { child: MyButton.save( onPressed: () async { await widget.activity!.save(); - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } }, ), ), diff --git a/lib/widgets/athlete_widgets/edit_standalone_athlete_widget.dart b/lib/widgets/athlete_widgets/edit_standalone_athlete_widget.dart index 7e43a5e..372d872 100644 --- a/lib/widgets/athlete_widgets/edit_standalone_athlete_widget.dart +++ b/lib/widgets/athlete_widgets/edit_standalone_athlete_widget.dart @@ -72,15 +72,19 @@ class EditStandaloneAthleteWidgetState final List powerZoneSchemas = await widget.athlete!.powerZoneSchemas; if (powerZoneSchemas.isEmpty) { - Navigator.pushReplacement( - context, - MaterialPageRoute( - builder: (BuildContext _) => - OnBoardingPowerZoneSchemaScreen(athlete: widget.athlete), - ), - ); + if (context.mounted) { + Navigator.pushReplacement( + context, + MaterialPageRoute( + builder: (BuildContext _) => + OnBoardingPowerZoneSchemaScreen(athlete: widget.athlete), + ), + ); + } } else { - Navigator.of(context).pop(); + if (context.mounted) { + Navigator.of(context).pop(); + } } } } diff --git a/lib/widgets/athlete_widgets/edit_strava_athlete_widget.dart b/lib/widgets/athlete_widgets/edit_strava_athlete_widget.dart index 027405a..0bdd921 100644 --- a/lib/widgets/athlete_widgets/edit_strava_athlete_widget.dart +++ b/lib/widgets/athlete_widgets/edit_strava_athlete_widget.dart @@ -81,21 +81,24 @@ class EditStravaAthleteWidgetState extends State { Future saveStravaUser(BuildContext context) async { await widget.athlete!.save(); await widget.athlete!.storeCredentials(); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - duration: const Duration(seconds: 10), - content: Row( - children: [ - MyIcon.information, - const Text(' checking credentials...'), - ], + if (context.mounted) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + duration: const Duration(seconds: 10), + content: Row( + children: [ + MyIcon.information, + const Text(' checking credentials...'), + ], + ), ), - ), - ); + ); + } if (await StravaFitDownload.credentialsAreValid(athlete: widget.athlete!)) { final List powerZoneSchemas = await widget.athlete!.powerZoneSchemas; + if (context.mounted) { ScaffoldMessenger.of(context).removeCurrentSnackBar(); if (powerZoneSchemas.isEmpty) { Navigator.pushReplacement( @@ -105,21 +108,24 @@ class EditStravaAthleteWidgetState extends State { OnBoardingPowerZoneSchemaScreen(athlete: widget.athlete), ), ); + } } else { Navigator.of(context).pop(); } } else { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - duration: const Duration(seconds: 5), - content: Row( - children: [ - MyIcon.error, - const Text(' The credentials provided are invalid!'), - ], + if (context.mounted) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + duration: const Duration(seconds: 5), + content: Row( + children: [ + MyIcon.error, + const Text(' The credentials provided are invalid!'), + ], + ), ), - ), - ); + ); + } } } }