add request premission at import comics

This commit is contained in:
niuhuan 2021-11-18 09:53:30 +08:00
parent a3daed42a1
commit 06232e4d01
8 changed files with 80 additions and 23 deletions

View File

@ -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 ./

View File

@ -82,23 +82,12 @@ Future<dynamic> _saveImageAndroid(String path, 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(
title: '选择一个文件夹',
pickText: '将文件保存到这里',
context: context,
fsType: FilesystemType.folder,
rootDirectory: Directory(currentChooserRoot()),
rootDirectory: Directory(await currentChooserRoot()),
);
}

View File

@ -3,9 +3,11 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import '../Common.dart';
import '../Method.dart';
import 'Platform.dart';
const _propertyName = "chooserRoot";
late String _chooserRoot;
@ -14,7 +16,7 @@ Future<dynamic> initChooserRoot() async {
_chooserRoot = await method.loadProperty(_propertyName, "");
}
String currentChooserRoot() {
String _currentChooserRoot() {
if (_chooserRoot == "") {
if (Platform.isWindows) {
return '/';
@ -23,9 +25,6 @@ String currentChooserRoot() {
} else if (Platform.isLinux) {
return '/';
} else if (Platform.isAndroid) {
// if (androidVersion >= 30) {
// return '/storage/emulated/0/Download';
// }
return '/storage/emulated/0';
} else {
throw 'error';
@ -34,6 +33,21 @@ String currentChooserRoot() {
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 {
String? input = await displayTextInputDialog(
context,
@ -53,7 +67,7 @@ Widget chooserRootSetting() {
builder: (BuildContext context, void Function(void Function()) setState) {
return ListTile(
title: Text("文件夹选择器默认路径"),
subtitle: Text(currentChooserRoot()),
subtitle: Text(_currentChooserRoot()),
onTap: () async {
await _inputChooserRoot(context);
setState(() {});

View File

@ -38,7 +38,13 @@ Widget downloadAndExportPathSetting() {
"您即将选择一个目录, 如果文件系统可写, 下载的同时会为您自动导出一份",
);
if (b) {
String? folder = await chooseFolder(context);
late String? folder;
try {
folder = await chooseFolder(context);
} catch (e) {
defaultToast(context, "$e");
return;
}
if (folder != null) {
await method.saveDownloadAndExportPath(folder);
_downloadAndExportPath = folder;

View File

@ -15,6 +15,7 @@ RegExp _versionExp = RegExp(r"^v\d+\.\d+.\d+$");
late String _version;
String? _latestVersion;
String? _latestVersionInfo;
const _propertyName = "checkVersionPeriod";
late int _period = -1;
@ -46,6 +47,10 @@ String? latestVersion() {
return _latestVersion;
}
String? latestVersionInfo() {
return _latestVersionInfo;
}
Future autoCheckNewVersion() {
if (_period != 0) {
// -1 , >0
@ -76,6 +81,7 @@ Future _versionCheck() async {
String latestVersion = (json["name"]);
if (latestVersion != _version) {
_latestVersion = latestVersion;
_latestVersionInfo = json["body"] ?? "";
}
}
} // else dirtyVersion

View File

@ -36,6 +36,7 @@ class _AboutScreenState extends State<AboutScreen> {
var min = size.width < size.height ? size.width : size.height;
var _currentVersion = currentVersion();
var _latestVersion = latestVersion();
var _latestVersionInfo = latestVersionInfo();
var _dirty = dirtyVersion();
return Scaffold(
appBar: AppBar(
@ -80,6 +81,7 @@ class _AboutScreenState extends State<AboutScreen> {
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();
}
}

View File

@ -126,7 +126,13 @@ class _DownloadExportToFileScreenState
Platform.isAndroid) {
widgets.add(MaterialButton(
onPressed: () async {
String? path = await chooseFolder(context);
late String? path;
try {
path = await chooseFolder(context);
} catch (e) {
defaultToast(context, "$e");
return;
}
print("path $path");
if (path != null) {
try {
@ -156,7 +162,13 @@ class _DownloadExportToFileScreenState
widgets.add(Container(height: 10));
widgets.add(MaterialButton(
onPressed: () async {
String? path = await chooseFolder(context);
late String? path;
try {
path = await chooseFolder(context);
} catch (e) {
defaultToast(context, "$e");
return;
}
print("path $path");
if (path != null) {
try {

View File

@ -80,10 +80,17 @@ class _DownloadImportScreenState extends State<DownloadImportScreen> {
return MaterialButton(
height: 80,
onPressed: () async {
late String chooseRoot;
try {
chooseRoot = await currentChooserRoot();
} catch (e) {
defaultToast(context, "$e");
return;
}
String? path = await FilesystemPicker.open(
title: '选择要导入的文件',
context: context,
rootDirectory: Directory(currentChooserRoot()),
rootDirectory: Directory(chooseRoot),
fsType: FilesystemType.file,
folderIconColor: Colors.teal,
allowedExtensions: ['.zip'],
@ -117,7 +124,8 @@ class _DownloadImportScreenState extends State<DownloadImportScreen> {
return MaterialButton(
height: 80,
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) {
try {
setState(() {