feat(example_full): create example representing the whole plugin functional
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
import 'package:nearby_service/nearby_service.dart';
|
||||
|
||||
extension ChannalPreviewName on CommunicationChannelState {
|
||||
String get previewName {
|
||||
return switch (this) {
|
||||
CommunicationChannelState.notConnected => 'Not connected',
|
||||
CommunicationChannelState.loading => 'Connecting',
|
||||
CommunicationChannelState.connected => 'Connected',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:nearby_service/nearby_service.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class FilesSaver {
|
||||
FilesSaver._();
|
||||
|
||||
static Future<List<NearbyFileInfo>> savePack(
|
||||
ReceivedNearbyFilesPack pack) async {
|
||||
final files = <NearbyFileInfo>[];
|
||||
final directory = Platform.isAndroid
|
||||
? Directory('storage/emulated/0/Download')
|
||||
: await getApplicationDocumentsDirectory();
|
||||
|
||||
for (final nearbyFile in pack.files) {
|
||||
final newFile = await File(nearbyFile.path).copy(
|
||||
'${directory.path}/${DateTime.now().microsecondsSinceEpoch}.${nearbyFile.extension}',
|
||||
);
|
||||
if (!await newFile.exists()) {
|
||||
await newFile.create();
|
||||
}
|
||||
files.add(NearbyFileInfo(path: newFile.path));
|
||||
}
|
||||
return files;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user