I´m currently working on a project based on php and javascript where, within its functions, it requires uploading an image through an input, which works perfectly from the browser. Encapsulating the web application in an android app, I use flutter as a framework, through the webview_flutter plugin in version 3.0.0. It does not allow to open the camera or the android image gallery.
At the end, i need your valuable support, what kind of method is required or recommend for javascript to open the intent and display the camera or gallery?
Thanks to all!!!
Here´re my dependencies on my pubspec.yaml
dependencies:
flutter:
sdk: flutter
camera:
path_provider:
path:
image_picker: ^0.8.2
flutter_webview_plugin: ^0.3.10+1
this´s my default config Android in build.gradle:
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.jlcornejo.iaconlink"
minSdkVersion 21
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
here´re my imports too:
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:myapp/service/audio_service_mp3.dart';
import 'package:record_mp3/record_mp3.dart';
import 'webview/webview_channel_controller.dart';
my methods in main.dart:
/// selecciona la imagen desde la galería
Future<void> _pickImage(ImageSource source) async {
File selected = await ImagePicker.pickImage(source: source);
setState(() {
_imageFile = selected;
});
print("close");
if (_imageFile == null) {
print("close in");
flutterWebViewPlugin.show();
}
}
/// Remueve la imagen
void _clear() {
setState(() => _imageFile = null);
}
/// Sube la imagen
void _startUpload() {
File file = _imageFile;
if (file == null) return;
String base64Image = base64Encode(file.readAsBytesSync());
String fileName = file.path.split("/").last;
http.post(phpEndPoint, body: {
"image": base64Image,
"name": fileName,
}).then((res) {
print(res.statusCode);
print(fileName);
Navigator.of(context).pop(null);
flutterWebViewPlugin.show();
}).catchError((err) {
print(err);
});
}