Upgrade webview
This commit is contained in:
parent
027eb0b7d1
commit
d157673aac
|
@ -1,5 +1,5 @@
|
||||||
|
import 'package:embedded_webview/webview_widget.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:webview_flutter/webview_flutter.dart';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
const title = String.fromEnvironment("APP_TITLE");
|
const title = String.fromEnvironment("APP_TITLE");
|
||||||
|
@ -18,16 +18,8 @@ class MyApp extends StatelessWidget {
|
||||||
// This widget is the root of your application.
|
// This widget is the root of your application.
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
MaterialColor materialColor = this._getMaterialColor(this._color);
|
MaterialColor materialColor = _getMaterialColor(_color);
|
||||||
return MaterialApp(
|
return MaterialApp(title: _title, theme: ThemeData(primarySwatch: materialColor), home: WebViewWidget(_uri));
|
||||||
title: this._title,
|
|
||||||
theme: ThemeData(primarySwatch: materialColor),
|
|
||||||
home: WebView(
|
|
||||||
initialUrl: this._uri,
|
|
||||||
javascriptMode: JavascriptMode.unrestricted,
|
|
||||||
zoomEnabled: true,
|
|
||||||
allowsInlineMediaPlayback: true,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialColor _getMaterialColor(String colorString) {
|
MaterialColor _getMaterialColor(String colorString) {
|
||||||
|
|
47
lib/webview_widget.dart
Normal file
47
lib/webview_widget.dart
Normal 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)),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
46
pubspec.lock
46
pubspec.lock
|
@ -74,6 +74,13 @@ packages:
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
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:
|
lints:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -102,13 +109,6 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.0"
|
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:
|
sky_engine:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description: flutter
|
description: flutter
|
||||||
|
@ -170,34 +170,6 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0"
|
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:
|
sdks:
|
||||||
dart: ">=2.14.0 <3.0.0"
|
dart: ">=2.12.0 <3.0.0"
|
||||||
flutter: ">=2.5.0"
|
flutter: ">=1.22.0"
|
||||||
|
|
|
@ -34,7 +34,9 @@ dependencies:
|
||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
cupertino_icons: ^1.0.2
|
cupertino_icons: ^1.0.2
|
||||||
webview_flutter: ^2.3.1
|
#webview_flutter: ^2.3.1
|
||||||
|
flutter_webview_pro: ^1.0.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
Reference in New Issue
Block a user