Untitled
unknown
plain_text
3 years ago
1.2 kB
6
Indexable
class MyWidget extends StatefulWidget {
@override
_MyWidgetState createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> with WidgetsBindingObserver {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
void onUiKitViewCreated(int id) {
// Execute your function here
print('UiKitView is ready with ID: $id');
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
// After the app is resumed, use MethodChannel to get the UiKitView controller and call the function.
final MethodChannel methodChannel = MethodChannel('myMethodChannel');
methodChannel.invokeMethod<void>('getUiKitViewController').then((result) {
onUiKitViewCreated(result);
});
}
}
@override
Widget build(BuildContext context) {
return UiKitView(
viewType: 'myUiKitViewType',
onPlatformViewCreated: (int id) {
// Save the view id to call the function later.
_controller = id;
},
);
}
}Editor is loading...