Last updated:
0 purchases
flutter webview kawamura
A Flutter plugin that allows you to add an inline webview, to use an headless webview, and to open an in-app browser window.
Requirements #
Dart sdk: ">=2.17.0 <4.0.0"
Flutter: ">=3.0.0"
Android: minSdkVersion >= 19, compileSdk >= 34, AGP version >= 7.3.0 (use Android Studio - Android Gradle plugin Upgrade Assistant for help), support for androidx (see AndroidX Migration to migrate an existing app)
iOS 9.0+: --ios-language swift, Xcode version >= 14.3
MacOS 10.11+: Xcode version >= 14.3
WebView Page Instruction Code Sample #
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_webview_kawamura/flutter_webview_kawamura.dart';
class WebViewExampleScreen extends StatefulWidget {
@override
_WebViewExampleScreenState createState() => _WebViewExampleScreenState();
}
class _WebViewExampleScreenState extends State<WebViewExampleScreen> {
final GlobalKey webViewKey = GlobalKey();
InAppWebViewController? webViewController;
InAppWebViewSettings settings = InAppWebViewSettings(
isInspectable: kDebugMode,
mediaPlaybackRequiresUserGesture: false,
allowsInlineMediaPlayback: true,
iframeAllow: "camera; microphone",
iframeAllowFullscreen: true);
String url = "";
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(children: <Widget>[
Expanded(
child: Stack(
children: [
InAppWebView(
key: webViewKey,
zoneId: '',
userParameter: '',
initialSettings: settings,
onWebViewCreated: (controller) async {
webViewController = controller;
},
onLoadStart: (controller, url) async {
setState(() {
this.url = url.toString();
});
},
onPermissionRequest: (controller, request) async {
return PermissionResponse(
resources: request.resources,
action: PermissionResponseAction.GRANT);
},
shouldOverrideUrlLoading: (controller, navigationAction) async {
var uri = navigationAction.request.url!;
print('uri = $uri');
return NavigationActionPolicy.ALLOW;
},
onLoadStop: (controller, url) async {
setState(() {
this.url = url.toString();
});
},
onReceivedError: (controller, request, error) {},
onWebViewClosed: (controller) async {
//TODO Navigator.pop(context);
print('webview closed');
Navigator.pop(context);
},
onUpdateVisitedHistory: (controller, url, isReload) {
setState(() {
this.url = url.toString();
});
},
onConsoleMessage: (controller, consoleMessage) {
print(consoleMessage);
},
),
],
),
),
])));
}
}
copied to clipboard
Installation #
Add flutter_webview as a dependency in your pubspec.yaml file.
Installation - Web support #
To make it work properly on the Web platform, you need to add the web_support.js file inside the <head> of your web/index.html file:
<head>
<!-- ... -->
<script
type="application/javascript"
src="/assets/packages/flutter_webview_web/assets/web/web_support.js"
defer
></script>
<!-- ... -->
</head>
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.