Files
wehub-resource-sync bb087aad19
CI / format (push) Failing after 2s
CI / packaging (push) Failing after 0s
CI / test (push) Failing after 3s
chore: import upstream snapshot with attribution
2026-07-13 11:58:56 +08:00

30 lines
1.1 KiB
Dart

import 'package:common/model/file_type.dart';
import 'package:flutter/material.dart';
import 'package:localsend_app/util/native/channel/android_channel.dart' as android_channel;
import 'package:localsend_app/util/native/platform_check.dart';
import 'package:localsend_app/widget/dialogs/cannot_open_file_dialog.dart';
import 'package:open_filex/open_filex.dart';
import 'package:permission_handler/permission_handler.dart';
/// Opens the selected file which is stored on the device.
Future<void> openFile(
BuildContext context,
FileType fileType,
String filePath, {
void Function()? onDeleteTap,
}) async {
if ((fileType == FileType.apk || filePath.toLowerCase().endsWith('.apk')) && checkPlatform([TargetPlatform.android])) {
await Permission.requestInstallPackages.request();
}
if (filePath.startsWith('content://')) {
await android_channel.openContentUri(uri: filePath);
return;
}
final fileOpenResult = await OpenFilex.open(filePath);
if (fileOpenResult.type != ResultType.done && context.mounted) {
await CannotOpenFileDialog.open(context, filePath, onDeleteTap);
}
}