diff --git a/example/lib/main.dart b/example/lib/main.dart index b885caa..b1cdc13 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,11 +1,9 @@ import 'dart:io'; import 'package:chatwoot_sdk/chatwoot_sdk.dart'; +import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:image/image.dart' as image; -import 'package:image_picker/image_picker.dart' as image_picker; -import 'package:path_provider/path_provider.dart'; void main() { runApp(MyApp()); @@ -62,8 +60,8 @@ class _MyHomePageState extends State { exit(0); } }, - //attachment only works on android for now - onAttachFile: _androidFilePicker, + //work for both android, iOS + onAttachFile: _pickFiles, onLoadStarted: () { print("loading widget"); }, @@ -77,26 +75,14 @@ class _MyHomePageState extends State { ); } - Future> _androidFilePicker() async { - final picker = image_picker.ImagePicker(); - final photo = - await picker.pickImage(source: image_picker.ImageSource.gallery); + Future> _pickFiles() async { + FilePickerResult result = await FilePicker.platform.pickFiles(allowMultiple: true); - if (photo == null) { + if (result != null) { + File file = File(result.files.single.path); + return [file.uri.toString()]; + } else { return []; } - - final imageData = await photo.readAsBytes(); - final decodedImage = image.decodeImage(imageData); - final scaledImage = image.copyResize(decodedImage, width: 500); - final jpg = image.encodeJpg(scaledImage, quality: 90); - - final filePath = (await getTemporaryDirectory()).uri.resolve( - './image_${DateTime.now().microsecondsSinceEpoch}.jpg', - ); - final file = await File.fromUri(filePath).create(recursive: true); - await file.writeAsBytes(jpg, flush: true); - - return [file.uri.toString()]; } } diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 8631553..b076b2e 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -26,12 +26,11 @@ dependencies: chatwoot_sdk: path: ../ + # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 - image_picker: ^0.8.7 - image: ^4.0.15 - path_provider: ^2.0.13 + file_picker: ^5.2.9 dev_dependencies: flutter_test: diff --git a/lib/ui/webview_widget/webview.dart b/lib/ui/webview_widget/webview.dart index c5be78a..a553db9 100644 --- a/lib/ui/webview_widget/webview.dart +++ b/lib/ui/webview_widget/webview.dart @@ -87,7 +87,8 @@ class _WebviewState extends State { onWebResourceError: (WebResourceError error) {}, onNavigationRequest: (NavigationRequest request) { _goToUrl(request.url); - return NavigationDecision.prevent; + // allow android, ios navigation + return NavigationDecision.navigate; }, ), )