use PlatformViewLink widget for Android WebView
This commit is contained in:
parent
56e0f30928
commit
21f4838f41
|
@ -85,5 +85,11 @@
|
||||||
android:resource="@xml/provider_paths"/>
|
android:resource="@xml/provider_paths"/>
|
||||||
</provider>
|
</provider>
|
||||||
|
|
||||||
|
<!-- Hybrid composition -->
|
||||||
|
<meta-data
|
||||||
|
android:name="io.flutter.embedded_views_preview"
|
||||||
|
android:value="true" />
|
||||||
|
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
|
@ -339,41 +340,37 @@ class _InAppWebViewState extends State<InAppWebView> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (defaultTargetPlatform == TargetPlatform.android) {
|
if (defaultTargetPlatform == TargetPlatform.android) {
|
||||||
return AndroidView(
|
return PlatformViewLink(
|
||||||
viewType: 'com.pichillilorenzo/flutter_inappwebview',
|
viewType: 'com.pichillilorenzo/flutter_inappwebview',
|
||||||
onPlatformViewCreated: _onPlatformViewCreated,
|
surfaceFactory: (
|
||||||
gestureRecognizers: widget.gestureRecognizers,
|
BuildContext context,
|
||||||
layoutDirection: TextDirection.rtl,
|
PlatformViewController controller,
|
||||||
creationParams: <String, dynamic>{
|
) {
|
||||||
'initialUrl': '${Uri.parse(widget.initialUrl)}',
|
return AndroidViewSurface(
|
||||||
'initialFile': widget.initialFile,
|
controller: controller,
|
||||||
'initialData': widget.initialData?.toMap(),
|
gestureRecognizers: widget.gestureRecognizers ?? const <Factory<OneSequenceGestureRecognizer>>{},
|
||||||
'initialHeaders': widget.initialHeaders,
|
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
|
||||||
'initialOptions': widget.initialOptions?.toMap() ?? {},
|
);
|
||||||
'contextMenu': widget.contextMenu?.toMap() ?? {},
|
},
|
||||||
'windowId': widget.windowId
|
onCreatePlatformView: (PlatformViewCreationParams params) {
|
||||||
|
return PlatformViewsService.initSurfaceAndroidView(
|
||||||
|
id: params.id,
|
||||||
|
viewType: 'com.pichillilorenzo/flutter_inappwebview',
|
||||||
|
layoutDirection: TextDirection.rtl,
|
||||||
|
creationParams: <String, dynamic>{
|
||||||
|
'initialUrl': '${Uri.parse(widget.initialUrl)}',
|
||||||
|
'initialFile': widget.initialFile,
|
||||||
|
'initialData': widget.initialData?.toMap(),
|
||||||
|
'initialHeaders': widget.initialHeaders,
|
||||||
|
'initialOptions': widget.initialOptions?.toMap() ?? {}
|
||||||
|
},
|
||||||
|
creationParamsCodec: const StandardMessageCodec(),
|
||||||
|
)
|
||||||
|
..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
|
||||||
|
..addOnPlatformViewCreatedListener((id) => _onPlatformViewCreated(id))
|
||||||
|
..create();
|
||||||
},
|
},
|
||||||
creationParamsCodec: const StandardMessageCodec(),
|
|
||||||
);
|
);
|
||||||
// onLongPress issue: https://github.com/flutter/plugins/blob/f31d16a6ca0c4bd6849cff925a00b6823973696b/packages/webview_flutter/lib/src/webview_android.dart#L31
|
|
||||||
/*return GestureDetector(
|
|
||||||
onLongPress: () {},
|
|
||||||
excludeFromSemantics: true,
|
|
||||||
child: AndroidView(
|
|
||||||
viewType: 'com.pichillilorenzo/flutter_inappwebview',
|
|
||||||
onPlatformViewCreated: _onPlatformViewCreated,
|
|
||||||
gestureRecognizers: widget.gestureRecognizers,
|
|
||||||
layoutDirection: TextDirection.rtl,
|
|
||||||
creationParams: <String, dynamic>{
|
|
||||||
'initialUrl': '${Uri.parse(widget.initialUrl)}',
|
|
||||||
'initialFile': widget.initialFile,
|
|
||||||
'initialData': widget.initialData?.toMap(),
|
|
||||||
'initialHeaders': widget.initialHeaders,
|
|
||||||
'initialOptions': initialOptions
|
|
||||||
},
|
|
||||||
creationParamsCodec: const StandardMessageCodec(),
|
|
||||||
),
|
|
||||||
);*/
|
|
||||||
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
|
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
|
||||||
return UiKitView(
|
return UiKitView(
|
||||||
viewType: 'com.pichillilorenzo/flutter_inappwebview',
|
viewType: 'com.pichillilorenzo/flutter_inappwebview',
|
||||||
|
|
Loading…
Reference in New Issue