skip to Main Content
@override
Widget build(BuildContext context) {
  return WillPopScope(
    onWillPop: () async {
      await _stop(); // Stop the speech when the back button is pressed
      return true;
    },
        child: Scaffold (...),
    );
  }

The flutter code block of mine (above) shows the warning though it’s working but I want to migrate to the recommended approach. Please help me to solve this issue as I can not migrate to the recommended approach. I am having trouble with that. Android Studio message is shown below:

enter image description here

I’ve tried but found errors.

2

Answers


  1. Chosen as BEST ANSWER

    My solution that worked perfectly:

    enter image description here


  2. Use popscope Widget Or For back_button_interceptor 7.0.3 package From pub dev

    PopScope(
      canPop: canPop,// Make it  false to Work
      onPopInvoked: (bool value) {
        setState(() {
          canPop= !value; //Logic and manage State
        });
    
        if (canPop) {
          ScaffoldMessenger.of(context).showSnackBar(
            const SnackBar(
              content: Text("Click once more to go back"),
              duration: Duration(milliseconds: 1500),
            ),
          );
        }
      },
    

    This is Example You can add Business Logic in Pop scope
    Flutter Package For Changing Defult behaviour of back Button
    For use This package Remember
    To make it work on Android 13 and up, set this to false in the Android manifest:
    android:enableOnBackInvokedCallback="false"

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search