buildSmileIDPlatformView function

Widget buildSmileIDPlatformView({
  1. required BuildContext context,
  2. required String viewType,
  3. required Map<String, dynamic> creationParams,
  4. required void onSuccess(
    1. String result
    ),
  5. required void onError(
    1. String error
    ),
})

Implementation

Widget buildSmileIDPlatformView({
  required BuildContext context,
  required String viewType,
  required Map<String, dynamic> creationParams,
  required void Function(String result) onSuccess,
  required void Function(String error) onError,
}) {
  void onPlatformViewCreated(int id) {
    final channel = MethodChannel("${viewType}_$id");
    channel.setMethodCallHandler((call) async {
      switch (call.method) {
        case "onSuccess":
          onSuccess(call.arguments);
          break;
        case "onError":
          onError(call.arguments);
          break;
        default:
          throw MissingPluginException('Unknown method ${call.method}');
      }
    });
  }

  switch (defaultTargetPlatform) {
    case TargetPlatform.android:
      return SafeArea(
        child: PlatformViewLink(
          viewType: viewType,
          surfaceFactory: (context, controller) {
            return AndroidViewSurface(
              controller: controller as AndroidViewController,
              hitTestBehavior: PlatformViewHitTestBehavior.opaque,
              gestureRecognizers: const {
                Factory<OneSequenceGestureRecognizer>(
                    EagerGestureRecognizer.new)
              },
            );
          },
          onCreatePlatformView: (params) {
            return PlatformViewsService.initExpensiveAndroidView(
              id: params.id,
              viewType: viewType,
              layoutDirection: Directionality.of(context),
              creationParams: creationParams,
              creationParamsCodec: const StandardMessageCodec(),
              onFocus: () {
                params.onFocusChanged(true);
              },
            )
              ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
              ..addOnPlatformViewCreatedListener(onPlatformViewCreated)
              ..create();
          },
        ),
      );
    case TargetPlatform.iOS:
      return UiKitView(
        viewType: viewType,
        creationParams: creationParams,
        creationParamsCodec: const StandardMessageCodec(),
        onPlatformViewCreated: onPlatformViewCreated,
      );
    default:
      throw UnsupportedError("Unsupported platform");
  }
}