when snackbar is being displayed on screen and at the same time if back button is pressed, it throws error in console in flutter / dart
I have removed snackbar by using
return WillPopScope(
onWillPop: () async {
ScaffoldMessenger.of(context).removeCurrentSnackBar();
return true;
},
child: Scaffold(...
but it is also not working.
error log is as:
E/flutter (13058): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: Looking up a deactivated widget's ancestor is unsafe.
E/flutter (13058): At this point the state of the widget's element tree is no longer stable.
E/flutter (13058): To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.
How can I fix this issue?