Add the Flutter video editing application with project management, media import, timeline editing, preview, AI assistance, diagnostics and settings. Include shared UI and native host packages, platform runners, application tests and release tooling. Provide usage and contribution guides, the MIT license and third-party notices. Exclude local credentials, build outputs and validation data.
59 lines
1.5 KiB
Dart
59 lines
1.5 KiB
Dart
import 'package:filegate/filegate.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
|
import '../../workspace/media_import.dart';
|
|
|
|
part 'file_picker.g.dart';
|
|
|
|
@Riverpod(keepAlive: true)
|
|
AppFilePicker filePicker(Ref ref) => const AppFilePicker();
|
|
|
|
class AppFilePicker {
|
|
const AppFilePicker();
|
|
|
|
Future<String?> pickDirectory({
|
|
String? initialDirectory,
|
|
String? confirmButtonText,
|
|
}) async {
|
|
final entry = await const Filegate().pickDirectory(
|
|
initialDirectory: initialDirectory,
|
|
confirmButtonText: confirmButtonText,
|
|
);
|
|
return entry == null ? null : _localPath(entry);
|
|
}
|
|
|
|
Future<List<ExternalMediaFile>> pickFiles({
|
|
required List<String> allowedExtensions,
|
|
}) async {
|
|
final entries = await const Filegate().pickFiles(
|
|
allowMultiple: true,
|
|
allowedExtensions: allowedExtensions,
|
|
persistAccess: false,
|
|
);
|
|
return [
|
|
for (final entry in entries ?? <PickedEntry>[])
|
|
if (entry.isContentUri)
|
|
ExternalMediaFile.content(
|
|
uri: entry.uri!,
|
|
name: entry.name,
|
|
byteLength: entry.size,
|
|
)
|
|
else
|
|
ExternalMediaFile(path: _localPath(entry)),
|
|
];
|
|
}
|
|
|
|
String _localPath(PickedEntry entry) {
|
|
final path = entry.fileSystemPath;
|
|
if (path == null) {
|
|
throw PlatformException(
|
|
code: 'unsupported_location',
|
|
message: 'Cutdex requires a local file system path.',
|
|
details: entry.path,
|
|
);
|
|
}
|
|
return path;
|
|
}
|
|
}
|