android app

This commit is contained in:
2025-11-10 16:42:12 +01:00
parent 2836d8d1b2
commit 047bce9610
8 changed files with 115 additions and 7 deletions
+27 -2
View File
@@ -1,13 +1,26 @@
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:url_launcher/url_launcher.dart';
/// Opens a folder in the native file explorer.
/// Returns true if a launch was attempted.
Future<bool> openFolder(String path) async {
if (path.isEmpty) return false;
try {
if (kIsWeb) return false;
if (kIsWeb) {
final uri = _parseLaunchableUri(path);
if (uri != null) {
return await launchUrl(uri, mode: LaunchMode.platformDefault);
}
return false;
}
if (Platform.isAndroid || Platform.isIOS) {
final uri = _parseLaunchableUri(path);
if (uri != null) {
return await launchUrl(uri, mode: LaunchMode.externalApplication);
}
return false; // Non-HTTP paths (e.g., Windows shares) are not openable on mobile
}
if (Platform.isWindows) {
await Process.run('explorer', [path]);
return true;
@@ -24,3 +37,15 @@ Future<bool> openFolder(String path) async {
return false;
}
Uri? _parseLaunchableUri(String input) {
final s = input.trim();
if (s.isEmpty) return null;
if (s.startsWith('http://') || s.startsWith('https://') || s.startsWith('content://') || s.startsWith('file://')) {
return Uri.tryParse(s);
}
// Allow smb:// or ftp:// if present
if (s.startsWith('smb://') || s.startsWith('ftp://')) {
return Uri.tryParse(s);
}
return null;
}