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
# 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

View File

@ -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...'),
],
),
),
);
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.')
],
),
),
),
);
);
}
}

View File

@ -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.'),
],
),
),
);
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!'),
],
),
),
),
);
);
}
}
}

View File

@ -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'),
],
),
),
),
);
);
}
}

View File

@ -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!'),
),
);
}
}
}

View File

@ -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!'),
],
),
),
),
);
);
}
}

View File

@ -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')),
);
}
}
}

View File

@ -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'),
],
),
),
),
);
);
}
}

View File

@ -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();
}
}

View File

@ -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!'),
],
),
),
),
);
);
}
}
}

View File

@ -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(),
),
],
),
);
}
}
}

View File

@ -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();
}
}
}

View File

@ -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(),
),
],
),
);
}
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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;

View File

@ -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();
}
},
),
),

View File

@ -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(),
),
);
}
}
}

View File

@ -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),
),
);
}
},
)
],

View File

@ -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,
),
),
),
);
);
}
}
}

View File

@ -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,
),
),
),
);
);
}
}
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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),

View File

@ -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();
}
}
}
}

View File

@ -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(() {});
}

View File

@ -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> {
child: MyButton.save(
onPressed: () async {
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 =
await widget.athlete!.powerZoneSchemas;
if (powerZoneSchemas.isEmpty) {
Navigator.pushReplacement(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext _) =>
OnBoardingPowerZoneSchemaScreen(athlete: widget.athlete),
),
);
if (context.mounted) {
Navigator.pushReplacement(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext _) =>
OnBoardingPowerZoneSchemaScreen(athlete: widget.athlete),
),
);
}
} 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 {
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<PowerZoneSchema> 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<EditStravaAthleteWidget> {
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!'),
],
),
),
),
);
);
}
}
}
}