From 296dd3102e1baf3f0c4acf5c6b1ef0789025a188 Mon Sep 17 00:00:00 2001 From: "vijay.maurya" Date: Wed, 19 Apr 2023 14:48:13 +0530 Subject: [PATCH 1/2] Attach image, docs etc. --- example/lib/main.dart | 16 ++++++++++++++-- example/pubspec.yaml | 1 + lib/ui/webview_widget/webview.dart | 3 ++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index b885caa..550ac32 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,6 +1,7 @@ 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; @@ -62,8 +63,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,6 +78,17 @@ class _MyHomePageState extends State { ); } + Future> _pickFiles() async { + FilePickerResult result = await FilePicker.platform.pickFiles(allowMultiple: true); + + if (result != null) { + File file = File(result.files.single.path); + return [file.uri.toString()]; + } else { + return []; + } + } + Future> _androidFilePicker() async { final picker = image_picker.ImagePicker(); final photo = diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 8631553..70e53b8 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -25,6 +25,7 @@ dependencies: sdk: flutter chatwoot_sdk: path: ../ + file_picker: ^5.2.9 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. 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; }, ), ) From 1cd74566496fec599c539cdf8d34a7f60a2318b4 Mon Sep 17 00:00:00 2001 From: "vijay.maurya" Date: Thu, 20 Apr 2023 12:53:09 +0530 Subject: [PATCH 2/2] file attach --- example/lib/main.dart | 26 -------------------------- example/pubspec.yaml | 6 ++---- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 550ac32..b1cdc13 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -4,9 +4,6 @@ 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()); @@ -88,27 +85,4 @@ class _MyHomePageState extends State { return []; } } - - Future> _androidFilePicker() async { - final picker = image_picker.ImagePicker(); - final photo = - await picker.pickImage(source: image_picker.ImageSource.gallery); - - if (photo == null) { - 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 70e53b8..b076b2e 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -25,14 +25,12 @@ dependencies: sdk: flutter chatwoot_sdk: path: ../ - file_picker: ^5.2.9 + # 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: