mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
38 lines
988 B
Dart
38 lines
988 B
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:share_plus/share_plus.dart';
|
|
|
|
import '../../generated/l10n.dart';
|
|
|
|
Future<bool> shareFiles(BuildContext context, List<String> filePaths) async {
|
|
for (final filePath in filePaths) {
|
|
if (!await File(filePath).exists()) {
|
|
return false;
|
|
}
|
|
}
|
|
var text = '';
|
|
if (filePaths.length == 1) {
|
|
text = filePaths.first.split('/').last;
|
|
} else {
|
|
text = '${filePaths.length} ${S.of(context).files}';
|
|
}
|
|
final xfiles = filePaths.map((e) => XFile(e)).toList();
|
|
await Share.shareXFiles(xfiles, text: 'ServerBox -> $text');
|
|
return filePaths.isNotEmpty;
|
|
}
|
|
|
|
bool get longPressEnabled {
|
|
switch (defaultTargetPlatform) {
|
|
case TargetPlatform.android:
|
|
case TargetPlatform.iOS:
|
|
return true;
|
|
case TargetPlatform.macOS:
|
|
case TargetPlatform.fuchsia:
|
|
case TargetPlatform.linux:
|
|
case TargetPlatform.windows:
|
|
return false;
|
|
}
|
|
}
|