flutter_webview_pro

Creator: coderz1093

Last updated:

Add to Cart

Description:

flutter webview pro

Flutter WebView Pro #

A Flutter plugin that provides a WebView widget.
On iOS the WebView widget is backed by a WKWebView;
On Android the WebView widget is backed by a WebView.
A Flutter plugin that provides a WebView widget who Support photo upload/take camera and Geolocation.
The official flutter plugin webview_flutter Android does not support H5 file upload, that is, it does not support the H5 code below.
<input type="file">
copied to clipboard
This caused us a lot of inconvenience, so this plugin adds support for file upload and geolocation on the android side on the basis of the official plugin.
Usage #
Add flutter_webview_pro as a dependency in your pubspec.yaml file. If you are targeting Android, make sure to read the Android Platform Views section below to choose the platform view mode that best suits your needs.
You can now include a WebView widget in your widget tree. See the
WebView
widget's Dartdoc for more details on how to use the widget.
1.Installing #
Add this to your package's pubspec.yaml file:
dependencies:
# if you Flutter >=2.5 and <2.8, depend this
flutter_webview_pro: ^3.0.1+4

# if you Flutter >=2.8 , depend this
flutter_webview_pro:
git:
url: https://github.com/wenzhiming/flutter-plugins.git
ref: dev-3.0.4
path: packages/webview_flutter/webview_flutter
copied to clipboard
2.Import #
import 'package:flutter_webview_pro/webview_flutter.dart';
copied to clipboard
3.How to use #
body: Builder(builder: (BuildContext context) {
return WebView(
initialUrl: 'https://www.xxxxxxx',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
onProgress: (int progress) {
print("WebView is loading (progress : $progress%)");
},
javascriptChannels: <JavascriptChannel>{
_toasterJavascriptChannel(context),
},
navigationDelegate: (NavigationRequest request) {
if (request.url.startsWith('https://www.youtube.com/')) {
print('blocking navigation to $request}');
return NavigationDecision.prevent;
}
print('allowing navigation to $request');
return NavigationDecision.navigate;
},
onPageStarted: (String url) {
print('Page started loading: $url');
},
onPageFinished: (String url) {
print('Page finished loading: $url');
},
gestureNavigationEnabled: true,
geolocationEnabled: false,//support geolocation or not
);
}),
copied to clipboard
Android Platform Views #
This plugin uses
Platform Views to embed
the Android’s webview within the Flutter app. It supports two modes:
hybrid composition (the current default) and virtual display.
Here are some points to consider when choosing between the two:

Hybrid composition has built-in keyboard support while virtual display has multiple
keyboard issues.
Hybrid composition requires Android SDK 19+ while virtual display requires Android SDK 20+.
Hybrid composition and virtual display have different
performance tradeoffs.

Using Hybrid Composition #
The mode is currently enabled by default. You should however make sure to set the correct minSdkVersion in android/app/build.gradle if it was previously lower than 19:
android {
defaultConfig {
minSdkVersion 19
}
}
copied to clipboard
Using Virtual displays #


Set the correct minSdkVersion in android/app/build.gradle (if it was previously lower than 20):
android {
defaultConfig {
minSdkVersion 20
}
}
copied to clipboard


Set WebView.platform = AndroidWebView(); in initState().
For example:
import 'dart:io';

import 'package:webview_flutter/webview_flutter.dart';

class WebViewExample extends StatefulWidget {
@override
WebViewExampleState createState() => WebViewExampleState();
}

class WebViewExampleState extends State<WebViewExample> {
@override
void initState() {
super.initState();
// Enable virtual display.
if (Platform.isAndroid) WebView.platform = AndroidWebView();
}

@override
Widget build(BuildContext context) {
return WebView(
initialUrl: 'https://flutter.dev',
);
}
}
copied to clipboard


Enable Material Components for Android #
To use Material Components when the user interacts with input elements in the WebView,
follow the steps described in the Enabling Material Components instructions.
Setting custom headers on POST requests #
Currently, setting custom headers when making a post request with the WebViewController's loadRequest method is not supported on Android.
If you require this functionality, a workaround is to make the request manually, and then load the response data using loadHTMLString instead.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.