Currently, webview_flutter
does not support uploading files to websites on Android.
This funcionality will be added in version 2.0.3
through the follwing PR: flutter/plugins#3225.
This repo contains a quick fix based on the suggestions in this issue comment and the following gists:
I modified these files to:
- use EasyPermissions
- use material theme for dialogs
- fit my usecase a bit better
For other usecases it might be usefull to clone this and mess with
FilePickerActivity.java
.
Note that this version of webview_flutter
is based on version 1.0.7,
so there are some existing issues fixed in later releases.
I'm not going to maintain this actively and will switch to the official fix once that comes out (and once there are no dependency conflicts).
In your pubspec.yaml
, replace
dependencies:
webview_flutter: ^1.0.7
with:
dependencies:
webview_flutter:
git: [email protected]:Siarl/webview_flutter_with_filepicker.git
A Flutter plugin that provides a WebView.
On iOS the WebView widget is backed by a WKWebView; On Android the WebView widget is backed by a WebView.
Add webview_flutter
as a dependency in your pubspec.yaml file.
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.
The WebView is relying on Platform Views to embed the Android’s webview within the Flutter app. By default a Virtual Display based platform view backend is used, this implementation has multiple keyboard. When keyboard input is required we recommend using the Hybrid Composition based platform views implementation. Note that on Android versions prior to Android 10 Hybrid Composition has some performance drawbacks.
To enable hybrid composition, set WebView.platform = SurfaceAndroidWebView();
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 hybrid composition.
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
}
@override
Widget build(BuildContext context) {
return WebView(
initialUrl: 'https://flutter.dev',
);
}
}
SurfaceAndroidWebView()
requires API level 19. The plugin itself doesn't enforce the API level, so if you want to make the app available on devices running this API level or above, add the following to <your-app>/android/app/build.gradle
:
android {
defaultConfig {
// Required by the Flutter WebView plugin.
minSdkVersion 19
}
}