feat: fix debug updater

This commit is contained in:
2026-07-30 04:46:03 +02:00
parent 715aa529d4
commit 217be08231
9 changed files with 616 additions and 91 deletions
+106 -17
View File
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
import '../utils/app_update_util.dart';
import '../viewmodels/dev_menu_view_model.dart';
class DevMenuView extends StatefulWidget {
@@ -128,9 +129,9 @@ class _DevMenuViewState extends State<DevMenuView> {
children: [
_Tile(
icon: Icons.update_rounded,
title: 'Mock update available',
subtitle: 'Simulate OTA update dialog',
onTap: () => _showMockUpdateDialog(),
title: 'Simulate update download',
subtitle: 'Open the download progress screen',
onTap: () => _showSimulateUpdateDialog(),
),
],
),
@@ -209,28 +210,66 @@ class _DevMenuViewState extends State<DevMenuView> {
);
}
void _showMockUpdateDialog() {
void _showSimulateUpdateDialog() {
final fakeUpdate = UpdateInfo(
update: true,
version: '99.0.0',
notes: 'Bug fixes and performance improvements.',
mandatory: false,
sha256: 'abc123',
download: 'https://example.com/fake-update.apk',
);
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Update available'),
content: const Column(
builder: (dialogContext) => AlertDialog(
title: const Text('Simulate update'),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Version 99.0.0 is available.'),
SizedBox(height: 12),
Text('Bug fixes and performance improvements.'),
const Text('Choose a simulation mode:'),
const SizedBox(height: 16),
_SimOption(
icon: Icons.download_rounded,
label: 'Successful download',
description: 'Progress 0→100%, then install, then done',
onTap: () {
Navigator.pop(dialogContext);
context.push(
'/update-progress?simulate=true',
extra: fakeUpdate,
);
},
),
const SizedBox(height: 8),
_SimOption(
icon: Icons.error_outline_rounded,
label: 'Download error',
description: 'Fails at 50% with a network timeout',
onTap: () {
Navigator.pop(dialogContext);
context.push(
'/update-progress?simulate=true&simulateError=true',
extra: fakeUpdate,
);
},
),
const SizedBox(height: 8),
_SimOption(
icon: Icons.wifi_off_rounded,
label: 'Real download (will fail)',
description: 'Attempts real OTA with fake URL',
onTap: () {
Navigator.pop(dialogContext);
context.push('/update-progress', extra: fakeUpdate);
},
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Later'),
),
FilledButton(
onPressed: () => Navigator.pop(context),
child: const Text('Update'),
onPressed: () => Navigator.pop(dialogContext),
child: const Text('Cancel'),
),
],
),
@@ -238,6 +277,56 @@ class _DevMenuViewState extends State<DevMenuView> {
}
}
class _SimOption extends StatelessWidget {
final IconData icon;
final String label;
final String description;
final VoidCallback onTap;
const _SimOption({
required this.icon,
required this.label,
required this.description,
required this.onTap,
});
@override
Widget build(BuildContext context) {
return Material(
color: Theme.of(context).colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(12),
child: InkWell(
borderRadius: BorderRadius.circular(12),
onTap: onTap,
child: Padding(
padding: const EdgeInsets.all(12),
child: Row(
children: [
Icon(icon, size: 28),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label, style: Theme.of(context).textTheme.titleSmall),
Text(
description,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.6),
),
),
],
),
),
const Icon(Icons.chevron_right_rounded),
],
),
),
),
);
}
}
class _Section extends StatelessWidget {
final String title;
final List<Widget> children;