add request premission at import comics
This commit is contained in:
parent
a3daed42a1
commit
06232e4d01
|
@ -1 +1 @@
|
||||||
gomobile bind -target=android/arm,android/arm64,android/386 -o lib/Mobile.aar ./
|
gomobile bind -target=android/arm,android/arm64,android/386,android/amd64 -o lib/Mobile.aar ./
|
||||||
|
|
|
@ -82,23 +82,12 @@ Future<dynamic> _saveImageAndroid(String path, BuildContext context) async {
|
||||||
|
|
||||||
/// 选择一个文件夹用于保存文件
|
/// 选择一个文件夹用于保存文件
|
||||||
Future<String?> chooseFolder(BuildContext context) async {
|
Future<String?> chooseFolder(BuildContext context) async {
|
||||||
if (Platform.isAndroid) {
|
|
||||||
if (androidVersion >= 30) {
|
|
||||||
if (!(await Permission.manageExternalStorage.request()).isGranted) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!(await Permission.storage.request()).isGranted) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return FilesystemPicker.open(
|
return FilesystemPicker.open(
|
||||||
title: '选择一个文件夹',
|
title: '选择一个文件夹',
|
||||||
pickText: '将文件保存到这里',
|
pickText: '将文件保存到这里',
|
||||||
context: context,
|
context: context,
|
||||||
fsType: FilesystemType.folder,
|
fsType: FilesystemType.folder,
|
||||||
rootDirectory: Directory(currentChooserRoot()),
|
rootDirectory: Directory(await currentChooserRoot()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,11 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
|
||||||
import '../Common.dart';
|
import '../Common.dart';
|
||||||
import '../Method.dart';
|
import '../Method.dart';
|
||||||
|
import 'Platform.dart';
|
||||||
|
|
||||||
const _propertyName = "chooserRoot";
|
const _propertyName = "chooserRoot";
|
||||||
late String _chooserRoot;
|
late String _chooserRoot;
|
||||||
|
@ -14,7 +16,7 @@ Future<dynamic> initChooserRoot() async {
|
||||||
_chooserRoot = await method.loadProperty(_propertyName, "");
|
_chooserRoot = await method.loadProperty(_propertyName, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
String currentChooserRoot() {
|
String _currentChooserRoot() {
|
||||||
if (_chooserRoot == "") {
|
if (_chooserRoot == "") {
|
||||||
if (Platform.isWindows) {
|
if (Platform.isWindows) {
|
||||||
return '/';
|
return '/';
|
||||||
|
@ -23,9 +25,6 @@ String currentChooserRoot() {
|
||||||
} else if (Platform.isLinux) {
|
} else if (Platform.isLinux) {
|
||||||
return '/';
|
return '/';
|
||||||
} else if (Platform.isAndroid) {
|
} else if (Platform.isAndroid) {
|
||||||
// if (androidVersion >= 30) {
|
|
||||||
// return '/storage/emulated/0/Download';
|
|
||||||
// }
|
|
||||||
return '/storage/emulated/0';
|
return '/storage/emulated/0';
|
||||||
} else {
|
} else {
|
||||||
throw 'error';
|
throw 'error';
|
||||||
|
@ -34,6 +33,21 @@ String currentChooserRoot() {
|
||||||
return _chooserRoot;
|
return _chooserRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<String> currentChooserRoot() async {
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
if (androidVersion >= 30) {
|
||||||
|
if (!(await Permission.manageExternalStorage.request()).isGranted) {
|
||||||
|
throw Exception("申请权限被拒绝");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!(await Permission.storage.request()).isGranted) {
|
||||||
|
throw Exception("申请权限被拒绝");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _currentChooserRoot();
|
||||||
|
}
|
||||||
|
|
||||||
Future<dynamic> _inputChooserRoot(BuildContext context) async {
|
Future<dynamic> _inputChooserRoot(BuildContext context) async {
|
||||||
String? input = await displayTextInputDialog(
|
String? input = await displayTextInputDialog(
|
||||||
context,
|
context,
|
||||||
|
@ -53,7 +67,7 @@ Widget chooserRootSetting() {
|
||||||
builder: (BuildContext context, void Function(void Function()) setState) {
|
builder: (BuildContext context, void Function(void Function()) setState) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text("文件夹选择器默认路径"),
|
title: Text("文件夹选择器默认路径"),
|
||||||
subtitle: Text(currentChooserRoot()),
|
subtitle: Text(_currentChooserRoot()),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
await _inputChooserRoot(context);
|
await _inputChooserRoot(context);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
|
|
|
@ -38,7 +38,13 @@ Widget downloadAndExportPathSetting() {
|
||||||
"您即将选择一个目录, 如果文件系统可写, 下载的同时会为您自动导出一份",
|
"您即将选择一个目录, 如果文件系统可写, 下载的同时会为您自动导出一份",
|
||||||
);
|
);
|
||||||
if (b) {
|
if (b) {
|
||||||
String? folder = await chooseFolder(context);
|
late String? folder;
|
||||||
|
try {
|
||||||
|
folder = await chooseFolder(context);
|
||||||
|
} catch (e) {
|
||||||
|
defaultToast(context, "$e");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (folder != null) {
|
if (folder != null) {
|
||||||
await method.saveDownloadAndExportPath(folder);
|
await method.saveDownloadAndExportPath(folder);
|
||||||
_downloadAndExportPath = folder;
|
_downloadAndExportPath = folder;
|
||||||
|
|
|
@ -15,6 +15,7 @@ RegExp _versionExp = RegExp(r"^v\d+\.\d+.\d+$");
|
||||||
|
|
||||||
late String _version;
|
late String _version;
|
||||||
String? _latestVersion;
|
String? _latestVersion;
|
||||||
|
String? _latestVersionInfo;
|
||||||
|
|
||||||
const _propertyName = "checkVersionPeriod";
|
const _propertyName = "checkVersionPeriod";
|
||||||
late int _period = -1;
|
late int _period = -1;
|
||||||
|
@ -46,6 +47,10 @@ String? latestVersion() {
|
||||||
return _latestVersion;
|
return _latestVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String? latestVersionInfo() {
|
||||||
|
return _latestVersionInfo;
|
||||||
|
}
|
||||||
|
|
||||||
Future autoCheckNewVersion() {
|
Future autoCheckNewVersion() {
|
||||||
if (_period != 0) {
|
if (_period != 0) {
|
||||||
// -1 不检查, >0 未到检查时间
|
// -1 不检查, >0 未到检查时间
|
||||||
|
@ -76,6 +81,7 @@ Future _versionCheck() async {
|
||||||
String latestVersion = (json["name"]);
|
String latestVersion = (json["name"]);
|
||||||
if (latestVersion != _version) {
|
if (latestVersion != _version) {
|
||||||
_latestVersion = latestVersion;
|
_latestVersion = latestVersion;
|
||||||
|
_latestVersionInfo = json["body"] ?? "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // else dirtyVersion
|
} // else dirtyVersion
|
||||||
|
|
|
@ -36,6 +36,7 @@ class _AboutScreenState extends State<AboutScreen> {
|
||||||
var min = size.width < size.height ? size.width : size.height;
|
var min = size.width < size.height ? size.width : size.height;
|
||||||
var _currentVersion = currentVersion();
|
var _currentVersion = currentVersion();
|
||||||
var _latestVersion = latestVersion();
|
var _latestVersion = latestVersion();
|
||||||
|
var _latestVersionInfo = latestVersionInfo();
|
||||||
var _dirty = dirtyVersion();
|
var _dirty = dirtyVersion();
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
|
@ -80,6 +81,7 @@ class _AboutScreenState extends State<AboutScreen> {
|
||||||
Expanded(child: Container()),
|
Expanded(child: Container()),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
_buildNewVersionInfo(_latestVersionInfo),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -177,4 +179,24 @@ class _AboutScreenState extends State<AboutScreen> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildNewVersionInfo(String? latestVersionInfo) {
|
||||||
|
if (latestVersionInfo != null) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Divider(),
|
||||||
|
Text("更新内容:"),
|
||||||
|
Container(
|
||||||
|
padding: EdgeInsets.all(15),
|
||||||
|
child: Text(
|
||||||
|
latestVersionInfo,
|
||||||
|
style: TextStyle(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Container();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,13 @@ class _DownloadExportToFileScreenState
|
||||||
Platform.isAndroid) {
|
Platform.isAndroid) {
|
||||||
widgets.add(MaterialButton(
|
widgets.add(MaterialButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
String? path = await chooseFolder(context);
|
late String? path;
|
||||||
|
try {
|
||||||
|
path = await chooseFolder(context);
|
||||||
|
} catch (e) {
|
||||||
|
defaultToast(context, "$e");
|
||||||
|
return;
|
||||||
|
}
|
||||||
print("path $path");
|
print("path $path");
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -156,7 +162,13 @@ class _DownloadExportToFileScreenState
|
||||||
widgets.add(Container(height: 10));
|
widgets.add(Container(height: 10));
|
||||||
widgets.add(MaterialButton(
|
widgets.add(MaterialButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
String? path = await chooseFolder(context);
|
late String? path;
|
||||||
|
try {
|
||||||
|
path = await chooseFolder(context);
|
||||||
|
} catch (e) {
|
||||||
|
defaultToast(context, "$e");
|
||||||
|
return;
|
||||||
|
}
|
||||||
print("path $path");
|
print("path $path");
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -80,10 +80,17 @@ class _DownloadImportScreenState extends State<DownloadImportScreen> {
|
||||||
return MaterialButton(
|
return MaterialButton(
|
||||||
height: 80,
|
height: 80,
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
late String chooseRoot;
|
||||||
|
try {
|
||||||
|
chooseRoot = await currentChooserRoot();
|
||||||
|
} catch (e) {
|
||||||
|
defaultToast(context, "$e");
|
||||||
|
return;
|
||||||
|
}
|
||||||
String? path = await FilesystemPicker.open(
|
String? path = await FilesystemPicker.open(
|
||||||
title: '选择要导入的文件',
|
title: '选择要导入的文件',
|
||||||
context: context,
|
context: context,
|
||||||
rootDirectory: Directory(currentChooserRoot()),
|
rootDirectory: Directory(chooseRoot),
|
||||||
fsType: FilesystemType.file,
|
fsType: FilesystemType.file,
|
||||||
folderIconColor: Colors.teal,
|
folderIconColor: Colors.teal,
|
||||||
allowedExtensions: ['.zip'],
|
allowedExtensions: ['.zip'],
|
||||||
|
@ -117,7 +124,8 @@ class _DownloadImportScreenState extends State<DownloadImportScreen> {
|
||||||
return MaterialButton(
|
return MaterialButton(
|
||||||
height: 80,
|
height: 80,
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
var path = await inputString(context, '请输入导出设备提供的地址\n例如 "192.168.1.2:50000"');
|
var path =
|
||||||
|
await inputString(context, '请输入导出设备提供的地址\n例如 "192.168.1.2:50000"');
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
try {
|
try {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|
Loading…
Reference in New Issue