feat(example): clean up for android
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AppSnackBar {
|
||||
AppSnackBar._();
|
||||
|
||||
static Future<void> show(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
String? subtitle,
|
||||
String? actionName,
|
||||
VoidCallback? onAcceptAction,
|
||||
}) async {
|
||||
final content = Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(title, style: const TextStyle(fontSize: 16)),
|
||||
if (subtitle != null) Text(subtitle),
|
||||
],
|
||||
);
|
||||
final action = onAcceptAction != null && actionName != null
|
||||
? SnackBarAction(label: actionName, onPressed: onAcceptAction)
|
||||
: null;
|
||||
final messenger = ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: content,
|
||||
action: action,
|
||||
),
|
||||
);
|
||||
return messenger.closed.then((value) => null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:nearby_service/nearby_service.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class FilesSaver {
|
||||
FilesSaver._();
|
||||
|
||||
static Future<bool> savePack(
|
||||
ReceivedNearbyFilesPack pack,
|
||||
) async {
|
||||
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();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user