flutter_cupertino_will_pop_scope
flutter_cupertino_will_pop_scope copied to clipboard
_onWillPop() callback always gets vetoed
I believe I found an odd behaviour when the _onWillPop() callback always vetoes an attempt to pop the screen no matter if it returns true or false;
Future<bool> _onWillPop() async {
return true;
}
It is the same code provided with the package example (minus the styling and decoration to keep the question concise).
@override
Widget build(BuildContext context) {
return ConditionalWillPopScope(
onWillPop: _onWillPop,
shouldAddCallback: _hasChanges,
child: Scaffold(
appBar: AppBar(title: Text('Second Screen')),
body: Center(
child: Container(
child: SwitchListTile(
onChanged: _updateChanges,
title: Text('Disable back navigation'),
value: _hasChanges,
),
),
),
),
);
}
I've double-checked that the custom transition builder is also set correctly, as per:
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme:
primarySwatch: Colors.blue,
pageTransitionsTheme: PageTransitionsTheme(builders: {
TargetPlatform.iOS: CupertinoWillPopScopePageTransionsBuilder()
})),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
The issue is reproducible in a brand-new project to make sure it doesn't conflict with any other packages. Also relates to this issue which seems to be stale.
Any idea what might be wrong?
Same here. The _onWillPop is always called - even with the iOs back swipe. But the screen is only popping when the default BackButton of the AppBar is used. When using the back swipe, pop is always canceled (despite _onWillPop returning true).