Back button not working properly...
widget code:
onWillPop: () async {
print(await context
.watch<ShowOverlayLoaderProvider>()
.shouldShowOverlayLoader);
if (context
.watch<ShowOverlayLoaderProvider>()
.shouldShowOverlayLoader ==
false) {
return Future.value(false);
} else {
Navigator.pop(context);
return Future.value(true);
}
},
Provider:
class ShowOverlayLoaderProvider extends ChangeNotifier {
var _shouldShowOverlayLoader = false;
get shouldShowOverlayLoader {
return _shouldShowOverlayLoader;
}
changeShowOverlayState(s) {
_shouldShowOverlayLoader = s;
notifyListeners();
}
}
Not getting any print response also if I try to print the value of shouldShowOverlayLoader
upon clicking the back button.
Fixed onWillPop method:
onWillPop: (context.watch().shouldShowOverlayLoader == false)? () { Navigator.pop(context); return Future.value(true); }: () { return Future.value(false); },
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.