2021-10-18 09:31:05 +00:00
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
2021-11-11 03:00:38 +00:00
|
|
|
|
import 'package:pikapika/basic/Common.dart';
|
|
|
|
|
import 'package:pikapika/basic/Method.dart';
|
|
|
|
|
import 'package:pikapika/screens/components/ContentBuilder.dart';
|
|
|
|
|
import 'package:pikapika/screens/components/ContentLoading.dart';
|
2021-10-18 09:31:05 +00:00
|
|
|
|
|
2023-05-08 09:57:28 +00:00
|
|
|
|
import 'components/ListView.dart';
|
2022-03-19 04:12:27 +00:00
|
|
|
|
import 'components/RightClickPop.dart';
|
|
|
|
|
|
2021-10-26 11:04:23 +00:00
|
|
|
|
// 数据迁移页面
|
2021-10-18 09:31:05 +00:00
|
|
|
|
class MigrateScreen extends StatefulWidget {
|
2022-03-17 03:31:25 +00:00
|
|
|
|
const MigrateScreen({Key? key}) : super(key: key);
|
|
|
|
|
|
2021-10-18 09:31:05 +00:00
|
|
|
|
@override
|
|
|
|
|
State<StatefulWidget> createState() => _MigrateScreenState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _MigrateScreenState extends State<MigrateScreen> {
|
2022-07-12 07:28:47 +00:00
|
|
|
|
late final Key _key = UniqueKey();
|
2022-03-17 03:31:25 +00:00
|
|
|
|
late final Future _future = _load();
|
2021-10-18 09:31:05 +00:00
|
|
|
|
late String _current;
|
|
|
|
|
late List<String> paths;
|
|
|
|
|
String _message = "";
|
|
|
|
|
|
|
|
|
|
int _migrate = 0; // 0 没有开始迁移,1 正在迁移,2 迁移成功,3 迁移失败
|
|
|
|
|
|
|
|
|
|
Future _load() async {
|
|
|
|
|
await method.setDownloadRunning(false);
|
|
|
|
|
_current = await method.dataLocal();
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
|
paths = await method.androidGetExtendDirs();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
2022-04-17 05:48:09 +00:00
|
|
|
|
Widget build(BuildContext context) {
|
2022-03-25 14:57:30 +00:00
|
|
|
|
return rightClickPop(
|
|
|
|
|
child: buildScreen(context),
|
|
|
|
|
context: context,
|
|
|
|
|
canPop: true,
|
|
|
|
|
);
|
2022-03-19 04:12:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget buildScreen(BuildContext context) {
|
2021-10-18 09:31:05 +00:00
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
2022-03-19 04:12:27 +00:00
|
|
|
|
title: const Text('数据迁移'),
|
2021-10-18 09:31:05 +00:00
|
|
|
|
),
|
|
|
|
|
body: ContentBuilder(
|
2022-07-12 07:28:47 +00:00
|
|
|
|
key: _key,
|
2021-10-18 09:31:05 +00:00
|
|
|
|
future: _future,
|
|
|
|
|
onRefresh: () async {},
|
|
|
|
|
successBuilder:
|
|
|
|
|
(BuildContext context, AsyncSnapshot<dynamic> snapshot) {
|
|
|
|
|
switch (_migrate) {
|
|
|
|
|
case 0:
|
2023-05-08 09:57:28 +00:00
|
|
|
|
return PikaListView(
|
2021-10-18 09:31:05 +00:00
|
|
|
|
children: [
|
|
|
|
|
Container(
|
2022-03-19 04:12:27 +00:00
|
|
|
|
padding: const EdgeInsets.all(10),
|
|
|
|
|
child: const Text(
|
2021-10-18 09:31:05 +00:00
|
|
|
|
"1. 为了手机数据存储空间不足, 且具有内存卡的安卓手机设计, 可将数据迁移到内存卡上。\n\n"
|
|
|
|
|
"2. 您在迁移之前, 请确保您的下载处于暂停状态, 或下载均已完成, 以保证您的数据完整性。\n\n"
|
|
|
|
|
"3. 如果迁移中断, 迁移失败, 或其他原因导致程序无法启动, 图片失效等问题, 您可在程序管理中清除本应用程序的数据, 以回复正常使用。\n\n"
|
|
|
|
|
"4. 如果您将数据迁移后将内存卡取出, 将会使用默认本地存储, 再次插入同一张内存卡会继续使用该储存卡, 不支持更换内存卡, 途中您若再次迁移会发生数据覆盖, 这必然会丢失一部分数据.\n\n"
|
|
|
|
|
"5. 您不能更改, 删除, 移动这些数据, 否则程序可能不能正常执行\n\n"
|
|
|
|
|
"6. 迁移成功之前一定不要退出应用程序, 也不要按返回键\n\n"
|
|
|
|
|
"7. 如果您已经了解此功能, 悉知文件迁移的风险, 可以在下面的按钮中选择一项执行\n\n",
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Container(
|
2022-03-19 04:12:27 +00:00
|
|
|
|
padding: const EdgeInsets.all(10),
|
2021-10-18 09:31:05 +00:00
|
|
|
|
child: Text("当前文件储存路径 : $_current"),
|
|
|
|
|
),
|
|
|
|
|
...paths.map((e) => Container(
|
2022-03-19 04:12:27 +00:00
|
|
|
|
padding: const EdgeInsets.all(10),
|
2021-10-18 09:31:05 +00:00
|
|
|
|
child: MaterialButton(
|
2022-04-17 05:48:09 +00:00
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
|
|
|
textColor:
|
|
|
|
|
Theme.of(context).textTheme.bodyText1?.color,
|
2022-03-19 04:12:27 +00:00
|
|
|
|
padding: const EdgeInsets.all(10),
|
2021-10-18 09:31:05 +00:00
|
|
|
|
onPressed: () async {
|
|
|
|
|
if (!await confirmDialog(context, "文件迁移",
|
|
|
|
|
"您将要迁移到$e, 迁移过程中一定《 不 要 关 闭 程 序 》")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setState(() {
|
|
|
|
|
_migrate = 1;
|
|
|
|
|
});
|
|
|
|
|
try {
|
|
|
|
|
await method.migrate(e);
|
|
|
|
|
setState(() {
|
|
|
|
|
_migrate = 2;
|
|
|
|
|
});
|
|
|
|
|
} catch (ex, tr) {
|
|
|
|
|
_message = "$ex\n$tr\n";
|
|
|
|
|
setState(() {
|
|
|
|
|
_migrate = 3;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
child: Text("迁移到 $e"),
|
|
|
|
|
),
|
|
|
|
|
)),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
case 1:
|
2022-03-19 04:12:27 +00:00
|
|
|
|
return const ContentLoading(label: "迁移中");
|
2021-10-18 09:31:05 +00:00
|
|
|
|
case 2:
|
2022-03-19 04:12:27 +00:00
|
|
|
|
return const Center(child: Text("迁移成功 您需要关闭应用程序重新启动"));
|
2021-10-18 09:31:05 +00:00
|
|
|
|
case 3:
|
|
|
|
|
return Center(child: Text("迁移失败\n$_message"));
|
|
|
|
|
default:
|
|
|
|
|
throw "";
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|