Fluro is a Flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.
3.66k
stars
416
forks
source link
PopScope or WillPopScope never trigger in Flutter Web #286
Open
pitcairn1987 opened 2 months ago
PopScope or WillPopScope never trigger in Flutter Web.
**1. Going To Second Page.
` 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); }
} `