Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 9 additions & 23 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -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());
Expand Down Expand Up @@ -62,8 +60,8 @@ class _MyHomePageState extends State<MyHomePage> {
exit(0);
}
},
//attachment only works on android for now
onAttachFile: _androidFilePicker,
//work for both android, iOS
onAttachFile: _pickFiles,
onLoadStarted: () {
print("loading widget");
},
Expand All @@ -77,26 +75,14 @@ class _MyHomePageState extends State<MyHomePage> {
);
}

Future<List<String>> _androidFilePicker() async {
final picker = image_picker.ImagePicker();
final photo =
await picker.pickImage(source: image_picker.ImageSource.gallery);
Future<List<String>> _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()];
}
}
5 changes: 2 additions & 3 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion lib/ui/webview_widget/webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class _WebviewState extends State<Webview> {
onWebResourceError: (WebResourceError error) {},
onNavigationRequest: (NavigationRequest request) {
_goToUrl(request.url);
return NavigationDecision.prevent;
// allow android, ios navigation
return NavigationDecision.navigate;
},
),
)
Expand Down