Remove Cupertino update dialog branches
Keep the Material update dialogs as the only reachable implementation while preserving public cupertino parameters for callers. Update focused tests and document the verified checks.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'app_updates.dart';
|
||||
@@ -10,113 +9,60 @@ Future<bool?> showLaunchUpdateDialog(
|
||||
required bool cupertino,
|
||||
String sourceName = '',
|
||||
String nativePlatform = 'android',
|
||||
}) => cupertino
|
||||
? showCupertinoDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => CupertinoAlertDialog(
|
||||
title: const Text('Update available'),
|
||||
content: Text(
|
||||
web
|
||||
? 'A newer Pipelines web build is available.'
|
||||
: 'A newer ${nativePlatform == 'macos'
|
||||
? 'macOS'
|
||||
: nativePlatform == 'linux'
|
||||
? 'Linux'
|
||||
: 'Android'} build is available${sourceName.isEmpty ? '' : ' from $sourceName'}.${switch (nativePlatform) {
|
||||
'linux' => ' Pipelines installs it and restarts.',
|
||||
'macos' => ' Download and extract the archive to update the app.',
|
||||
_ => '',
|
||||
}}',
|
||||
),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: const Text('Later'),
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
isDefaultAction: true,
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: Text(
|
||||
web
|
||||
? 'Refresh'
|
||||
: nativePlatform == 'linux'
|
||||
? 'Install and restart'
|
||||
: 'Download',
|
||||
),
|
||||
),
|
||||
],
|
||||
}) => showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Update available'),
|
||||
content: Text(
|
||||
web
|
||||
? 'A newer Pipelines web build is available.'
|
||||
: 'A newer ${nativePlatform == 'macos'
|
||||
? 'macOS'
|
||||
: nativePlatform == 'linux'
|
||||
? 'Linux'
|
||||
: 'Android'} build is available${sourceName.isEmpty ? '' : ' from $sourceName'}.${switch (nativePlatform) {
|
||||
'linux' => ' Pipelines installs it and restarts.',
|
||||
'macos' => ' Download and extract the archive to update the app.',
|
||||
_ => '',
|
||||
}}',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: const Text('Later'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: Text(
|
||||
web
|
||||
? 'Refresh'
|
||||
: nativePlatform == 'linux'
|
||||
? 'Install and restart'
|
||||
: 'Download',
|
||||
),
|
||||
)
|
||||
: showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Update available'),
|
||||
content: Text(
|
||||
web
|
||||
? 'A newer Pipelines web build is available.'
|
||||
: 'A newer ${nativePlatform == 'macos'
|
||||
? 'macOS'
|
||||
: nativePlatform == 'linux'
|
||||
? 'Linux'
|
||||
: 'Android'} build is available${sourceName.isEmpty ? '' : ' from $sourceName'}.${switch (nativePlatform) {
|
||||
'linux' => ' Pipelines installs it and restarts.',
|
||||
'macos' => ' Download and extract the archive to update the app.',
|
||||
_ => '',
|
||||
}}',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: const Text('Later'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: Text(
|
||||
web
|
||||
? 'Refresh'
|
||||
: nativePlatform == 'linux'
|
||||
? 'Install and restart'
|
||||
: 'Download',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Future<void> showLaunchUpdateFailure(
|
||||
BuildContext context,
|
||||
Object error, {
|
||||
required bool cupertino,
|
||||
}) async {
|
||||
if (cupertino) {
|
||||
await showCupertinoDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => CupertinoAlertDialog(
|
||||
title: const Text('Update failed'),
|
||||
content: Text('$error'),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Update failed'),
|
||||
content: Text('$error'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Update failed'),
|
||||
content: Text('$error'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Reuses the Settings installer while keeping download progress visible.
|
||||
@@ -126,24 +72,11 @@ Future<void> installLaunchUpdate(
|
||||
required UpdateInstaller installer,
|
||||
required bool cupertino,
|
||||
}) async {
|
||||
final result = cupertino
|
||||
? await showCupertinoDialog<_InstallResult>(
|
||||
context: context,
|
||||
builder: (_) => _InstallProgress(
|
||||
update: update,
|
||||
installer: installer,
|
||||
cupertino: true,
|
||||
),
|
||||
)
|
||||
: await showDialog<_InstallResult>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (_) => _InstallProgress(
|
||||
update: update,
|
||||
installer: installer,
|
||||
cupertino: false,
|
||||
),
|
||||
);
|
||||
final result = await showDialog<_InstallResult>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (_) => _InstallProgress(update: update, installer: installer),
|
||||
);
|
||||
if (result?.error case final Object error) throw error;
|
||||
}
|
||||
|
||||
@@ -153,14 +86,9 @@ class _InstallResult {
|
||||
}
|
||||
|
||||
class _InstallProgress extends StatefulWidget {
|
||||
const _InstallProgress({
|
||||
required this.update,
|
||||
required this.installer,
|
||||
required this.cupertino,
|
||||
});
|
||||
const _InstallProgress({required this.update, required this.installer});
|
||||
final AppUpdate update;
|
||||
final UpdateInstaller installer;
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
State<_InstallProgress> createState() => _InstallProgressState();
|
||||
@@ -200,19 +128,12 @@ class _InstallProgressState extends State<_InstallProgress> {
|
||||
: 'Downloading update… ${(progress * 100).round()}%',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
widget.cupertino
|
||||
? const CupertinoActivityIndicator()
|
||||
: LinearProgressIndicator(value: progress),
|
||||
LinearProgressIndicator(value: progress),
|
||||
],
|
||||
);
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
child: widget.cupertino
|
||||
? CupertinoAlertDialog(
|
||||
title: const Text('App update'),
|
||||
content: content,
|
||||
)
|
||||
: AlertDialog(title: const Text('App update'), content: content),
|
||||
child: AlertDialog(title: const Text('App update'), content: content),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user