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 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'app_updates.dart';
|
import 'app_updates.dart';
|
||||||
@@ -10,113 +9,60 @@ Future<bool?> showLaunchUpdateDialog(
|
|||||||
required bool cupertino,
|
required bool cupertino,
|
||||||
String sourceName = '',
|
String sourceName = '',
|
||||||
String nativePlatform = 'android',
|
String nativePlatform = 'android',
|
||||||
}) => cupertino
|
}) => showDialog<bool>(
|
||||||
? showCupertinoDialog<bool>(
|
context: context,
|
||||||
context: context,
|
builder: (context) => AlertDialog(
|
||||||
builder: (context) => CupertinoAlertDialog(
|
title: const Text('Update available'),
|
||||||
title: const Text('Update available'),
|
content: Text(
|
||||||
content: Text(
|
web
|
||||||
web
|
? 'A newer Pipelines web build is available.'
|
||||||
? 'A newer Pipelines web build is available.'
|
: 'A newer ${nativePlatform == 'macos'
|
||||||
: 'A newer ${nativePlatform == 'macos'
|
? 'macOS'
|
||||||
? 'macOS'
|
: nativePlatform == 'linux'
|
||||||
: nativePlatform == 'linux'
|
? 'Linux'
|
||||||
? 'Linux'
|
: 'Android'} build is available${sourceName.isEmpty ? '' : ' from $sourceName'}.${switch (nativePlatform) {
|
||||||
: 'Android'} build is available${sourceName.isEmpty ? '' : ' from $sourceName'}.${switch (nativePlatform) {
|
'linux' => ' Pipelines installs it and restarts.',
|
||||||
'linux' => ' Pipelines installs it and restarts.',
|
'macos' => ' Download and extract the archive to update the app.',
|
||||||
'macos' => ' Download and extract the archive to update the app.',
|
_ => '',
|
||||||
_ => '',
|
}}',
|
||||||
}}',
|
),
|
||||||
),
|
actions: [
|
||||||
actions: [
|
TextButton(
|
||||||
CupertinoDialogAction(
|
onPressed: () => Navigator.pop(context, false),
|
||||||
onPressed: () => Navigator.pop(context, false),
|
child: const Text('Later'),
|
||||||
child: const Text('Later'),
|
),
|
||||||
),
|
FilledButton(
|
||||||
CupertinoDialogAction(
|
onPressed: () => Navigator.pop(context, true),
|
||||||
isDefaultAction: true,
|
child: Text(
|
||||||
onPressed: () => Navigator.pop(context, true),
|
web
|
||||||
child: Text(
|
? 'Refresh'
|
||||||
web
|
: nativePlatform == 'linux'
|
||||||
? 'Refresh'
|
? 'Install and restart'
|
||||||
: nativePlatform == 'linux'
|
: 'Download',
|
||||||
? '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(
|
Future<void> showLaunchUpdateFailure(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
Object error, {
|
Object error, {
|
||||||
required bool cupertino,
|
required bool cupertino,
|
||||||
}) async {
|
}) async {
|
||||||
if (cupertino) {
|
await showDialog<void>(
|
||||||
await showCupertinoDialog<void>(
|
context: context,
|
||||||
context: context,
|
builder: (context) => AlertDialog(
|
||||||
builder: (context) => CupertinoAlertDialog(
|
title: const Text('Update failed'),
|
||||||
title: const Text('Update failed'),
|
content: Text('$error'),
|
||||||
content: Text('$error'),
|
actions: [
|
||||||
actions: [
|
TextButton(
|
||||||
CupertinoDialogAction(
|
onPressed: () => Navigator.pop(context),
|
||||||
onPressed: () => Navigator.pop(context),
|
child: const Text('OK'),
|
||||||
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'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reuses the Settings installer while keeping download progress visible.
|
/// Reuses the Settings installer while keeping download progress visible.
|
||||||
@@ -126,24 +72,11 @@ Future<void> installLaunchUpdate(
|
|||||||
required UpdateInstaller installer,
|
required UpdateInstaller installer,
|
||||||
required bool cupertino,
|
required bool cupertino,
|
||||||
}) async {
|
}) async {
|
||||||
final result = cupertino
|
final result = await showDialog<_InstallResult>(
|
||||||
? await showCupertinoDialog<_InstallResult>(
|
context: context,
|
||||||
context: context,
|
barrierDismissible: false,
|
||||||
builder: (_) => _InstallProgress(
|
builder: (_) => _InstallProgress(update: update, installer: installer),
|
||||||
update: update,
|
);
|
||||||
installer: installer,
|
|
||||||
cupertino: true,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: await showDialog<_InstallResult>(
|
|
||||||
context: context,
|
|
||||||
barrierDismissible: false,
|
|
||||||
builder: (_) => _InstallProgress(
|
|
||||||
update: update,
|
|
||||||
installer: installer,
|
|
||||||
cupertino: false,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if (result?.error case final Object error) throw error;
|
if (result?.error case final Object error) throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,14 +86,9 @@ class _InstallResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _InstallProgress extends StatefulWidget {
|
class _InstallProgress extends StatefulWidget {
|
||||||
const _InstallProgress({
|
const _InstallProgress({required this.update, required this.installer});
|
||||||
required this.update,
|
|
||||||
required this.installer,
|
|
||||||
required this.cupertino,
|
|
||||||
});
|
|
||||||
final AppUpdate update;
|
final AppUpdate update;
|
||||||
final UpdateInstaller installer;
|
final UpdateInstaller installer;
|
||||||
final bool cupertino;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<_InstallProgress> createState() => _InstallProgressState();
|
State<_InstallProgress> createState() => _InstallProgressState();
|
||||||
@@ -200,19 +128,12 @@ class _InstallProgressState extends State<_InstallProgress> {
|
|||||||
: 'Downloading update… ${(progress * 100).round()}%',
|
: 'Downloading update… ${(progress * 100).round()}%',
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
widget.cupertino
|
LinearProgressIndicator(value: progress),
|
||||||
? const CupertinoActivityIndicator()
|
|
||||||
: LinearProgressIndicator(value: progress),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
return PopScope(
|
return PopScope(
|
||||||
canPop: false,
|
canPop: false,
|
||||||
child: widget.cupertino
|
child: AlertDialog(title: const Text('App update'), content: content),
|
||||||
? CupertinoAlertDialog(
|
|
||||||
title: const Text('App update'),
|
|
||||||
content: content,
|
|
||||||
)
|
|
||||||
: AlertDialog(title: const Text('App update'), content: content),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
# Cupertino removal — lib/features/updates
|
||||||
|
|
||||||
|
## Change
|
||||||
|
- `lib/features/updates/launch_update_dialog.dart`: deleted the Cupertino dialog
|
||||||
|
branches from `showLaunchUpdateDialog`, `showLaunchUpdateFailure` and
|
||||||
|
`installLaunchUpdate`, and from the private `_InstallProgress` widget
|
||||||
|
(`CupertinoAlertDialog`, `CupertinoActivityIndicator`, `CupertinoDialogAction`,
|
||||||
|
`showCupertinoDialog`). The Material `AlertDialog`/`LinearProgressIndicator`
|
||||||
|
path is unchanged.
|
||||||
|
- Public signatures keep `required bool cupertino` (unused now) so callers in
|
||||||
|
other directories continue to compile; nothing outside `lib/features/updates`
|
||||||
|
was edited.
|
||||||
|
- Removed the `package:flutter/cupertino.dart` import; no `CupertinoIcons` or
|
||||||
|
`CupertinoColors` were used in this directory.
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
- `test/features/updates/native_update_dialog_test.dart`: existing Material
|
||||||
|
prompt loop retained (`cupertino: false`). Added regression tests for the
|
||||||
|
Material failure alert and the Material install-progress dialog/progress bar.
|
||||||
|
No Cupertino test variants were present to delete.
|
||||||
|
- `test/application/startup_update_flow_test.dart` (review follow-up): the web
|
||||||
|
refresh test no longer mounts with `cupertino: true`; it now asserts the
|
||||||
|
Material `AlertDialog`. The local `mount` helper lost its unused `cupertino`
|
||||||
|
parameter and passes `cupertino: false` explicitly. The
|
||||||
|
`package:flutter/cupertino.dart` import became `package:flutter/material.dart`.
|
||||||
|
- `test/application/startup_update_check_test.dart` already mounted Material
|
||||||
|
only (`cupertino: false`); no change.
|
||||||
|
- No other test reaches these dialogs with `cupertino: true` or a `CupertinoApp`
|
||||||
|
host; the remaining `cupertino: true` tests elsewhere cover unrelated UI.
|
||||||
|
|
||||||
|
## Checks
|
||||||
|
- `tool/analyze.sh`: clean (16s, exit 0).
|
||||||
|
- `tool/memwatch/full.sh 'test/features/updates test/application/startup_update_flow_test.dart test/application/startup_update_check_test.dart'`:
|
||||||
|
38 passed, 0 failed, 0 skipped; 38s; exit 0.
|
||||||
|
- `grep -rn 'Cupertino\|cupertino' lib/features/updates`: only the three kept
|
||||||
|
`required bool cupertino` parameters. In the update tests only `cupertino:
|
||||||
|
false` arguments remain.
|
||||||
|
|
||||||
|
## UI states
|
||||||
|
- Update-available prompt, update-failure alert and install-progress dialog now
|
||||||
|
always render the existing Material variants. No pixel change on the Material
|
||||||
|
path; Cupertino host paths are unreachable in this Material-only app.
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:pipelines_app/application/pipelines_app.dart';
|
import 'package:pipelines_app/application/pipelines_app.dart';
|
||||||
import 'package:pipelines_app/application/server_endpoint.dart';
|
import 'package:pipelines_app/application/server_endpoint.dart';
|
||||||
@@ -14,7 +14,6 @@ void main() {
|
|||||||
Future<void> mount(
|
Future<void> mount(
|
||||||
WidgetTester tester, {
|
WidgetTester tester, {
|
||||||
bool web = true,
|
bool web = true,
|
||||||
bool cupertino = false,
|
|
||||||
Future<String?> Function(Uri)? read,
|
Future<String?> Function(Uri)? read,
|
||||||
Future<void> Function()? refresh,
|
Future<void> Function()? refresh,
|
||||||
UpdateInstaller? installer,
|
UpdateInstaller? installer,
|
||||||
@@ -31,7 +30,7 @@ void main() {
|
|||||||
web: true,
|
web: true,
|
||||||
),
|
),
|
||||||
client: PipelinesClient(channelFactory: (_) => channel),
|
client: PipelinesClient(channelFactory: (_) => channel),
|
||||||
cupertino: cupertino,
|
cupertino: false,
|
||||||
routeInformationProvider: provider,
|
routeInformationProvider: provider,
|
||||||
webPlatform: web,
|
webPlatform: web,
|
||||||
webPageUri: Uri.parse('https://app.test/chats?selected=1'),
|
webPageUri: Uri.parse('https://app.test/chats?selected=1'),
|
||||||
@@ -180,7 +179,6 @@ void main() {
|
|||||||
var refreshes = 0;
|
var refreshes = 0;
|
||||||
await mount(
|
await mount(
|
||||||
tester,
|
tester,
|
||||||
cupertino: true,
|
|
||||||
read: (uri) async {
|
read: (uri) async {
|
||||||
expect(uri, Uri.parse('https://app.test/release.json'));
|
expect(uri, Uri.parse('https://app.test/release.json'));
|
||||||
return '{"schema":1,"platform":"web","buildId":"web-new"}';
|
return '{"schema":1,"platform":"web","buildId":"web-new"}';
|
||||||
@@ -189,7 +187,7 @@ void main() {
|
|||||||
refreshes++;
|
refreshes++;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
|
expect(find.byType(AlertDialog), findsOneWidget);
|
||||||
expect(refreshes, 0);
|
expect(refreshes, 0);
|
||||||
await tester.tap(find.text('Refresh'));
|
await tester.tap(find.text('Refresh'));
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pipelines_app/features/updates/app_updates.dart';
|
||||||
import 'package:pipelines_app/features/updates/launch_update_dialog.dart';
|
import 'package:pipelines_app/features/updates/launch_update_dialog.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
@@ -34,4 +37,63 @@ void main() {
|
|||||||
expect(find.textContaining('Android'), findsNothing);
|
expect(find.textContaining('Android'), findsNothing);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testWidgets('update failure uses a Material alert', (tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: Builder(
|
||||||
|
builder: (context) => TextButton(
|
||||||
|
onPressed: () =>
|
||||||
|
showLaunchUpdateFailure(context, 'boom', cupertino: false),
|
||||||
|
child: const Text('Fail'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.tap(find.text('Fail'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.byType(AlertDialog), findsOneWidget);
|
||||||
|
expect(find.text('Update failed'), findsOneWidget);
|
||||||
|
expect(find.text('boom'), findsOneWidget);
|
||||||
|
expect(find.text('OK'), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('install progress uses a Material alert and progress bar', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
final finished = Completer<void>();
|
||||||
|
late BuildContext dialogContext;
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: Builder(
|
||||||
|
builder: (context) {
|
||||||
|
dialogContext = context;
|
||||||
|
return const SizedBox();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final install = installLaunchUpdate(
|
||||||
|
dialogContext,
|
||||||
|
AppUpdate(
|
||||||
|
versionCode: 2,
|
||||||
|
versionName: '2.0',
|
||||||
|
apk: Uri.parse('https://example.test/app.apk'),
|
||||||
|
),
|
||||||
|
installer: (update, {onProgress}) async {
|
||||||
|
onProgress?.call(0.5);
|
||||||
|
await finished.future;
|
||||||
|
},
|
||||||
|
cupertino: false,
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.byType(AlertDialog), findsOneWidget);
|
||||||
|
expect(find.byType(LinearProgressIndicator), findsOneWidget);
|
||||||
|
expect(find.text('App update'), findsOneWidget);
|
||||||
|
expect(find.text('Downloading update… 50%'), findsOneWidget);
|
||||||
|
finished.complete();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.byType(AlertDialog), findsNothing);
|
||||||
|
await install;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user