From 493e950195b79fdda09906050672619047ec3164 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Tue, 3 Nov 2026 16:07:48 +0000 Subject: [PATCH] App uses the Material host and controls on every platform iOS and macOS no longer switch to the Cupertino host or Cupertino controls by target platform; they render the same Material UI as web and Android. Cupertino paths remain for an explicit cupertino: true host. Flutter's automatic platform behaviours (scroll physics, text selection, back-swipe transitions) are unchanged. --- .../chat/ui/sessions/chat_adaptive.dart | 19 +++----- .../transcript/chat_attachment_thumbnail.dart | 2 +- .../pipelines/widgets/pipeline_controls.dart | 8 ++-- app/lib/features/search/search_screen.dart | 11 ++--- app/lib/features/settings/settings_theme.dart | 6 +-- app/lib/ui/adaptive/platform.dart | 16 +++---- ..._test.dart => chat_ios_material_test.dart} | 23 +++++----- ...settings_device_delivery_section_test.dart | 22 +++++----- .../settings/settings_layout_test.dart | 44 ++++++++++--------- .../settings/settings_ntfy_section_test.dart | 18 ++++---- .../settings/settings_screen_test.dart | 30 ++++++++++++- .../settings_shell_background_test.dart | 29 ++++++------ app/test/ui/adaptive/platform_test.dart | 41 ++++++++--------- 13 files changed, 139 insertions(+), 130 deletions(-) rename app/test/features/chat/ui/sessions/{chat_cupertino_theme_test.dart => chat_ios_material_test.dart} (70%) diff --git a/app/lib/features/chat/ui/sessions/chat_adaptive.dart b/app/lib/features/chat/ui/sessions/chat_adaptive.dart index 0a89e5ad..4402b55c 100644 --- a/app/lib/features/chat/ui/sessions/chat_adaptive.dart +++ b/app/lib/features/chat/ui/sessions/chat_adaptive.dart @@ -5,18 +5,13 @@ import 'package:flutter/material.dart'; /// Which standard control family this screen renders. enum ChatControlsStyle { material, cupertino } -/// Cupertino under a Cupertino app or an iOS/macOS Material theme, Material -/// everywhere else. The shell decides the app class, so a bare Cupertino app -/// never has to grow a Material ancestor just for this screen. -ChatControlsStyle chatControlsStyleOf(BuildContext context) { - if (context.findAncestorWidgetOfExactType() == null) { - return ChatControlsStyle.cupertino; - } - final platform = Theme.of(context).platform; - return platform == TargetPlatform.iOS || platform == TargetPlatform.macOS - ? ChatControlsStyle.cupertino - : ChatControlsStyle.material; -} +/// Cupertino under an explicit Cupertino app, Material everywhere else, +/// whatever the target platform. The shell decides the app class, so a bare +/// Cupertino app never has to grow a Material ancestor just for this screen. +ChatControlsStyle chatControlsStyleOf(BuildContext context) => + context.findAncestorWidgetOfExactType() == null + ? ChatControlsStyle.cupertino + : ChatControlsStyle.material; class ChatBarAction extends StatelessWidget { const ChatBarAction({ diff --git a/app/lib/features/chat/ui/transcript/chat_attachment_thumbnail.dart b/app/lib/features/chat/ui/transcript/chat_attachment_thumbnail.dart index 7e4c91ca..2a83199e 100644 --- a/app/lib/features/chat/ui/transcript/chat_attachment_thumbnail.dart +++ b/app/lib/features/chat/ui/transcript/chat_attachment_thumbnail.dart @@ -100,7 +100,7 @@ class _ChatAttachmentThumbnailState extends State { child: Center( child: widget.cupertino ? const CupertinoActivityIndicator() - : const CircularProgressIndicator.adaptive(), + : const CircularProgressIndicator(), ), ); diff --git a/app/lib/features/pipelines/widgets/pipeline_controls.dart b/app/lib/features/pipelines/widgets/pipeline_controls.dart index 550ecdc8..3dee4153 100644 --- a/app/lib/features/pipelines/widgets/pipeline_controls.dart +++ b/app/lib/features/pipelines/widgets/pipeline_controls.dart @@ -6,11 +6,9 @@ import '../../../ui/adaptive/segmented_bar.dart'; import '../pipeline_query.dart'; -/// The one platform decision for this feature. The screen itself receives no -/// platform flag, so tests and integration obey Flutter's target platform. -bool useCupertinoControls(BuildContext context) => - usesCupertinoHost(context) || - Theme.of(context).platform == TargetPlatform.iOS; +/// The one control-family decision for this feature: Cupertino only under an +/// explicit Cupertino host, Material on every platform otherwise. +bool useCupertinoControls(BuildContext context) => usesCupertinoHost(context); /// Standard platform activity indicator with an accessible status label. class PipelineProgress extends StatelessWidget { diff --git a/app/lib/features/search/search_screen.dart b/app/lib/features/search/search_screen.dart index cff61b14..a57de2ae 100644 --- a/app/lib/features/search/search_screen.dart +++ b/app/lib/features/search/search_screen.dart @@ -81,14 +81,9 @@ class _SearchScreenState extends State { @override Widget build(BuildContext context) { - // Follow the actual host app class first: a CupertinoApp supplies no - // Material theme, so reading only the platform would pick Material controls - // inside a Cupertino host on macOS/iOS. - final cupertino = - widget.cupertino ?? - (usesCupertinoHost(context) || - Theme.of(context).platform == TargetPlatform.iOS || - Theme.of(context).platform == TargetPlatform.macOS); + // Follow the actual host app class: Cupertino only under an explicit + // Cupertino host, Material on every platform otherwise. + final cupertino = widget.cupertino ?? usesCupertinoHost(context); if (widget.embedded) { // The shell's bar carries the controls; without a shell (a bare embed) // they lead the results instead. diff --git a/app/lib/features/settings/settings_theme.dart b/app/lib/features/settings/settings_theme.dart index 75868479..7553cb16 100644 --- a/app/lib/features/settings/settings_theme.dart +++ b/app/lib/features/settings/settings_theme.dart @@ -3,9 +3,9 @@ import 'package:flutter/material.dart'; import '../../ui/adaptive/host.dart'; -bool usesCupertinoControls(BuildContext context) => - usesCupertinoHost(context) || - Theme.of(context).platform == TargetPlatform.iOS; +/// Cupertino only under an explicit Cupertino host; Material on every +/// platform otherwise. +bool usesCupertinoControls(BuildContext context) => usesCupertinoHost(context); Color settingsErrorColor(BuildContext context) => usesCupertinoControls(context) ? CupertinoColors.destructiveRed.resolveFrom(context) diff --git a/app/lib/ui/adaptive/platform.dart b/app/lib/ui/adaptive/platform.dart index c1a29a18..82dda1e2 100644 --- a/app/lib/ui/adaptive/platform.dart +++ b/app/lib/ui/adaptive/platform.dart @@ -1,8 +1,8 @@ -import 'package:flutter/foundation.dart'; - -/// Browsers use Material consistently, regardless of their host OS. -bool prefersCupertino({bool web = kIsWeb, TargetPlatform? platform}) { - final target = platform ?? defaultTargetPlatform; - return !web && - (target == TargetPlatform.iOS || target == TargetPlatform.macOS); -} +/// The app renders the same Material layout and design on every platform: +/// web, Android, iOS and macOS. The Cupertino host and controls remain +/// available only when a caller asks for them explicitly (`cupertino: true`); +/// they are never chosen from the target platform. +/// +/// Flutter's automatic platform behaviours (scroll physics, text selection, +/// page transitions and back-swipe) still follow the target platform. +bool prefersCupertino() => false; diff --git a/app/test/features/chat/ui/sessions/chat_cupertino_theme_test.dart b/app/test/features/chat/ui/sessions/chat_ios_material_test.dart similarity index 70% rename from app/test/features/chat/ui/sessions/chat_cupertino_theme_test.dart rename to app/test/features/chat/ui/sessions/chat_ios_material_test.dart index d2f01eae..6deafedb 100644 --- a/app/test/features/chat/ui/sessions/chat_cupertino_theme_test.dart +++ b/app/test/features/chat/ui/sessions/chat_ios_material_test.dart @@ -6,25 +6,25 @@ import 'package:flutter_test/flutter_test.dart'; import 'chat_test_harness.dart'; import 'fake_chat_gateway.dart'; -/// The message card is also mounted under a bare `MaterialApp` (the screen's -/// iOS/macOS path). Without its own style, `Text` inherits MaterialApp's -/// "missing Material" fallback: 48px, red, monospace with a double underline. +/// iOS and macOS run the same Material app as web and Android, so the chat +/// list under an iOS `MaterialApp` renders the Material screen and controls, +/// with ordinary text rather than the "missing Material" fallback style. void main() { - testWidgets('Cupertino empty message under MaterialApp uses normal text', ( + testWidgets('iOS empty message under MaterialApp is the Material screen', ( tester, ) async { usePhoneSurface(tester); await pumpIosMaterialChat(tester, FakeChatGateway()); - expect(find.byType(CupertinoPageScaffold), findsOneWidget); - expect(find.byType(Scaffold), findsNothing); + expect(find.byType(Scaffold), findsWidgets); + expect(find.byType(CupertinoPageScaffold), findsNothing); const message = 'No chat sessions on this server yet.'; expect(find.text(message), findsOneWidget); expectNormalTextStyle(tester, message); }); - testWidgets('Cupertino load error under MaterialApp uses normal text', ( + testWidgets('iOS load error under MaterialApp uses Material controls', ( tester, ) async { usePhoneSurface(tester); @@ -42,18 +42,19 @@ void main() { expect(find.text(message), findsOneWidget); expectNormalTextStyle(tester, message); expect(find.text('No chat sessions on this server yet.'), findsNothing); - expect(find.widgetWithText(CupertinoButton, 'Retry'), findsOneWidget); + expect(find.widgetWithText(CupertinoButton, 'Retry'), findsNothing); + expect(find.text('Retry'), findsOneWidget); }); } -/// Resolves the style actually painted for [message] and checks it is the -/// ordinary Cupertino body style rather than MaterialApp's fallback style. +/// Resolves the style actually painted for [message] and checks it is not +/// MaterialApp's "missing Material" fallback style. void expectNormalTextStyle(WidgetTester tester, String message) { final paragraph = tester.renderObject(find.text(message)); final style = paragraph.text.style!; expect( style.fontSize, - const CupertinoThemeData().textTheme.textStyle.fontSize, + isNot(48), reason: 'message should not use MaterialApp\'s 48px fallback style', ); expect(style.fontFamily, isNot('monospace')); diff --git a/app/test/features/settings/settings_device_delivery_section_test.dart b/app/test/features/settings/settings_device_delivery_section_test.dart index 1e22ade5..9b583ba8 100644 --- a/app/test/features/settings/settings_device_delivery_section_test.dart +++ b/app/test/features/settings/settings_device_delivery_section_test.dart @@ -10,19 +10,17 @@ Widget _host( NotificationServiceBridge bridge, { required bool cupertino, Future Function()? requestPermission, -}) => MaterialApp( - theme: ThemeData( - platform: cupertino ? TargetPlatform.iOS : TargetPlatform.android, - ), - home: Scaffold( - body: SingleChildScrollView( - child: SettingsDeviceDeliverySection( - bridge: bridge, - requestNotificationPermission: requestPermission, - ), +}) { + final body = SingleChildScrollView( + child: SettingsDeviceDeliverySection( + bridge: bridge, + requestNotificationPermission: requestPermission, ), - ), -); + ); + return cupertino + ? CupertinoApp(home: CupertinoPageScaffold(child: body)) + : MaterialApp(home: Scaffold(body: body)); +} bool _switchValue(WidgetTester tester, {required bool cupertino}) { final tile = find.byKey(DeviceDeliveryKeys.toggle); diff --git a/app/test/features/settings/settings_layout_test.dart b/app/test/features/settings/settings_layout_test.dart index 958c424d..41d8c47c 100644 --- a/app/test/features/settings/settings_layout_test.dart +++ b/app/test/features/settings/settings_layout_test.dart @@ -88,7 +88,7 @@ void main() { testWidgets('Cupertino uses inset-grouped sections on the grouped page', ( tester, ) async { - await _pump(tester, platform: TargetPlatform.iOS); + await _pump(tester, cupertino: true); expect(find.byType(Card), findsNothing); expect(find.byType(CupertinoListSection), findsWidgets); @@ -124,7 +124,7 @@ void main() { testWidgets('Cupertino keeps the compact secondary field label', ( tester, ) async { - await _pump(tester, platform: TargetPlatform.iOS); + await _pump(tester, cupertino: true); final label = tester.widget(find.text('Server URL')); final context = tester.element(find.text('Server URL')); @@ -191,7 +191,7 @@ void main() { Future _pump( WidgetTester tester, { - TargetPlatform platform = TargetPlatform.android, + bool cupertino = false, NotificationController? notifications, Size size = const Size(800, 1600), double topPadding = 0, @@ -201,24 +201,28 @@ Future _pump( final factory = FakeChannelFactory(); final client = transport.PipelinesClient(channelFactory: factory.call); addTearDown(client.dispose); + final screen = SettingsScreen( + client: client, + store: MemorySettingsStore(), + notifications: notifications, + embedded: true, + ); + Widget padded(BuildContext context, Widget? child) => MediaQuery( + data: MediaQuery.of( + context, + ).copyWith(padding: EdgeInsets.only(top: topPadding)), + child: child!, + ); await tester.pumpWidget( - MaterialApp( - theme: ThemeData(platform: platform), - builder: (context, child) => MediaQuery( - data: MediaQuery.of( - context, - ).copyWith(padding: EdgeInsets.only(top: topPadding)), - child: child!, - ), - home: Scaffold( - body: SettingsScreen( - client: client, - store: MemorySettingsStore(), - notifications: notifications, - embedded: true, - ), - ), - ), + cupertino + ? CupertinoApp( + builder: padded, + home: CupertinoPageScaffold(child: screen), + ) + : MaterialApp( + builder: padded, + home: Scaffold(body: screen), + ), ); await tester.pump(); await tester.pump(); diff --git a/app/test/features/settings/settings_ntfy_section_test.dart b/app/test/features/settings/settings_ntfy_section_test.dart index 294a692f..c73f4b89 100644 --- a/app/test/features/settings/settings_ntfy_section_test.dart +++ b/app/test/features/settings/settings_ntfy_section_test.dart @@ -33,16 +33,14 @@ JsonMap _reply(bool run, bool needs, bool reply) => { }, }; -Widget _host(ApiGateway gateway, {required bool cupertino}) => MaterialApp( - theme: ThemeData( - platform: cupertino ? TargetPlatform.iOS : TargetPlatform.android, - ), - home: Scaffold( - body: SingleChildScrollView( - child: SettingsNtfySection(gateway: gateway, connected: true), - ), - ), -); +Widget _host(ApiGateway gateway, {required bool cupertino}) { + final body = SingleChildScrollView( + child: SettingsNtfySection(gateway: gateway, connected: true), + ); + return cupertino + ? CupertinoApp(home: CupertinoPageScaffold(child: body)) + : MaterialApp(home: Scaffold(body: body)); +} bool _checked(WidgetTester tester, String key, {required bool cupertino}) { final tile = find.byKey(ntfySettingKey(key)); diff --git a/app/test/features/settings/settings_screen_test.dart b/app/test/features/settings/settings_screen_test.dart index a217a34f..b6971dd2 100644 --- a/app/test/features/settings/settings_screen_test.dart +++ b/app/test/features/settings/settings_screen_test.dart @@ -242,14 +242,26 @@ void main() { }, ); - testWidgets('iOS uses Cupertino fields, buttons and navigation', ( + testWidgets('iOS uses the same Material fields and buttons', (tester) async { + final factory = FakeChannelFactory(); + final client = transport.PipelinesClient(channelFactory: factory.call); + addTearDown(client.dispose); + + await _pump(tester, client, platform: TargetPlatform.iOS); + + expect(find.byType(CupertinoTextField), findsNothing); + expect(find.byType(TextField), findsWidgets); + expect(find.byKey(SettingsKeys.connect), findsOneWidget); + }); + + testWidgets('an explicit Cupertino host uses Cupertino fields and buttons', ( tester, ) async { final factory = FakeChannelFactory(); final client = transport.PipelinesClient(channelFactory: factory.call); addTearDown(client.dispose); - await _pump(tester, client, platform: TargetPlatform.iOS); + await _pump(tester, client, cupertino: true); expect(find.byType(SegmentedBar), findsOneWidget); expect(find.byType(CupertinoTextField), findsNWidgets(2)); @@ -354,11 +366,25 @@ Future _pump( transport.PipelinesClient client, { SettingsStore? store, TargetPlatform platform = TargetPlatform.android, + bool cupertino = false, double textScale = 1, Size size = const Size(800, 1200), }) async { await tester.binding.setSurfaceSize(size); addTearDown(() => tester.binding.setSurfaceSize(null)); + if (cupertino) { + await tester.pumpWidget( + CupertinoApp( + home: SettingsScreen( + client: client, + store: store ?? MemorySettingsStore(), + ), + ), + ); + await tester.pump(); + await tester.pump(); + return; + } await tester.pumpWidget( MaterialApp( theme: ThemeData(platform: platform), diff --git a/app/test/features/settings/settings_shell_background_test.dart b/app/test/features/settings/settings_shell_background_test.dart index 7c7c3a0a..41803d90 100644 --- a/app/test/features/settings/settings_shell_background_test.dart +++ b/app/test/features/settings/settings_shell_background_test.dart @@ -1,3 +1,4 @@ +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/transport/pipelines_client.dart' @@ -22,23 +23,19 @@ void main() { final factory = FakeChannelFactory(); final client = transport.PipelinesClient(channelFactory: factory.call); addTearDown(client.dispose); + final shell = AdaptiveShell( + cupertino: cupertino, + destination: AppDestination.settings, + destinationBodies: { + AppDestination.settings: (_) => SettingsScreen( + client: client, + store: MemorySettingsStore(), + embedded: true, + ), + }, + ); await tester.pumpWidget( - MaterialApp( - theme: ThemeData( - platform: cupertino ? TargetPlatform.iOS : TargetPlatform.android, - ), - home: AdaptiveShell( - cupertino: cupertino, - destination: AppDestination.settings, - destinationBodies: { - AppDestination.settings: (_) => SettingsScreen( - client: client, - store: MemorySettingsStore(), - embedded: true, - ), - }, - ), - ), + cupertino ? CupertinoApp(home: shell) : MaterialApp(home: shell), ); await tester.pump(); await tester.pump(); diff --git a/app/test/ui/adaptive/platform_test.dart b/app/test/ui/adaptive/platform_test.dart index 65f60fa7..ae18324f 100644 --- a/app/test/ui/adaptive/platform_test.dart +++ b/app/test/ui/adaptive/platform_test.dart @@ -7,35 +7,32 @@ import 'package:pipelines_app/ui/adaptive/platform.dart'; import 'package:pipelines_app/ui/theme/app_theme.dart'; void main() { - test('web uses Material on every host; native Apple uses Cupertino', () { - for (final platform in TargetPlatform.values) { - expect(prefersCupertino(web: true, platform: platform), isFalse); - expect( - prefersCupertino(web: false, platform: platform), - platform == TargetPlatform.iOS || platform == TargetPlatform.macOS, - ); - } + test('no platform prefers the Cupertino host', () { + expect(prefersCupertino(), isFalse); }); - for (final platform in [TargetPlatform.macOS, TargetPlatform.iOS]) { - testWidgets('app and themes select the right controls on $platform', ( - tester, - ) async { + for (final platform in TargetPlatform.values) { + testWidgets('the app uses the Material host on $platform', (tester) async { debugDefaultTargetPlatformOverride = platform; addTearDown(() => debugDefaultTargetPlatformOverride = null); await tester.pumpWidget(const MyApp()); - if (kIsWeb) { - expect(find.byType(MaterialApp), findsOneWidget); - expect(find.byType(CupertinoApp), findsNothing); - expect(appLightTheme().platform, TargetPlatform.android); - expect(appDarkTheme().platform, TargetPlatform.android); - } else { - expect(find.byType(CupertinoApp), findsOneWidget); - expect(appLightTheme().platform, platform); - expect(appDarkTheme().platform, platform); - } + expect(find.byType(MaterialApp), findsOneWidget); + expect(find.byType(CupertinoApp), findsNothing); + // Native hosts keep the target platform so Flutter's automatic + // behaviours (scroll physics, text selection, back-swipe) still apply. + final expected = kIsWeb ? TargetPlatform.android : platform; + expect(appLightTheme().platform, expected); + expect(appDarkTheme().platform, expected); await tester.pumpWidget(const SizedBox.shrink()); debugDefaultTargetPlatformOverride = null; }); } + + testWidgets('an explicit cupertino choice still builds the Cupertino host', ( + tester, + ) async { + await tester.pumpWidget(const MyApp(cupertino: true)); + expect(find.byType(CupertinoApp), findsOneWidget); + await tester.pumpWidget(const SizedBox.shrink()); + }); }