Skip to content

Commit

Permalink
handle sending files on android
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmaSd committed Mar 14, 2021
1 parent 2bed81f commit b8b8a0a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
37 changes: 27 additions & 10 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
import 'package:file_selector/file_selector.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:path_provider/path_provider.dart';
import 'package:file_picker/file_picker.dart';

////////////////
///////FFI//////
Expand Down Expand Up @@ -191,6 +192,7 @@ class _BodyState extends State<Body> {
new Timer.periodic(Duration(milliseconds: 100), (Timer t) {
final msg = poll_recv_msg(message_ffi).toDartString();
if (msg != "") {
print(msg);
setState(() {
this.chats.add("${now()};$msg");
});
Expand Down Expand Up @@ -248,6 +250,7 @@ class _BodyState extends State<Body> {
final tmpDir = await getTemporaryDirectory();
final chat_s = chat.split("file:///");
final path = chat_s[0] + tmpDir.path + chat_s[1];
print(path);
launch(path);
}
},
Expand Down Expand Up @@ -307,18 +310,32 @@ class _BodyState extends State<Body> {
border: OutlineInputBorder(),
suffixIcon: IconButton(
onPressed: () async {
final file = await openFile();
if (file != null) {
final path = file.path;
setState(() {
this.chats.add("${now()};me;$path");
});
send_file(message_ffi, path.toNativeUtf8());
var path;
if (Platform.isAndroid) {
final result = await FilePicker.platform.pickFiles();

String fileUri = "file:///" + basename(path);
print(fileUri);
send_msg(message_ffi, fileUri.toNativeUtf8());
if (result != null) {
path = result.files.single.path;
} else {
return;
}
} else {
final file = await openFile();
if (file != null) {
path = file.path;
} else {
return;
}
}
setState(() {
this.chats.add("${now()};me;$path");
});
String fileUri = "file:///" + basename(path);
//send msg needs to happen before send file!!
send_msg(message_ffi, "$fileUri".toNativeUtf8());
send_file(message_ffi, "$path".toNativeUtf8());

print("fileuri=$fileUri");
},
icon: Icon(Icons.send),
))),
Expand Down
14 changes: 14 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.0"
file_picker:
dependency: "direct main"
description:
name: file_picker
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
file_selector:
dependency: "direct main"
description:
Expand Down Expand Up @@ -111,6 +118,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
name: flutter_plugin_android_lifecycle
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down
4 changes: 4 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
ffi: ^1.0.0
#desktop
file_selector: ^0.8.2
file_selector_linux: ^0.0.2
#mobile
file_picker: ^3.0.0

url_launcher: ^6.0.2
path_provider: ^2.0.1

Expand Down

0 comments on commit b8b8a0a

Please sign in to comment.