vendredi 17 juillet 2020

navigate between screens based on if condition result in flutter

i have created a button to initiate a method after pressing this button , and this method applying if condition and i need to go to specific screen based on the result of this if statement but every time nothing happens , i don't even get an error!

1- the button:

RaisedButton(
                  child: Text('check'),
                  onPressed: _mobilestate,
                )

2 the method :

  _mobilestate() async {
    var connectivityResult = await (Connectivity().checkConnectivity());
    if (connectivityResult == ConnectivityResult.mobile) {
      return MaterialPageRoute(
        builder: (BuildContext context) => XDdetectingproblems19(),
      );



    } else if (connectivityResult == ConnectivityResult.none) {
      return MaterialPageRoute(
        builder: (BuildContext context) => XDdetectingproblems14(),
      );
    }
  }

i added the routes in main. dart as below :

  routes: {
        '/XDdetectingproblems19' :(context) => XDdetectingproblems19(),
        '/XDdetectingproblems14' :(context) => XDdetectingproblems14(),

      },

Please advise , noting that the button and the method working fine , but the issue is with the navigation step.

Aucun commentaire:

Enregistrer un commentaire