iosPlatformView method
Widget
iosPlatformView(
- String viewType,
- ValueNotifier<
bool> isDetachedValueNotifier, - ValueNotifier<
bool> isLoadingValueNotifier, - Widget? faceMaskOverlay,
- Widget? onLoadingWidget,
- Map<
String, dynamic> creationParams,
Implementation
Widget iosPlatformView(
String viewType,
ValueNotifier<bool> isDetachedValueNotifier,
ValueNotifier<bool> isLoadingValueNotifier,
Widget? faceMaskOverlay,
Widget? onLoadingWidget,
Map<String, dynamic> creationParams,
) {
return ValueListenableBuilder<bool>(
valueListenable: isDetachedValueNotifier,
builder: (context, isDetached, _) {
return ValueListenableBuilder<bool>(
valueListenable: isLoadingValueNotifier,
builder: (context, isLoading, child) {
return Stack(
children: <Widget>[
if (!isDetached) // Only build UiKitView if not detached
UiKitView(
viewType: viewType,
layoutDirection: TextDirection.ltr,
creationParams: creationParams,
creationParamsCodec: const StandardMessageCodec(),
gestureRecognizers: const <Factory<
OneSequenceGestureRecognizer>>{},
onPlatformViewCreated: (int id) {
// Ensure the listener is only added once or managed appropriately
// if this widget can be rebuilt.
// A simple way for this example:
void listener() {
if (isDetachedValueNotifier.value) {
methodChannel.invokeMethod('detach');
// TODO: removing the listener if it's a one-time event
// or if the view controller for this id will be disposed.
// isDetachedValueNotifier.removeListener(listener);
}
}
// Remove any existing listener before adding a new one if the widget can rebuild
// This is a simplistic approach; a more robust solution might involve
// managing the listener lifecycle more carefully, e.g., in a StatefulWidget's dispose method.
isDetachedValueNotifier.removeListener(
() {}); // Placeholder for actual removal if needed
isDetachedValueNotifier.addListener(listener);
},
)
else
const SizedBox.shrink(),
faceMaskOverlay ?? const SizedBox.shrink(),
if (isLoading || isDetached)
onLoadingWidget ??
const Center(
child: CircularProgressIndicator(),
)
else
const SizedBox.shrink(),
],
);
},
);
},
);
}