修复版本管理整包更新无法弹出的问题
完成集成新的登录接口的更换使用 完成集成用户的场站列表接口 完成开发设计选择场站项为全局属性 完成我的页面的个人信息的集成和详情页面的开发 完成设备页面的中无人机机场的列表接口对接入和个项页面的布局的优化 完成设备页面的中无人机机场的详情接口的对接和使用和页面的更新布局
This commit is contained in:
216
lib/main.dart
216
lib/main.dart
@@ -41,6 +41,11 @@ void main() async {
|
||||
final logger = sl<ILoggerService>();
|
||||
await logger.init();
|
||||
Bloc.observer = AppBlocObserver(logger);
|
||||
|
||||
// ⚠️ 注意:不要在启动时清除补丁版本记录!
|
||||
// 补丁版本记录只在整包更新成功后才清除
|
||||
// 如果在启动时清除,会导致差量更新后划掉App再进入时循环更新
|
||||
|
||||
runApp(const MyApp());
|
||||
},
|
||||
(error, stack) {
|
||||
@@ -203,6 +208,33 @@ class _UpdateCheckerState extends State<_UpdateChecker> {
|
||||
Text(state.versionInfo.updateDesc),
|
||||
],
|
||||
const SizedBox(height: 20),
|
||||
if (state.versionInfo.updateType != 'patch') ...[
|
||||
// 🔥 整包更新:显示两个选项
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue.shade50,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: Colors.blue.shade200),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'💡 选择下载方式',
|
||||
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
'• 自动安装:App 内下载并调起系统安装\n'
|
||||
'• 手动下载:在浏览器中下载安装',
|
||||
style: TextStyle(fontSize: 13, height: 1.5),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
@@ -212,24 +244,44 @@ class _UpdateCheckerState extends State<_UpdateChecker> {
|
||||
child: const Text('稍后'),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
final info = state.versionInfo;
|
||||
if (info.patchUrl != null) {
|
||||
// 🔥 执行差量更新
|
||||
context.read<UpdateCubit>().applyPatch(
|
||||
info.patchUrl!,
|
||||
info.version,
|
||||
info.versionCode,
|
||||
md5: info.patchMd5,
|
||||
);
|
||||
} else if (info.apkUrl != null) {
|
||||
// 🔥 执行整包更新
|
||||
context.read<UpdateCubit>().downloadAndInstallApk(info.apkUrl!);
|
||||
}
|
||||
},
|
||||
child: const Text('立即更新'),
|
||||
),
|
||||
if (state.versionInfo.updateType == 'patch')
|
||||
// 🔥 差量更新:单个按钮
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
final info = state.versionInfo;
|
||||
if (info.patchUrl != null) {
|
||||
context.read<UpdateCubit>().applyPatch(
|
||||
info.patchUrl!,
|
||||
info.version,
|
||||
info.versionCode,
|
||||
md5: info.patchMd5,
|
||||
);
|
||||
}
|
||||
},
|
||||
child: const Text('立即更新'),
|
||||
)
|
||||
else ...[
|
||||
// 🔥 整包更新:两个按钮
|
||||
OutlinedButton(
|
||||
onPressed: () {
|
||||
final info = state.versionInfo;
|
||||
if (info.apkUrl != null) {
|
||||
context.read<UpdateCubit>().downloadAndInstallApk(info.apkUrl!);
|
||||
}
|
||||
},
|
||||
child: const Text('手动下载'),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
final info = state.versionInfo;
|
||||
if (info.apkUrl != null) {
|
||||
context.read<UpdateCubit>().downloadAndInstallApk(info.apkUrl!);
|
||||
}
|
||||
},
|
||||
child: const Text('自动安装'),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -239,8 +291,49 @@ class _UpdateCheckerState extends State<_UpdateChecker> {
|
||||
),
|
||||
),
|
||||
),
|
||||
// 🔥 下载/安装进度弹窗
|
||||
if (state is UpdateDownloading || state is UpdateInstalling)
|
||||
// 🔥 整包更新步骤引导弹窗
|
||||
if (state is UpdateInstalling && !(state.isPatch ?? false))
|
||||
Positioned.fill(
|
||||
child: Container(
|
||||
color: Colors.black.withOpacity(0.7),
|
||||
child: Center(
|
||||
child: Card(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 30),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'📱 整包更新步骤',
|
||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildStepItem(1, '在浏览器中下载 APK', true),
|
||||
const SizedBox(height: 8),
|
||||
_buildStepItem(2, '手动安装下载的 APK', false),
|
||||
const SizedBox(height: 8),
|
||||
_buildStepItem(3, '清除旧版本记录', false),
|
||||
const SizedBox(height: 20),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
context.read<UpdateCubit>().cancelUpdate();
|
||||
},
|
||||
child: const Text('我知道了'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
// 🔥 下载进度显示(差量补丁和整包APK)
|
||||
if (state is UpdateDownloading)
|
||||
Positioned.fill(
|
||||
child: Container(
|
||||
color: Colors.black.withOpacity(0.7),
|
||||
@@ -252,31 +345,32 @@ class _UpdateCheckerState extends State<_UpdateChecker> {
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (state is UpdateDownloading)
|
||||
const Text('⬇️ 正在下载更新...',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
if (state is UpdateInstalling)
|
||||
const Text('🔧 正在应用更新...',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 16),
|
||||
if (state is UpdateDownloading)
|
||||
LinearProgressIndicator(
|
||||
value: state.progress,
|
||||
minHeight: 8,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
Text(
|
||||
state.isPatch ? '⬇️ 正在下载补丁...' : '⬇️ 正在下载 APK...',
|
||||
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
SizedBox(
|
||||
width: 80,
|
||||
height: 80,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(
|
||||
value: state.progress,
|
||||
strokeWidth: 5,
|
||||
),
|
||||
Text(
|
||||
'${(state.progress * 100).toInt()}%',
|
||||
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (state is UpdateDownloading)
|
||||
const SizedBox(height: 8),
|
||||
if (state is UpdateDownloading)
|
||||
Text('${(state.progress * 100).toInt()}%',
|
||||
style: const TextStyle(fontSize: 14, color: Colors.grey)),
|
||||
if (state is UpdateInstalling)
|
||||
const CircularProgressIndicator(),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
state is UpdateDownloading ? '请稍候,正在下载补丁文件' : '正在应用补丁,请勿关闭应用',
|
||||
style: const TextStyle(fontSize: 14, color: Colors.grey),
|
||||
textAlign: TextAlign.center,
|
||||
'请稍候...',
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey.shade600),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -358,4 +452,42 @@ class _UpdateCheckerState extends State<_UpdateChecker> {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建步骤项
|
||||
Widget _buildStepItem(int step, String text, bool completed) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 28,
|
||||
height: 28,
|
||||
decoration: BoxDecoration(
|
||||
color: completed ? Colors.green : Colors.grey.shade300,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'$step',
|
||||
style: TextStyle(
|
||||
color: completed ? Colors.white : Colors.black54,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
color: completed ? Colors.green : Colors.black87,
|
||||
decoration: completed ? TextDecoration.lineThrough : null,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (completed)
|
||||
const Icon(Icons.check, color: Colors.green, size: 20),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user