open file path
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import '../models/project.dart';
|
||||
import '../services/storage_service.dart';
|
||||
import 'project_screen.dart';
|
||||
@ -90,6 +92,29 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _openFolder(String filePath) async {
|
||||
try {
|
||||
final directory = path.dirname(filePath);
|
||||
|
||||
if (Platform.isLinux) {
|
||||
await Process.run('xdg-open', [directory]);
|
||||
} else if (Platform.isWindows) {
|
||||
await Process.run('explorer', [directory]);
|
||||
} else if (Platform.isMacOS) {
|
||||
await Process.run('open', [directory]);
|
||||
}
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Failed to open folder: $e'),
|
||||
backgroundColor: Colors.red,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _showStorageInfo() async {
|
||||
final filePath = await _storageService.getProjectsFilePath();
|
||||
if (!mounted) return;
|
||||
@ -132,6 +157,14 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Close'),
|
||||
),
|
||||
FilledButton.icon(
|
||||
onPressed: () {
|
||||
_openFolder(filePath);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
icon: const Icon(Icons.folder_open),
|
||||
label: const Text('Open Folder'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user