Android native open flutter screen

Viewed 1144

How can I open a flutter screen from Android-Native-Screen?

I Was open an Android-Native-Screen from existing our Flutter project.

So, on Android-Native-Screen, we need open Flutter-Screen.

That means our work-flow: FLutter -> Native-Android-Activity -> Flutter Screen.

1 Answers

Flutter provides FlutterActivity to display a Flutter experience within an Android app. Like any other Activity

You can go through this Documentation https://flutter.dev/docs/development/add-to-app/android/add-flutter-screen

Step 1: Add FlutterActivity to AndroidManifest.xml

<activity
  android:name="io.flutter.embedding.android.FlutterActivity"
  android:theme="@style/LaunchTheme"
  android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
  android:hardwareAccelerated="true"
  android:windowSoftInputMode="adjustResize"
  />

Step 2: Launch FlutterActivity

myButton.setOnClickListener(new OnClickListener() {
  @Override
  public void onClick(View v) {
    startActivity(
      FlutterActivity.createDefaultIntent(currentActivity)
    );
  }
});

The following example demonstrates how to launch a FlutterActivity that initially renders a custom route in Flutter.

   myButton.addOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        startActivity(
          FlutterActivity
            .withNewEngine()
            .initialRoute("/my_route")
            .build(currentActivity)
          );
      }
    });
Related