diff --git a/android/app/build.gradle b/android/app/build.gradle index 18c117a..6ef3881 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -40,6 +40,10 @@ android { targetCompatibility JavaVersion.VERSION_1_8 } + dependencies { + implementation 'com.google.android.material:material:1.4.0' + } + kotlinOptions { jvmTarget = '1.8' } diff --git a/android/app/src/main/res/values-night/styles.xml b/android/app/src/main/res/values-night/styles.xml index 449a9f9..26750f2 100644 --- a/android/app/src/main/res/values-night/styles.xml +++ b/android/app/src/main/res/values-night/styles.xml @@ -12,7 +12,7 @@ running. This Theme is only used starting with V2 of Flutter's Android embedding. --> - diff --git a/android/app/src/main/res/values/styles.xml b/android/app/src/main/res/values/styles.xml index d74aa35..2316bee 100644 --- a/android/app/src/main/res/values/styles.xml +++ b/android/app/src/main/res/values/styles.xml @@ -12,7 +12,7 @@ running. This Theme is only used starting with V2 of Flutter's Android embedding. --> - diff --git a/lib/main.dart b/lib/main.dart index 24038d4..1044a57 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,5 @@ +import 'package:comptaplan_app/webview_widget.dart'; import 'package:flutter/material.dart'; -import 'package:webview_flutter/webview_flutter.dart'; void main() { const title = String.fromEnvironment("APP_TITLE"); @@ -18,14 +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, - )); + MaterialColor materialColor = _getMaterialColor(this._color); + return MaterialApp(title: _title, theme: ThemeData(primarySwatch: materialColor), home: WebViewWidget(_uri)); } MaterialColor _getMaterialColor(String colorString) { diff --git a/lib/webview_widget.dart b/lib/webview_widget.dart new file mode 100644 index 0000000..a16e0c1 --- /dev/null +++ b/lib/webview_widget.dart @@ -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 { + 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: { + _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)), + ); + }); + } +} diff --git a/pubspec.lock b/pubspec.lock index fcdf4d4..f1e5d5e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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" diff --git a/pubspec.yaml b/pubspec.yaml index 47c13cc..4f2480e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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.0.13 +# webview_flutter: ^2.0.13 + # COmmunity plugin adding features unsupported in the official webview + flutter_webview_pro: ^1.0.0 dev_dependencies: flutter_test: sdk: flutter