2021-10-07 03:47:28 +00:00
|
|
|
/// 文件夹选择器的根路径
|
|
|
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import '../Common.dart';
|
|
|
|
import '../Method.dart';
|
|
|
|
|
|
|
|
const _propertyName = "chooserRoot";
|
|
|
|
late String _chooserRoot;
|
|
|
|
|
2021-11-04 05:56:25 +00:00
|
|
|
Future<dynamic> initChooserRoot() async {
|
2021-10-07 03:47:28 +00:00
|
|
|
_chooserRoot = await method.loadProperty(_propertyName, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
String currentChooserRoot() {
|
|
|
|
if (_chooserRoot == "") {
|
|
|
|
if (Platform.isWindows) {
|
|
|
|
return '/';
|
|
|
|
} else if (Platform.isMacOS) {
|
|
|
|
return '/Users';
|
|
|
|
} else if (Platform.isLinux) {
|
|
|
|
return '/';
|
|
|
|
} else if (Platform.isAndroid) {
|
2021-10-14 10:12:36 +00:00
|
|
|
// if (androidVersion >= 30) {
|
|
|
|
// return '/storage/emulated/0/Download';
|
|
|
|
// }
|
|
|
|
return '/storage/emulated/0';
|
2021-10-07 03:47:28 +00:00
|
|
|
} else {
|
|
|
|
throw 'error';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _chooserRoot;
|
|
|
|
}
|
|
|
|
|
2021-11-04 05:56:25 +00:00
|
|
|
Future<dynamic> _inputChooserRoot(BuildContext context) async {
|
2021-10-07 03:47:28 +00:00
|
|
|
String? input = await displayTextInputDialog(
|
|
|
|
context,
|
|
|
|
'文件夹选择器根路径',
|
|
|
|
'请输入文件夹选择器根路径',
|
|
|
|
_chooserRoot,
|
|
|
|
"导出时选择目录的默认路径, 同时也是根路径, 不能正常导出时也可以尝试设置此选项。",
|
|
|
|
);
|
|
|
|
if (input != null) {
|
|
|
|
await method.saveProperty(_propertyName, input);
|
|
|
|
_chooserRoot = input;
|
|
|
|
}
|
|
|
|
}
|
2021-11-04 03:45:22 +00:00
|
|
|
|
|
|
|
Widget chooserRootSetting() {
|
|
|
|
return StatefulBuilder(
|
|
|
|
builder: (BuildContext context, void Function(void Function()) setState) {
|
|
|
|
return ListTile(
|
|
|
|
title: Text("文件夹选择器默认路径"),
|
|
|
|
subtitle: Text(currentChooserRoot()),
|
|
|
|
onTap: () async {
|
2021-11-04 05:56:25 +00:00
|
|
|
await _inputChooserRoot(context);
|
2021-11-04 03:45:22 +00:00
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|