So far I couldn't find any way to implement directly implement, in a straight forward manner, android components inside a flutter app. However is possible the opposite things, that is using a Flutter fragment inside an android application. So I can propose you a workaround for this problem that may lead to the same result:
- use a method channel to start a new android activity:
void startAndroidActivity() async {
//TODO: fix result type, etc.
dynamic result = await MethodChannel("CHANNEL_X").invokeMethod('METHOD');
}
public class MainActivity extends FlutterActivity {
private MethodChannel.Result result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new MethodChannel(getFlutterView(), "CHANNEL_X").setMethodCallHandler((call, result) -> {
if (call.method.equals("METHOD")) {
Intent intent = new Intent(this, MyActivity.class);
this.result = result;
startActivityForResult(intent, data);
}
});
GeneratedPluginRegistrant.registerWith(this);
}
//TODO: Handle result
}
- Implement your android components and import the flutter fragment. For this topic, I leave you this reference: https://flutter.dev/docs/development/add-to-app/android/add-flutter-fragment
Another reference I can give you is this one, that maybe can allow you to import what you want in Flutter, but it requires a bit more time: https://medium.com/@KarthikPonnam/build-your-own-plugin-using-platformviews-flutter-5b42b4c4fb0a