Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to navigate between flutter screen to native(android/ios) screens

Tags:

flutter

Iam new to flutter,tried hello_services example provided by flutter.io . in that example both flutter view and native view are in same screen. My question is, how to navigate to two different screens like one written in flutter and another in native(android/ios) with params or extras.Please help !!!! thanks

like image 393
Ashrith K S Avatar asked Jan 01 '26 00:01

Ashrith K S


1 Answers

The only solution I found, it is to send a message to your native view (https://flutter.io/platform-services/), catch the message in Java or Swift/ObjectiveC code then navigate to the other view.

Dart Code

Map params = <String, dynamic>{
  "view": "MyView"
};

PlatformMessages.sendJson("navigateTo", params);

Java Code

flutterView.addOnMessageListener("navigateTo", new FlutterView.OnMessageListener() {
                @Override
                public String onMessage(FlutterView view, String message) {
                  try {
                     JSONObject object = new JSONObject(message);
                     if (object.getString("view") == "MyView") {
                       // navigate to MyView
                     }
                  } catch (JSONException e) {
                     e.printStackTrace();
                  }
                    return null;
                }
            });
like image 105
Hadrien Lejard Avatar answered Jan 09 '26 05:01

Hadrien Lejard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!