-
Notifications
You must be signed in to change notification settings - Fork 415
Description
PopScope or WillPopScope never trigger in Flutter Web.
1. Going To Second Page.
2. Click back button in browser.
`
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@OverRide
State createState() => _MyAppState();
}
class _MyAppState extends State {
@OverRide
void initState() {
super.initState();
Routes.defineRoutes();
}
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
initialRoute: '/',
onGenerateRoute: Routes.router.generator,
);
}
}
class SecondPage extends StatelessWidget {
Widget build(BuildContext context) {
return PopScope(
canPop: false,
onPopInvoked: (bool didPop) {
if (didPop) {
return;
}
},
child: Scaffold(
backgroundColor: Colors.red,
body: Container(),
),
);
}
}
class HomePage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blue,
body: Container(
child: ElevatedButton(
child: const Text("Button 1"),
onPressed: () => Navigator.pushNamed(context, 'second'),
),
),
);
}
}
class Routes {
static final router = FluroRouter();
static var firstScreen = Handler(
handlerFunc: (BuildContext ? context, Map<String, dynamic> params) {
return HomePage();
});
static var secondScreen = Handler(
handlerFunc: (BuildContext ? context, Map<String, dynamic> params) {
return SecondPage();
});
static dynamic defineRoutes() {
router.define("/", handler: firstScreen,transitionType: TransitionType.fadeIn);
router.define("second", handler: secondScreen,transitionType: TransitionType.inFromLeft);
}
}
`