You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1019 B
34 lines
1019 B
2 months ago
|
import 'package:flutter/material.dart';
|
||
|
import 'package:file_picker/file_picker.dart';
|
||
|
import 'package:provider/provider.dart';
|
||
|
import 'package:win_text_editor/app/menus/menu_constants.dart';
|
||
|
import 'package:win_text_editor/app/providers/file_provider.dart';
|
||
|
import 'dart:io';
|
||
|
|
||
|
class MenuActions {
|
||
|
static Future<void> handleMenuAction(String value, BuildContext context) async {
|
||
|
switch (value) {
|
||
|
case MenuConstants.openFolder:
|
||
|
await _openFolder(context);
|
||
|
break;
|
||
|
case MenuConstants.exit:
|
||
|
_exitApplication();
|
||
|
break;
|
||
|
// 其他菜单项可以在这里添加处理逻辑
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static Future<void> _openFolder(BuildContext context) async {
|
||
|
final fileProvider = Provider.of<FileProvider>(context, listen: false);
|
||
|
final String? selectedDirectory = await FilePicker.platform.getDirectoryPath();
|
||
|
|
||
|
if (selectedDirectory != null) {
|
||
|
await fileProvider.loadDirectory(selectedDirectory);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static void _exitApplication() {
|
||
|
exit(0);
|
||
|
}
|
||
|
}
|