initialize method
Initializes the underlying platform view.
Implementation
Future<void> initialize() async {
if (_isDisposed) {
return Future<void>.value();
}
_creatingCompleter = Completer<void>();
try {
final reply =
await _pluginChannel.invokeMapMethod<String, dynamic>('initialize');
_textureId = reply!['textureId'];
_methodChannel = MethodChannel('$_pluginChannelPrefix/$_textureId');
_eventChannel = EventChannel('$_pluginChannelPrefix/$_textureId/events');
_eventStreamSubscription =
_eventChannel.receiveBroadcastStream().listen((event) {
final map = event as Map<dynamic, dynamic>;
switch (map['type']) {
case 'urlChanged':
_urlStreamController.add(map['value']);
break;
case 'onLoadError':
final value = WebErrorStatus.values[map['value']];
_onLoadErrorStreamController.add(value);
break;
case 'loadingStateChanged':
final value = LoadingState.values[map['value']];
_loadingStateStreamController.add(value);
break;
case 'historyChanged':
final value = HistoryChanged(
map['value']['canGoBack'], map['value']['canGoForward']);
_historyChangedStreamController.add(value);
break;
case 'securityStateChanged':
_securityStateChangedStreamController.add(map['value']);
break;
case 'titleChanged':
_titleStreamController.add(map['value']);
break;
case 'cursorChanged':
_cursorStreamController.add(getCursorByName(map['value']));
break;
case 'webMessageReceived':
try {
final message = json.decode(map['value']);
_webMessageStreamController.add(message);
} catch (ex) {
_webMessageStreamController.addError(ex);
}
break;
case 'containsFullScreenElementChanged':
_containsFullScreenElementChangedStreamController.add(map['value']);
break;
}
});
_methodChannel.setMethodCallHandler((call) {
if (call.method == 'permissionRequested') {
return _onPermissionRequested(
call.arguments as Map<dynamic, dynamic>);
}
throw MissingPluginException('Unknown method ${call.method}');
});
value = value.copyWith(isInitialized: true);
_creatingCompleter.complete();
} on PlatformException catch (e) {
_creatingCompleter.completeError(e);
}
return _creatingCompleter.future;
}