Skip to content

Commit

Permalink
Fix using context across asynchronous gaps.
Browse files Browse the repository at this point in the history
amugofjava committed Jan 1, 2025
1 parent b1036cd commit 4773366
Showing 4 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/ui/anytime_podcast_app.dart
Original file line number Diff line number Diff line change
@@ -615,7 +615,11 @@ class _AnytimeHomePageState extends State<AnytimeHomePage> with WidgetsBindingOb
MaterialPageRoute<void>(
settings: const RouteSettings(name: 'podcastdetails'),
builder: (context) => PodcastDetails(Podcast.fromUrl(url: url), podcastBloc)),
).then((value) => Navigator.pop(context));
).then((value) {
if (mounted) {
Navigator.of(context).pop();
}
});
},
),
],
4 changes: 3 additions & 1 deletion lib/ui/podcast/funding_menu.dart
Original file line number Diff line number Diff line change
@@ -134,7 +134,9 @@ class _CupertinoFundingMenu extends StatelessWidget {
context,
).then((value) {
settingsBloc.setExternalLinkConsent(value);
Navigator.pop(context, 'Cancel');
if (context.mounted) {
Navigator.of(context).pop('Cancel');
}
});
},
child: Text(funding![index].value),
4 changes: 3 additions & 1 deletion lib/ui/podcast/now_playing.dart
Original file line number Diff line number Diff line change
@@ -65,8 +65,10 @@ class _NowPlayingState extends State<NowPlaying> with WidgetsBindingObserver {
audioBloc.playingState!.where((state) => state == AudioState.stopped).listen((playingState) async {
// Prevent responding to multiple stop events after we've popped and lost context.
if (!popped) {
Navigator.pop(context);
popped = true;
if (mounted) {
Navigator.of(context).pop();
}
}
});
}
4 changes: 3 additions & 1 deletion lib/ui/podcast/playback_error_listener.dart
Original file line number Diff line number Diff line change
@@ -39,7 +39,9 @@ class _PlaybackErrorListenerState extends State<PlaybackErrorListener> {
final audioBloc = Provider.of<AudioBloc>(context, listen: false);

errorSubscription = audioBloc.playbackError!.listen((code) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(_codeToMessage(context, code))));
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(_codeToMessage(context, code))));
}
});
}

0 comments on commit 4773366

Please sign in to comment.