youtube-course-bloc
youtube-course-bloc copied to clipboard
"Do not use BuildContexts across async gaps" in views/main_popup_menu_button.dart
It seems that recently flutter lint has been updated with a new linting rule that warns the developer to not use the context in async functions after an await has been performed: Use Build Context Synchronously.

In step-8
we are using it in the views/main_popup_menu_button.dart
when showing the logout and delete account dialogs for dispatching the action to the bloc:
- https://github.com/vandadnp/youtube-course-bloc/blob/main/lib/views/main_popup_menu_button.dart#L21
- https://github.com/vandadnp/youtube-course-bloc/blob/main/lib/views/main_popup_menu_button.dart#L29
Some solutions are suggesting to check whether or not the component is mounted before dispatching the event, but I was wondering if there is another solution with still using the StatelessWidget
, without the need of converting it into a StatefulWidget
.
yeah, please write this line before using context in the async method:
if(!mounted) return; context.read<...>(...);