I have managed to implement a native Android Activity on Flutter. The code looks like this:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class Communication extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return MyCommunication();
}
}
class MyCommunication extends State<Communication> {
static const platform = const MethodChannel("test_activity");
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: FutureBuilder<Widget>(
future: getNewActivity(),
builder: (BuildContext context, AsyncSnapshot<Widget> snapshot) {
if (snapshot.hasData)
return snapshot.data;
else
return Container(child: CircularProgressIndicator());
}),
));
}
Future<Widget> getNewActivity() async {
try {
return await platform.invokeMethod('startNewActivity');
} on PlatformException catch (e) {
print(e.message);
}
}
}
The problem is, when I tap the back button from the native activity to go to the screen that presented it, the app displays the Container with a circular progress indicator returned when snapshot.hasData is false.
I have to tap again on Back to dismiss this screen and get to the intended presenting view. Obviously there is something I am not doing right in the code. How could I fix this?