pikapika/lib/screens/MigrateScreen.dart

120 lines
4.8 KiB
Dart
Raw Normal View History

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
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-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
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(
future: _future,
onRefresh: () async {},
successBuilder:
(BuildContext context, AsyncSnapshot<dynamic> snapshot) {
switch (_migrate) {
case 0:
return ListView(
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(
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 "";
}
},
),
);
}
}