WillPopScope deprecation warning

65 Views Asked by At

i'm not a Flutter expert :( How can i convert this my widget to avoid WillPopScope?

@override
Widget build(BuildContext context) {
  return WillPopScope(
    onWillPop: () async {
      if (!Navigator.of(context).canPop()) {
        Navigator.of(context).pushReplacementNamed(Routes.welcome);
      } else {
        Navigator.of(context).pop();
      }
      return false;
    },
    child: Scaffold(
      resizeToAvoidBottomInset: false,
      primary: true,
      appBar: _buildAppBar(),
      body: BaseWidget(child: _buildBody()),
    ),
  );
}

I've found one similar question here but i can't do changes myself :(

1

There are 1 best solutions below

0
K.D.Dilshan On

WillpopScope is deprecared after v3.12.0-1.0.pre. you can find more details thought this link.

So, PopScope calss we can use directly instance of WillPopScope, so you can find more details by using this link.

1.How to prevent go to back when click defult back button on mobile devices,

return Scaffold(
      body: PopScope(
        canPop: true,
        onPopInvoked: (didPop) {
          Navigator.pop(context);
        },
        ),
  );

when I was making a game I want prevent goin to back when click the default back button, I fix it as above example.your's requirements are will be different but logic is same,

Find this answer by this link you can get more idea