Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PopScope or WillPopScope never trigger in Flutter Web #286

Open
pitcairn1987 opened this issue Apr 12, 2024 · 0 comments
Open

PopScope or WillPopScope never trigger in Flutter Web #286

pitcairn1987 opened this issue Apr 12, 2024 · 0 comments

Comments

@pitcairn1987
Copy link

pitcairn1987 commented Apr 12, 2024

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);
}

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant