Upgrade webview

This commit is contained in:
cghislai 2021-11-28 15:44:08 +01:00
parent 027eb0b7d1
commit d157673aac
4 changed files with 62 additions and 49 deletions

View File

@ -1,5 +1,5 @@
import 'package:embedded_webview/webview_widget.dart';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
void main() {
const title = String.fromEnvironment("APP_TITLE");
@ -18,16 +18,8 @@ class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
MaterialColor materialColor = this._getMaterialColor(this._color);
return MaterialApp(
title: this._title,
theme: ThemeData(primarySwatch: materialColor),
home: WebView(
initialUrl: this._uri,
javascriptMode: JavascriptMode.unrestricted,
zoomEnabled: true,
allowsInlineMediaPlayback: true,
));
MaterialColor materialColor = _getMaterialColor(_color);
return MaterialApp(title: _title, theme: ThemeData(primarySwatch: materialColor), home: WebViewWidget(_uri));
}
MaterialColor _getMaterialColor(String colorString) {

47
lib/webview_widget.dart Normal file
View File

@ -0,0 +1,47 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_webview_pro/webview_flutter.dart';
class WebViewWidget extends StatefulWidget {
final String _initialUrl;
const WebViewWidget(this._initialUrl, {Key? key}) : super(key: key);
@override
WebViewWidgetState createState() => WebViewWidgetState();
}
class WebViewWidgetState extends State<WebViewWidget> {
WebViewWidgetState();
@override
void initState() {
super.initState();
// Enable hybrid composition.
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
}
@override
Widget build(BuildContext context) {
return WebView(
initialUrl: widget._initialUrl,
javascriptMode: JavascriptMode.unrestricted,
javascriptChannels: <JavascriptChannel>{
_toasterJavascriptChannel(context),
},
gestureNavigationEnabled: true,
);
}
JavascriptChannel _toasterJavascriptChannel(BuildContext context) {
return JavascriptChannel(
name: 'Toaster',
onMessageReceived: (JavascriptMessage message) {
// ignore: deprecated_member_use
Scaffold.of(context).showSnackBar(
SnackBar(content: Text(message.message)),
);
});
}
}

View File

@ -74,6 +74,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_webview_pro:
dependency: "direct main"
description:
name: flutter_webview_pro
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
lints:
dependency: transitive
description:
@ -102,13 +109,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
sky_engine:
dependency: transitive
description: flutter
@ -170,34 +170,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
webview_flutter:
dependency: "direct main"
description:
name: webview_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.1"
webview_flutter_android:
dependency: transitive
description:
name: webview_flutter_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.1"
webview_flutter_platform_interface:
dependency: transitive
description:
name: webview_flutter_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.1"
webview_flutter_wkwebview:
dependency: transitive
description:
name: webview_flutter_wkwebview
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
sdks:
dart: ">=2.14.0 <3.0.0"
flutter: ">=2.5.0"
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.22.0"

View File

@ -34,7 +34,9 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
webview_flutter: ^2.3.1
#webview_flutter: ^2.3.1
flutter_webview_pro: ^1.0.0
dev_dependencies:
flutter_test:
sdk: flutter