Browse Source

fix all build context warnings

master
Haslinger Stefan (extern) 1 month ago
parent
commit
e6352a33bc
  1. 2
      .flutter-plugins-dependencies
  2. 2
      analysis_options.yaml
  3. 69
      lib/actions/analyse_activities.dart
  4. 111
      lib/actions/auto_tagging.dart
  5. 24
      lib/actions/download_activity.dart
  6. 83
      lib/actions/download_demo_data.dart
  7. 59
      lib/actions/import_activities_locally.dart
  8. 14
      lib/actions/parse_activity.dart
  9. 24
      lib/actions/query_strava.dart
  10. 15
      lib/actions/setup_demo_athlete.dart
  11. 83
      lib/actions/update_job.dart
  12. 44
      lib/screens/add_heart_rate_zone_schema_screen.dart
  13. 8
      lib/screens/add_heart_rate_zone_screen.dart
  14. 45
      lib/screens/add_power_zone_schema_screen.dart
  15. 8
      lib/screens/add_power_zone_screen.dart
  16. 8
      lib/screens/add_tag_group_screen.dart
  17. 8
      lib/screens/add_tag_screen.dart
  18. 8
      lib/screens/add_weight_screen.dart
  19. 32
      lib/screens/dashboard.dart
  20. 22
      lib/screens/edit_event_screen.dart
  21. 14
      lib/screens/onboarding_screens/onboarding_body_weight_screen.dart
  22. 34
      lib/screens/onboarding_screens/onboarding_create_user.dart
  23. 17
      lib/screens/onboarding_screens/onboarding_heart_rate_zone_schema_screen.dart
  24. 17
      lib/screens/onboarding_screens/onboarding_power_zone_schema_screen.dart
  25. 66
      lib/screens/show_activity_screen.dart
  26. 15
      lib/screens/show_athlete_screen.dart
  27. 7
      lib/screens/show_interval_screen.dart
  28. 4
      lib/screens/strava_get_user.dart
  29. 22
      lib/widgets/activities_list_widget.dart
  30. 22
      lib/widgets/activity_widgets/edit_activity_widget.dart
  31. 20
      lib/widgets/athlete_widgets/edit_standalone_athlete_widget.dart
  32. 46
      lib/widgets/athlete_widgets/edit_strava_athlete_widget.dart

2
.flutter-plugins-dependencies

File diff suppressed because one or more lines are too long

2
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

69
lib/actions/analyse_activities.dart

@ -13,44 +13,55 @@ Future<void> analyseActivities({
int index = 0;
int percent;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
duration: const Duration(seconds: 5),
content: Row(
children: [
MyIcon.finishedWhite,
const Text(' Calculating...'),
],
if (context.mounted) {
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();
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: 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(' Averages are now up to date.')
],
),
),
);
}
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.')
],
),
),
);
}

111
lib/actions/auto_tagging.dart

@ -10,17 +10,19 @@ Future<void> 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<Activity> activities;
activities = await athlete.activities;
@ -28,61 +30,74 @@ Future<void> 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.'),
],
if (context.mounted) {
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();
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: 2),
duration: const Duration(seconds: 5),
content: Row(
children: [
CircularProgressIndicator(value: percent / 100, color: MyColor.progress),
Text(' $percent% done (autotagging »${activity.name}« )'),
MyIcon.finishedWhite,
const Text(' Autotaggings are now up to date.'),
],
),
),
);
}
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.'),
],
),
),
);
} 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!'),
],
),
),
),
);
);
}
}
}

24
lib/actions/download_activity.dart

@ -21,16 +21,18 @@ Future<void> 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'),
],
),
),
),
);
);
}
}

83
lib/actions/download_demo_data.dart

@ -24,17 +24,19 @@ Future<void> 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<void> 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!'),
),
);
}
}
}

59
lib/actions/import_activities_locally.dart

@ -23,17 +23,19 @@ Future<void> 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<Activity> downloadedActivities = activities
@ -44,23 +46,28 @@ Future<void> 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!'),
],
),
),
),
);
);
}
}

14
lib/actions/parse_activity.dart

@ -60,12 +60,14 @@ Future<void> 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')),
);
}
}
}

24
lib/actions/query_strava.dart

@ -19,16 +19,18 @@ Future<void> 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'),
],
),
),
),
);
);
}
}

15
lib/actions/setup_demo_athlete.dart

@ -25,10 +25,13 @@ Future<void> 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();
}
}

83
lib/actions/update_job.dart

@ -13,20 +13,24 @@ Future<void> updateJob({
List<Activity> 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<Activity> 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<Activity> downloadedActivities = activities.where(
@ -36,37 +40,44 @@ Future<void> 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!'),
],
),
),
),
);
);
}
}
}

44
lib/screens/add_heart_rate_zone_schema_screen.dart

@ -189,7 +189,9 @@ class AddHeartRateZoneSchemaScreenState
Future<void> saveHeartRateZoneSchema(BuildContext context) async {
await widget.heartRateZoneSchema.save();
await HeartRateZone.upsertAll(heartRateZones);
Navigator.of(context).pop();
if (context.mounted) {
Navigator.of(context).pop();
}
}
Future<void> getData() async {
@ -200,7 +202,9 @@ class AddHeartRateZoneSchemaScreenState
Future<void> 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<BuildContext>(
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: <Widget>[
ElevatedButton(
style: MyButtonStyle.raisedButtonStyle(color: MyColor.primary),
child: const Text('OK'),
onPressed: () => Navigator.of(context).pop(),
),
],
),
);
if (context.mounted) {
showDialog<BuildContext>(
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: <Widget>[
ElevatedButton(
style: MyButtonStyle.raisedButtonStyle(
color: MyColor.primary),
child: const Text('OK'),
onPressed: () => Navigator.of(context).pop(),
),
],
),
);
}
}
}

8
lib/screens/add_heart_rate_zone_screen.dart

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

45
lib/screens/add_power_zone_schema_screen.dart

@ -182,7 +182,9 @@ class AddPowerZoneSchemaScreenState extends State<AddPowerZoneSchemaScreen> {
Future<void> savePowerZoneSchema(BuildContext context) async {
await widget.powerZoneSchema.save();
await PowerZone.upsertAll(powerZones);
Navigator.of(context).pop();
if (context.mounted) {
Navigator.of(context).pop();
}
}
Future<void> getData() async {
@ -193,7 +195,9 @@ class AddPowerZoneSchemaScreenState extends State<AddPowerZoneSchemaScreen> {
Future<void> deletePowerZoneSchema(
{required PowerZoneSchema powerZoneSchema}) async {
await powerZoneSchema.delete();
Navigator.of(context).pop();
if (context.mounted) {
Navigator.of(context).pop();
}
}
Future<void>? updatePowerZoneBase({int? base}) {
@ -221,21 +225,26 @@ class AddPowerZoneSchemaScreenState extends State<AddPowerZoneSchemaScreen> {
}
await PowerZone.upsertAll(powerZones);
await getData();
showDialog<BuildContext>(
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: <Widget>[
ElevatedButton(
style: MyButtonStyle.raisedButtonStyle(color: MyColor.primary),
child: const Text('OK'),
onPressed: () => Navigator.of(context).pop(),
),
],
),
);
if (context.mounted) {
showDialog<BuildContext>(
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: <Widget>[
ElevatedButton(
style: MyButtonStyle.raisedButtonStyle(
color: MyColor.primary),
child: const Text('OK'),
onPressed: () => Navigator.of(context).pop(),
),
],
),
);
}
}
}

8
lib/screens/add_power_zone_screen.dart

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

8
lib/screens/add_tag_group_screen.dart

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

8
lib/screens/add_tag_screen.dart

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

8
lib/screens/add_weight_screen.dart

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

32
lib/screens/dashboard.dart

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

22
lib/screens/edit_event_screen.dart

@ -74,13 +74,17 @@ class EditEventScreenState extends State<EditEventScreen> {
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<EditEventScreen> {
child: MyButton.save(
onPressed: () async {
await widget.record!.save();
Navigator.of(context).pop();
if (context.mounted) {
Navigator.of(context).pop();
}
},
),
),

14
lib/screens/onboarding_screens/onboarding_body_weight_screen.dart

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

34
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<BuildContext>(
builder: (BuildContext _) =>
const OnboardingFinishedScreen(),
),
);
if (context.mounted) {
await Navigator.pushReplacement(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext _) =>
const OnboardingFinishedScreen(),
),
);
}
},
)
],
@ -95,14 +97,16 @@ class OnboardingCreateUserScreenState
StravaGetUser(athlete: athlete),
),
);
Navigator.pushReplacement(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext _) =>
OnBoardingStravaCredentialsScreen(
athlete: athlete),
),
);
if (context.mounted) {
Navigator.pushReplacement(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext _) =>
OnBoardingStravaCredentialsScreen(
athlete: athlete),
),
);
}
},
)
],

17
lib/screens/onboarding_screens/onboarding_heart_rate_zone_schema_screen.dart

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

17
lib/screens/onboarding_screens/onboarding_power_zone_schema_screen.dart

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

66
lib/screens/show_activity_screen.dart

@ -474,18 +474,20 @@ class ShowActivityScreenState extends State<ShowActivityScreen> {
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<ShowActivityScreen> {
Future<void> delete() async {
await widget.activity.delete();
Navigator.of(context).pop();
if (context.mounted) {
Navigator.of(context).pop();
}
}
Future<void> download() async {
@ -521,26 +525,30 @@ class ShowActivityScreenState extends State<ShowActivityScreen> {
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<void> parse() async {

15
lib/screens/show_athlete_screen.dart

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

7
lib/screens/show_interval_screen.dart

@ -177,7 +177,9 @@ class ShowIntervalScreen extends StatelessWidget {
onPressed: () async {
await interval.delete();
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(
style: MyButtonStyle.raisedButtonStyle(
color: color,
textColor: MyColor.textColor(backgroundColor: color)),
color: color, textColor: MyColor.textColor(backgroundColor: color)),
icon: icon,
label: Expanded(
child: Text(title),

4
lib/screens/strava_get_user.dart

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

22
lib/widgets/activities_list_widget.dart

@ -113,17 +113,19 @@ class ActivitiesListWidgetState extends State<ActivitiesListWidget> {
);
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(() {});
}

22
lib/widgets/activity_widgets/edit_activity_widget.dart

@ -60,13 +60,17 @@ class EditActivityWidgetState extends State<EditActivityWidget> {
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<EditActivityWidget> {