Merge commit '03915fbb35c202d554d9e4cbc1549c0c4e62bdef' into pipelines/run-20261111-0431-cupertino-out-chat-shell-2721

This commit is contained in:
2026-11-11 04:42:43 +00:00
26 changed files with 144 additions and 589 deletions
+1 -7
View File
@@ -73,19 +73,13 @@ class _SchedulesScreenState extends State<SchedulesScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final cupertino =
Localizations.of<MaterialLocalizations>(
context,
MaterialLocalizations,
) ==
null;
return AnimatedBuilder( return AnimatedBuilder(
animation: _controller, animation: _controller,
builder: (context, _) => SchedulesListView( builder: (context, _) => SchedulesListView(
controller: _controller, controller: _controller,
searchController: _searchController, searchController: _searchController,
scrollController: _scrollController, scrollController: _scrollController,
cupertino: cupertino, cupertino: false,
onOpen: widget.onOpen, onOpen: widget.onOpen,
onRefresh: () => unawaited(_controller.refresh()), onRefresh: () => unawaited(_controller.refresh()),
), ),
@@ -1,29 +1,15 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../ui/adaptive/host.dart'; /// Secondary text under a field, using the app's colours and text theme.
/// Secondary text under a field, using the host's own colours and text theme.
TextStyle scheduleEditorSecondaryStyle(BuildContext context) { TextStyle scheduleEditorSecondaryStyle(BuildContext context) {
if (usesCupertinoHost(context)) {
// The host's own secondary-label style; no invented point size.
return CupertinoTheme.of(context).textTheme.tabLabelTextStyle.copyWith(
color: CupertinoColors.secondaryLabel.resolveFrom(context),
);
}
final theme = Theme.of(context); final theme = Theme.of(context);
return (theme.textTheme.bodySmall ?? const TextStyle()).copyWith( return (theme.textTheme.bodySmall ?? const TextStyle()).copyWith(
color: theme.colorScheme.onSurfaceVariant, color: theme.colorScheme.onSurfaceVariant,
); );
} }
/// The host's semantic error colour, never a form-specific palette. /// The app's semantic error colour, never a form-specific palette.
TextStyle scheduleEditorErrorStyle(BuildContext context) { TextStyle scheduleEditorErrorStyle(BuildContext context) {
if (usesCupertinoHost(context)) {
return CupertinoTheme.of(context).textTheme.textStyle.copyWith(
color: CupertinoColors.systemRed.resolveFrom(context),
);
}
return TextStyle(color: Theme.of(context).colorScheme.error); return TextStyle(color: Theme.of(context).colorScheme.error);
} }
@@ -47,9 +33,7 @@ class ScheduleEditorField extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final labelStyle = usesCupertinoHost(context) final labelStyle = Theme.of(context).textTheme.bodyMedium;
? CupertinoTheme.of(context).textTheme.textStyle
: Theme.of(context).textTheme.bodyMedium;
return Column( return Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
@@ -103,27 +87,16 @@ class ScheduleEditorTextField extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final field = usesCupertinoHost(context) final field = TextField(
? CupertinoTextField( key: fieldKey,
key: fieldKey, controller: controller,
controller: controller, enabled: enabled,
enabled: enabled, keyboardType: keyboardType,
keyboardType: keyboardType, minLines: minLines,
minLines: minLines, maxLines: maxLines,
maxLines: maxLines, textInputAction: textInputAction,
textInputAction: textInputAction, onChanged: onChanged,
onChanged: onChanged, );
)
: TextField(
key: fieldKey,
controller: controller,
enabled: enabled,
keyboardType: keyboardType,
minLines: minLines,
maxLines: maxLines,
textInputAction: textInputAction,
onChanged: onChanged,
);
return MergeSemantics( return MergeSemantics(
child: ScheduleEditorField( child: ScheduleEditorField(
label: label, label: label,
@@ -156,17 +129,11 @@ class ScheduleEditorSwitchField extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final control = usesCupertinoHost(context) final control = Switch(
? CupertinoSwitch( key: switchKey,
key: switchKey, value: value,
value: value, onChanged: enabled ? onChanged : null,
onChanged: enabled ? onChanged : null, );
)
: Switch(
key: switchKey,
value: value,
onChanged: enabled ? onChanged : null,
);
return MergeSemantics( return MergeSemantics(
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
@@ -1,8 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart'; import '../../../../core/api_gateway.dart';
import '../../../../ui/adaptive/host.dart';
import '../../domain/editor/schedule_draft.dart'; import '../../domain/editor/schedule_draft.dart';
import '../../domain/schedule_rule.dart'; import '../../domain/schedule_rule.dart';
import 'schedule_editor_form_body.dart'; import 'schedule_editor_form_body.dart';
@@ -151,7 +149,6 @@ class _ScheduleEditorFormState extends State<ScheduleEditorForm> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
return ScheduleEditorFormBody( return ScheduleEditorFormBody(
heading: _heading, heading: _heading,
showHeading: widget.showHeading, showHeading: widget.showHeading,
@@ -193,25 +190,17 @@ class _ScheduleEditorFormState extends State<ScheduleEditorForm> {
runSpacing: 8, runSpacing: 8,
children: [ children: [
if (widget.onCancel != null) if (widget.onCancel != null)
_cancelButton(cupertino) _cancelButton()
else else
const SizedBox.shrink(), const SizedBox.shrink(),
_saveButton(cupertino), _saveButton(),
], ],
), ),
); );
} }
Widget _cancelButton(bool cupertino) { Widget _cancelButton() {
final onPressed = _sending ? null : widget.onCancel; final onPressed = _sending ? null : widget.onCancel;
if (cupertino) {
return CupertinoButton(
key: scheduleEditorCancelKey,
padding: EdgeInsets.zero,
onPressed: onPressed,
child: const Text(scheduleEditorCancelLabel),
);
}
return TextButton( return TextButton(
key: scheduleEditorCancelKey, key: scheduleEditorCancelKey,
onPressed: onPressed, onPressed: onPressed,
@@ -219,18 +208,11 @@ class _ScheduleEditorFormState extends State<ScheduleEditorForm> {
); );
} }
Widget _saveButton(bool cupertino) { Widget _saveButton() {
final label = Text( final label = Text(
_sending ? scheduleEditorSendingLabel : scheduleEditorSubmitLabel, _sending ? scheduleEditorSendingLabel : scheduleEditorSubmitLabel,
); );
final onPressed = _sending ? null : _submit; final onPressed = _sending ? null : _submit;
if (cupertino) {
return CupertinoButton.filled(
key: scheduleEditorSubmitKey,
onPressed: onPressed,
child: label,
);
}
return FilledButton( return FilledButton(
key: scheduleEditorSubmitKey, key: scheduleEditorSubmitKey,
onPressed: onPressed, onPressed: onPressed,
@@ -1,7 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../ui/adaptive/host.dart';
import '../../domain/editor/schedule_draft.dart'; import '../../domain/editor/schedule_draft.dart';
import 'schedule_editor_fields.dart'; import 'schedule_editor_fields.dart';
import 'schedule_editor_selectors.dart'; import 'schedule_editor_selectors.dart';
@@ -100,10 +98,7 @@ class ScheduleEditorFormBody extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context); final titleStyle = Theme.of(context).textTheme.titleLarge;
final titleStyle = cupertino
? CupertinoTheme.of(context).textTheme.navLargeTitleTextStyle
: Theme.of(context).textTheme.titleLarge;
return Column( return Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
@@ -1,7 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../ui/adaptive/host.dart';
import '../../domain/schedule_rule.dart'; import '../../domain/schedule_rule.dart';
import 'schedule_editor_fields.dart'; import 'schedule_editor_fields.dart';
@@ -17,7 +15,7 @@ class ScheduleEditorChoice<T> {
final String label; final String label;
} }
/// A native drop-down on Material and a native action sheet on Cupertino. /// A native drop-down of the field's options.
class ScheduleEditorChoiceField<T> extends StatelessWidget { class ScheduleEditorChoiceField<T> extends StatelessWidget {
const ScheduleEditorChoiceField({ const ScheduleEditorChoiceField({
super.key, super.key,
@@ -40,65 +38,22 @@ class ScheduleEditorChoiceField<T> extends StatelessWidget {
final String? error; final String? error;
final Key? fieldKey; final Key? fieldKey;
String get _selectedLabel {
for (final option in options) {
if (option.value == value) return option.label;
}
return '';
}
Future<void> _choose(BuildContext context) async {
final chosen = await showCupertinoModalPopup<T>(
context: context,
builder: (sheetContext) => CupertinoActionSheet(
title: Text(label),
actions: [
for (final option in options)
CupertinoActionSheetAction(
onPressed: () => Navigator.pop(sheetContext, option.value),
child: Text(option.label),
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.pop(sheetContext),
child: const Text('Cancel'),
),
),
);
if (chosen != null) onChanged(chosen);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final control = usesCupertinoHost(context) final control = DropdownButtonFormField<T>(
? CupertinoButton( key: fieldKey,
key: fieldKey, initialValue: value,
padding: EdgeInsets.zero, isExpanded: true,
onPressed: enabled ? () => _choose(context) : null, items: [
child: Row( for (final option in options)
children: [ DropdownMenuItem<T>(value: option.value, child: Text(option.label)),
Expanded(child: Text(_selectedLabel)), ],
const Icon(CupertinoIcons.chevron_down), onChanged: enabled
], ? (chosen) {
), if (chosen != null) onChanged(chosen);
) }
: DropdownButtonFormField<T>( : null,
key: fieldKey, );
initialValue: value,
isExpanded: true,
items: [
for (final option in options)
DropdownMenuItem<T>(
value: option.value,
child: Text(option.label),
),
],
onChanged: enabled
? (chosen) {
if (chosen != null) onChanged(chosen);
}
: null,
);
return MergeSemantics( return MergeSemantics(
child: ScheduleEditorField( child: ScheduleEditorField(
label: label, label: label,
@@ -164,18 +119,11 @@ class _DayToggle extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context); final checkbox = Checkbox(
final checkbox = cupertino key: scheduleEditorDayKey(day),
? CupertinoCheckbox( value: selected,
key: scheduleEditorDayKey(day), onChanged: enabled ? (_) => onTap() : null,
value: selected, );
onChanged: enabled ? (_) => onTap() : null,
)
: Checkbox(
key: scheduleEditorDayKey(day),
value: selected,
onChanged: enabled ? (_) => onTap() : null,
);
final content = Padding( final content = Padding(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4), padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4),
child: Row( child: Row(
@@ -184,17 +132,11 @@ class _DayToggle extends StatelessWidget {
), ),
); );
return MergeSemantics( return MergeSemantics(
child: cupertino child: InkWell(
? GestureDetector( borderRadius: BorderRadius.circular(8),
behavior: HitTestBehavior.opaque, onTap: enabled ? onTap : null,
onTap: enabled ? onTap : null, child: content,
child: content, ),
)
: InkWell(
borderRadius: BorderRadius.circular(8),
onTap: enabled ? onTap : null,
child: content,
),
); );
} }
} }
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../ui/layout/app_list_avatar.dart'; import '../../../../ui/layout/app_list_avatar.dart';
@@ -27,10 +26,10 @@ class ScheduleListRow extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AppListRow( return AppListRow(
cupertino: cupertino, cupertino: false,
divider: divider, divider: divider,
onTap: onOpen, onTap: onOpen,
leading: ScheduleAvatar(schedule: schedule, cupertino: cupertino), leading: ScheduleAvatar(schedule: schedule, cupertino: false),
title: Text(scheduleDisplayName(schedule)), title: Text(scheduleDisplayName(schedule)),
time: scheduleNextDueShort(schedule), time: scheduleNextDueShort(schedule),
subtitle: Text( subtitle: Text(
@@ -56,17 +55,13 @@ class ScheduleAvatar extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final Color? enabled = schedule.enabled final Color? enabled = schedule.enabled ? Colors.green.shade700 : null;
? (cupertino
? CupertinoColors.systemGreen.resolveFrom(context)
: Colors.green.shade700)
: null;
return Semantics( return Semantics(
label: scheduleStatusLabel(schedule), label: scheduleStatusLabel(schedule),
child: ExcludeSemantics( child: ExcludeSemantics(
child: AppListAvatar( child: AppListAvatar(
foreground: enabled, foreground: enabled,
child: Icon(cupertino ? CupertinoIcons.clock : Icons.schedule), child: const Icon(Icons.schedule),
), ),
), ),
); );
@@ -30,7 +30,7 @@ class ScheduleRefreshAction extends StatelessWidget {
@override @override
Widget build(BuildContext context) => BarIconButton( Widget build(BuildContext context) => BarIconButton(
key: controller.isLoading ? null : scheduleRefreshKey, key: controller.isLoading ? null : scheduleRefreshKey,
cupertino: cupertino, cupertino: false,
icon: Icons.refresh, icon: Icons.refresh,
cupertinoIcon: CupertinoIcons.refresh, cupertinoIcon: CupertinoIcons.refresh,
label: 'Refresh schedules', label: 'Refresh schedules',
@@ -69,7 +69,7 @@ class ScheduleListToolbar extends StatelessWidget {
final refresh = switch (onRefresh) { final refresh = switch (onRefresh) {
final refresh? => ScheduleRefreshAction( final refresh? => ScheduleRefreshAction(
controller: controller, controller: controller,
cupertino: cupertino, cupertino: false,
onRefresh: refresh, onRefresh: refresh,
), ),
null => null, null => null,
@@ -119,29 +119,13 @@ class ScheduleListToolbar extends StatelessWidget {
Widget _search(BuildContext context) => AppSearchField( Widget _search(BuildContext context) => AppSearchField(
fieldKey: scheduleSearchFieldKey, fieldKey: scheduleSearchFieldKey,
controller: searchController, controller: searchController,
cupertino: cupertino, cupertino: false,
placeholder: 'Search schedules', placeholder: 'Search schedules',
onChanged: controller.setQuery, onChanged: controller.setQuery,
onCleared: controller.clearQuery, onCleared: controller.clearQuery,
); );
Widget _filter(BuildContext context) { Widget _filter(BuildContext context) {
if (cupertino) {
return CupertinoSlidingSegmentedControl<ScheduleListFilter>(
key: scheduleFilterKey,
groupValue: controller.filter,
onValueChanged: (value) {
if (value != null) controller.setFilter(value);
},
children: {
for (final filter in ScheduleListFilter.values)
filter: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
child: Text(filter.label),
),
},
);
}
return SegmentedButton<ScheduleListFilter>( return SegmentedButton<ScheduleListFilter>(
key: scheduleFilterKey, key: scheduleFilterKey,
segments: [ segments: [
@@ -159,12 +143,8 @@ class ScheduleListToolbar extends StatelessWidget {
); );
} }
TextStyle? _metaStyle(BuildContext context) => cupertino TextStyle? _metaStyle(BuildContext context) => Theme.of(context)
? CupertinoTheme.of(context).textTheme.textStyle.copyWith( .textTheme
fontSize: 15, .bodyMedium
color: CupertinoColors.secondaryLabel.resolveFrom(context), ?.copyWith(color: Theme.of(context).colorScheme.onSurfaceVariant);
)
: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
);
} }
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../ui/adaptive/floating_bar_layout.dart'; import '../../../../ui/adaptive/floating_bar_layout.dart';
@@ -55,13 +54,13 @@ class SchedulesListView extends StatelessWidget {
edge: FloatingBarEdge.top, edge: FloatingBarEdge.top,
bar: TopGlassStrip( bar: TopGlassStrip(
key: scheduleToolbarKey, key: scheduleToolbarKey,
cupertino: cupertino, cupertino: false,
maxWidth: kScheduleToolbarMaxWidth, maxWidth: kScheduleToolbarMaxWidth,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
child: ScheduleListToolbar( child: ScheduleListToolbar(
controller: controller, controller: controller,
searchController: searchController, searchController: searchController,
cupertino: cupertino, cupertino: false,
onRefresh: refreshInToolbar ? onRefresh : null, onRefresh: refreshInToolbar ? onRefresh : null,
), ),
), ),
@@ -118,7 +117,7 @@ class SchedulesListView extends StatelessWidget {
'schedule-row-$index-${schedule.id ?? 'unknown'}', 'schedule-row-$index-${schedule.id ?? 'unknown'}',
), ),
schedule: schedule, schedule: schedule,
cupertino: cupertino, cupertino: false,
divider: index < schedules.length - 1, divider: index < schedules.length - 1,
onOpen: () => onOpen(schedule), onOpen: () => onOpen(schedule),
), ),
@@ -136,9 +135,7 @@ class SchedulesListView extends StatelessWidget {
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
cupertino const CircularProgressIndicator(),
? const CupertinoActivityIndicator()
: const CircularProgressIndicator(),
const SizedBox(height: 12), const SizedBox(height: 12),
const Text('Loading schedules…'), const Text('Loading schedules…'),
], ],
@@ -161,9 +158,7 @@ class SchedulesListView extends StatelessWidget {
detail, detail,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
color: cupertino color: Theme.of(context).colorScheme.onSurfaceVariant,
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant,
), ),
), ),
), ),
@@ -204,9 +199,7 @@ class SchedulesListView extends StatelessWidget {
} }
Widget _failureText(BuildContext context, ScheduleListFailure failure) { Widget _failureText(BuildContext context, ScheduleListFailure failure) {
final color = cupertino final color = Theme.of(context).colorScheme.error;
? CupertinoColors.systemRed.resolveFrom(context)
: Theme.of(context).colorScheme.error;
return Semantics( return Semantics(
liveRegion: true, liveRegion: true,
child: Text( child: Text(
@@ -218,14 +211,6 @@ class SchedulesListView extends StatelessWidget {
} }
Widget _retryButton() { Widget _retryButton() {
if (cupertino) {
return CupertinoButton(
key: scheduleRetryKey,
padding: EdgeInsets.zero,
onPressed: onRefresh,
child: const Text('Retry'),
);
}
return TextButton( return TextButton(
key: scheduleRetryKey, key: scheduleRetryKey,
onPressed: onRefresh, onPressed: onRefresh,
@@ -1,7 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../ui/adaptive/host.dart';
import 'schedule_pipeline_wording.dart'; import 'schedule_pipeline_wording.dart';
/// Deletes the exact schedule revision. Returns null once the server accepted /// Deletes the exact schedule revision. Returns null once the server accepted
@@ -18,13 +16,6 @@ Future<void> showScheduleDeleteDialog({
required ScheduleDeleteSubmit onSubmit, required ScheduleDeleteSubmit onSubmit,
}) { }) {
final prompt = _ScheduleDeletePrompt(name: name, onSubmit: onSubmit); final prompt = _ScheduleDeletePrompt(name: name, onSubmit: onSubmit);
if (usesCupertinoHost(context)) {
return showCupertinoDialog<void>(
context: context,
barrierDismissible: false,
builder: (_) => prompt,
);
}
return showDialog<void>( return showDialog<void>(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
@@ -70,10 +61,7 @@ class _ScheduleDeletePromptState extends State<_ScheduleDeletePrompt> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final dialog = usesCupertinoHost(context) return PopScope(canPop: !_sending, child: _material(context));
? _cupertino(context)
: _material(context);
return PopScope(canPop: !_sending, child: dialog);
} }
Widget _material(BuildContext context) { Widget _material(BuildContext context) {
@@ -98,30 +86,6 @@ class _ScheduleDeletePromptState extends State<_ScheduleDeletePrompt> {
); );
} }
Widget _cupertino(BuildContext context) {
return CupertinoAlertDialog(
title: Text(scheduleDeleteTitle(widget.name)),
content: _body(
errorStyle: TextStyle(
color: CupertinoColors.systemRed.resolveFrom(context),
),
),
actions: [
CupertinoDialogAction(
key: scheduleDeleteKeepKey,
onPressed: _sending ? null : _keep,
child: const Text(scheduleDeleteKeepLabel),
),
CupertinoDialogAction(
key: scheduleDeleteConfirmKey,
isDestructiveAction: true,
onPressed: _sending ? null : _confirm,
child: const Text(scheduleDeleteConfirmLabel),
),
],
);
}
Widget _body({required TextStyle errorStyle}) { Widget _body({required TextStyle errorStyle}) {
return Column( return Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
@@ -1,11 +1,9 @@
import '../../../../ui/adaptive/segmented_bar.dart'; import '../../../../ui/adaptive/segmented_bar.dart';
import 'dart:math'; import 'dart:math';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart'; import '../../../../core/api_gateway.dart';
import '../../../../ui/adaptive/host.dart';
import '../../domain/editor/schedule_draft.dart'; import '../../domain/editor/schedule_draft.dart';
import '../editor/schedule_editor_form.dart'; import '../editor/schedule_editor_form.dart';
import '../editor/schedule_editor_wording.dart'; import '../editor/schedule_editor_wording.dart';
@@ -40,22 +38,14 @@ Future<void> openSchedulePipelineEditor(
final title = draft.source == null final title = draft.source == null
? scheduleEditorAddTitle ? scheduleEditorAddTitle
: scheduleEditorEditTitle; : scheduleEditorEditTitle;
final route = usesCupertinoHost(context) final route = MaterialPageRoute<void>(
? CupertinoPageRoute<void>( settings: settings,
settings: settings, builder: (_) => Scaffold(
builder: (_) => CupertinoPageScaffold( extendBodyBehindAppBar: true,
navigationBar: SegmentedBar(cupertino: true, title: title), appBar: SegmentedBar(cupertino: false, title: title),
child: SafeArea(child: page), body: SafeArea(child: page),
), ),
) );
: MaterialPageRoute<void>(
settings: settings,
builder: (_) => Scaffold(
extendBodyBehindAppBar: true,
appBar: SegmentedBar(cupertino: false, title: title),
body: SafeArea(child: page),
),
);
return Navigator.of(context).push(route); return Navigator.of(context).push(route);
} }
@@ -1,7 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../ui/adaptive/host.dart';
import '../../../../ui/layout/section_heading.dart'; import '../../../../ui/layout/section_heading.dart';
import '../../domain/saved_schedule.dart'; import '../../domain/saved_schedule.dart';
import '../list/schedule_list_controller.dart'; import '../list/schedule_list_controller.dart';
@@ -83,24 +81,12 @@ class SchedulePipelineListBody extends StatelessWidget {
/// the section reloads after every accepted change and offers Retry when a /// the section reloads after every accepted change and offers Retry when a
/// load fails. /// load fails.
Widget _header(BuildContext context) { Widget _header(BuildContext context) {
final cupertino = usesCupertinoHost(context); final add = IconButton(
final add = cupertino key: scheduleAddKey,
? CupertinoButton( tooltip: scheduleAddLabel,
key: scheduleAddKey, onPressed: onAdd,
padding: EdgeInsets.zero, icon: const Icon(Icons.add),
minimumSize: const Size.square(44), );
onPressed: onAdd,
child: const Icon(
CupertinoIcons.add,
semanticLabel: scheduleAddLabel,
),
)
: IconButton(
key: scheduleAddKey,
tooltip: scheduleAddLabel,
onPressed: onAdd,
icon: const Icon(Icons.add),
);
return SectionHeading( return SectionHeading(
title: controller.hasLoaded && controller.failure == null title: controller.hasLoaded && controller.failure == null
? '$scheduleSectionTitle (${controller.schedules.length})' ? '$scheduleSectionTitle (${controller.schedules.length})'
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../ui/adaptive/host.dart';
import '../../../../ui/layout/app_list_row.dart'; import '../../../../ui/layout/app_list_row.dart';
import '../../../../ui/layout/app_overflow_menu.dart'; import '../../../../ui/layout/app_overflow_menu.dart';
import '../../domain/saved_schedule.dart'; import '../../domain/saved_schedule.dart';
@@ -39,12 +38,11 @@ class SchedulePipelineRow extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final id = schedule.id; final id = schedule.id;
final cupertino = usesCupertinoHost(context);
final row = AppListRow( final row = AppListRow(
cupertino: cupertino, cupertino: false,
divider: divider && error == null, divider: divider && error == null,
onTap: busy ? null : onEdit, onTap: busy ? null : onEdit,
leading: ScheduleAvatar(schedule: schedule, cupertino: cupertino), leading: ScheduleAvatar(schedule: schedule, cupertino: false),
title: Text(scheduleDisplayName(schedule)), title: Text(scheduleDisplayName(schedule)),
time: scheduleNextDueShort(schedule), time: scheduleNextDueShort(schedule),
subtitle: Text( subtitle: Text(
@@ -1,21 +1,11 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../ui/adaptive/host.dart'; /// Material text roles and standard buttons for the pipeline schedule section.
/// Host text roles and standard buttons for the pipeline schedule section.
/// No palette, font family or explicit point size is introduced. /// No palette, font family or explicit point size is introduced.
TextStyle? schedulePipelineHeadingStyle(BuildContext context) => TextStyle? schedulePipelineHeadingStyle(BuildContext context) =>
usesCupertinoHost(context) Theme.of(context).textTheme.titleMedium;
? CupertinoTheme.of(context).textTheme.navTitleTextStyle
: Theme.of(context).textTheme.titleMedium;
TextStyle? schedulePipelineMutedStyle(BuildContext context) { TextStyle? schedulePipelineMutedStyle(BuildContext context) {
if (usesCupertinoHost(context)) {
return CupertinoTheme.of(context).textTheme.tabLabelTextStyle.copyWith(
color: CupertinoColors.secondaryLabel.resolveFrom(context),
);
}
final theme = Theme.of(context); final theme = Theme.of(context);
return theme.textTheme.bodySmall?.copyWith( return theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant, color: theme.colorScheme.onSurfaceVariant,
@@ -25,32 +15,18 @@ TextStyle? schedulePipelineMutedStyle(BuildContext context) {
TextStyle? schedulePipelineStatusStyle(BuildContext context, bool enabled) { TextStyle? schedulePipelineStatusStyle(BuildContext context, bool enabled) {
final base = schedulePipelineMutedStyle(context); final base = schedulePipelineMutedStyle(context);
if (!enabled) return base; if (!enabled) return base;
return usesCupertinoHost(context) return base?.copyWith(color: Theme.of(context).colorScheme.primary);
? base?.copyWith(color: CupertinoTheme.of(context).primaryColor)
: base?.copyWith(color: Theme.of(context).colorScheme.primary);
} }
TextStyle? schedulePipelineErrorStyle(BuildContext context) => TextStyle? schedulePipelineErrorStyle(BuildContext context) =>
usesCupertinoHost(context) TextStyle(color: Theme.of(context).colorScheme.error);
? CupertinoTheme.of(context).textTheme.textStyle.copyWith(
color: CupertinoColors.systemRed.resolveFrom(context),
)
: TextStyle(color: Theme.of(context).colorScheme.error);
/// A standard platform text action. /// A standard text action.
Widget schedulePipelineTextButton( Widget schedulePipelineTextButton(
BuildContext context, { BuildContext context, {
required String label, required String label,
required VoidCallback? onPressed, required VoidCallback? onPressed,
Key? key, Key? key,
}) { }) {
if (usesCupertinoHost(context)) {
return CupertinoButton(
key: key,
padding: EdgeInsets.zero,
onPressed: onPressed,
child: Text(label),
);
}
return TextButton(key: key, onPressed: onPressed, child: Text(label)); return TextButton(key: key, onPressed: onPressed, child: Text(label));
} }
@@ -1,8 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart'; import '../../../../core/api_gateway.dart';
import '../../../../ui/adaptive/host.dart';
import '../../data/schedules_repository.dart'; import '../../data/schedules_repository.dart';
import '../../domain/editor/schedule_draft.dart'; import '../../domain/editor/schedule_draft.dart';
import '../../domain/schedule_json.dart'; import '../../domain/schedule_json.dart';
@@ -84,19 +82,11 @@ class _ScheduleRunActionState extends State<ScheduleRunAction> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (!canScheduleRun(widget.run)) return const SizedBox.shrink(); if (!canScheduleRun(widget.run)) return const SizedBox.shrink();
final cupertino = usesCupertinoHost(context); final action = OutlinedButton(
final action = cupertino key: scheduleRunActionKey,
? CupertinoButton.tinted( onPressed: _open,
sizeStyle: CupertinoButtonSize.small, child: const Text(scheduleRunActionLabel),
key: scheduleRunActionKey, );
onPressed: _open,
child: const Text(scheduleRunActionLabel),
)
: OutlinedButton(
key: scheduleRunActionKey,
onPressed: _open,
child: const Text(scheduleRunActionLabel),
);
return Tooltip(message: scheduleRunActionHint, child: action); return Tooltip(message: scheduleRunActionHint, child: action);
} }
} }
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
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/core/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
@@ -31,7 +30,6 @@ Future<void> pumpScheduleEditor(
WidgetTester tester, { WidgetTester tester, {
required ScheduleDraft draft, required ScheduleDraft draft,
required Future<void> Function(JsonMap record) onSubmit, required Future<void> Function(JsonMap record) onSubmit,
bool cupertino = false,
bool dark = false, bool dark = false,
double width = 390, double width = 390,
double height = 1600, double height = 1600,
@@ -57,21 +55,11 @@ Future<void> pumpScheduleEditor(
child: app!, child: app!,
); );
await tester.pumpWidget( await tester.pumpWidget(
cupertino MaterialApp(
? CupertinoApp( theme: ThemeData(brightness: dark ? Brightness.dark : Brightness.light),
theme: CupertinoThemeData( builder: scaled,
brightness: dark ? Brightness.dark : Brightness.light, home: Scaffold(body: SafeArea(child: form)),
), ),
builder: scaled,
home: CupertinoPageScaffold(child: SafeArea(child: form)),
)
: MaterialApp(
theme: ThemeData(
brightness: dark ? Brightness.dark : Brightness.light,
),
builder: scaled,
home: Scaffold(body: SafeArea(child: form)),
),
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
} }
@@ -1,10 +1,8 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/cupertino.dart';
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/core/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/schedules/ui/editor/schedule_editor_selectors.dart';
import 'package:pipelines_app/features/schedules/ui/editor/schedule_editor_wording.dart'; import 'package:pipelines_app/features/schedules/ui/editor/schedule_editor_wording.dart';
import 'schedule_editor_harness.dart'; import 'schedule_editor_harness.dart';
@@ -101,49 +99,6 @@ void main() {
); );
}); });
testWidgets('Cupertino form uses native fields and action sheets', (
tester,
) async {
final calls = <JsonMap>[];
await pumpScheduleEditor(
tester,
cupertino: true,
draft: createDraft(name: 'Cupertino schedule', prompt: 'Native fields'),
onSubmit: (record) async => calls.add(record),
);
expect(find.byType(CupertinoTextField), findsNWidgets(6));
expect(find.byType(TextField), findsNothing);
expect(find.byType(CupertinoSwitch), findsOneWidget);
expect(find.byType(Switch), findsNothing);
expect(find.byType(CupertinoCheckbox), findsNWidgets(7));
expect(find.byType(Checkbox), findsNothing);
await tester.tap(find.byKey(scheduleEditorTimerKey));
await tester.pumpAndSettle();
await tester.tap(find.text('Clock times').last);
await tester.pumpAndSettle();
await enterField(tester, scheduleEditorTimesKey, '06:30');
await tester.tap(find.byKey(scheduleEditorDayKey('mon')));
await tester.pump();
expect(
tester
.widget<CupertinoCheckbox>(find.byKey(scheduleEditorDayKey('mon')))
.value,
isTrue,
);
await tester.tap(find.byKey(scheduleEditorEnabledKey));
await tester.pump();
await tester.tap(find.byKey(scheduleEditorSubmitKey));
await tester.pumpAndSettle();
expect(calls.single['enabled'], isFalse);
expect(calls.single['rule'], {
'times': ['06:30'],
'days': ['mon'],
'timezone': 'Europe/London',
});
});
testWidgets('Cancel calls the injected callback and sends nothing', ( testWidgets('Cancel calls the injected callback and sends nothing', (
tester, tester,
) async { ) async {
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@@ -44,37 +43,4 @@ void main() {
); );
expect(note.size.width, lessThanOrEqualTo(320 - 32)); expect(note.size.width, lessThanOrEqualTo(320 - 32));
}); });
testWidgets('Cupertino dark uses native controls and the native palette', (
tester,
) async {
await pumpScheduleEditor(
tester,
cupertino: true,
dark: true,
width: 320,
height: 1800,
textScale: 2,
draft: createDraft(),
onSubmit: (JsonMap record) async {},
);
expect(tester.takeException(), isNull);
for (final label in _labels) {
expect(find.text(label), findsOneWidget, reason: label);
}
expect(find.byType(CupertinoTextField), findsNWidgets(6));
expect(find.byType(CupertinoSwitch), findsOneWidget);
expect(find.byType(CupertinoCheckbox), findsNWidgets(7));
expect(find.byType(Material), findsNothing);
expect(find.byType(TextField), findsNothing);
expect(find.byType(Switch), findsNothing);
expect(find.byType(Checkbox), findsNothing);
final context = tester.element(find.byKey(scheduleEditorNameKey));
expect(CupertinoTheme.of(context).brightness, Brightness.dark);
expect(
CupertinoColors.label.resolveFrom(context).toARGB32(),
CupertinoColors.label.darkColor.toARGB32(),
);
});
} }
@@ -1,6 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
@@ -119,23 +118,13 @@ List<JsonMap> longScheduleList(int count) => [
), ),
]; ];
Widget schedulesApp( Widget schedulesApp(Widget child, {double textScale = 1}) {
Widget child, {
required bool cupertino,
double textScale = 1,
}) {
Widget media(BuildContext context, Widget? app) => MediaQuery( Widget media(BuildContext context, Widget? app) => MediaQuery(
data: MediaQuery.of( data: MediaQuery.of(
context, context,
).copyWith(textScaler: TextScaler.linear(textScale)), ).copyWith(textScaler: TextScaler.linear(textScale)),
child: app!, child: app!,
); );
if (cupertino) {
return CupertinoApp(
builder: media,
home: CupertinoPageScaffold(child: SafeArea(child: child)),
);
}
return MaterialApp( return MaterialApp(
builder: media, builder: media,
home: Scaffold(body: child), home: Scaffold(body: child),
@@ -8,7 +8,6 @@ import 'schedule_list_test_support.dart';
Future<void> pumpSchedules( Future<void> pumpSchedules(
WidgetTester tester, { WidgetTester tester, {
required bool cupertino,
required ApiGateway gateway, required ApiGateway gateway,
ValueChanged<SavedSchedule>? onOpen, ValueChanged<SavedSchedule>? onOpen,
double textScale = 1, double textScale = 1,
@@ -22,7 +21,6 @@ Future<void> pumpSchedules(
await tester.pumpWidget( await tester.pumpWidget(
schedulesApp( schedulesApp(
SchedulesScreen(gateway: gateway, onOpen: onOpen ?? (_) {}), SchedulesScreen(gateway: gateway, onOpen: onOpen ?? (_) {}),
cupertino: cupertino,
textScale: textScale, textScale: textScale,
), ),
); );
@@ -17,12 +17,7 @@ void main() {
pausedRecord(), pausedRecord(),
]), ]),
); );
await pumpSchedules( await pumpSchedules(tester, gateway: gateway, textScale: textScale);
tester,
cupertino: false,
gateway: gateway,
textScale: textScale,
);
expect(find.text('2 schedules'), findsOneWidget); expect(find.text('2 schedules'), findsOneWidget);
// The strip carries the count only; the helper line lives in the // The strip carries the count only; the helper line lives in the
@@ -51,10 +46,7 @@ void main() {
expect(find.text('Paused'), findsOneWidget); expect(find.text('Paused'), findsOneWidget);
expect(find.byKey(scheduleSearchFieldKey), findsOneWidget); expect(find.byKey(scheduleSearchFieldKey), findsOneWidget);
expect( expect(find.byType(SegmentedButton<ScheduleListFilter>), findsOneWidget);
find.byType(SegmentedButton<ScheduleListFilter>),
findsOneWidget,
);
expect(find.byType(TextField), findsOneWidget); expect(find.byType(TextField), findsOneWidget);
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
}); });
@@ -14,7 +14,7 @@ void main() {
(type, fields) async => (type, fields) async =>
schedulesReply([scheduleRecord(), pausedRecord()]), schedulesReply([scheduleRecord(), pausedRecord()]),
); );
await pumpSchedules(tester, cupertino: false, gateway: gateway); await pumpSchedules(tester, gateway: gateway);
await tester.enterText( await tester.enterText(
find.byKey(scheduleSearchFieldKey), find.byKey(scheduleSearchFieldKey),
@@ -42,7 +42,7 @@ void main() {
final gateway = FakeSchedulesGateway( final gateway = FakeSchedulesGateway(
(type, fields) async => schedulesReply(longScheduleList(30)), (type, fields) async => schedulesReply(longScheduleList(30)),
); );
await pumpSchedules(tester, cupertino: false, gateway: gateway); await pumpSchedules(tester, gateway: gateway);
final list = find.byKey(scheduleListKey); final list = find.byKey(scheduleListKey);
await tester.drag(list, const Offset(0, -700)); await tester.drag(list, const Offset(0, -700));
@@ -66,7 +66,7 @@ void main() {
if (fail) throw StateError('refresh failed'); if (fail) throw StateError('refresh failed');
return schedulesReply(longScheduleList(30)); return schedulesReply(longScheduleList(30));
}); });
await pumpSchedules(tester, cupertino: false, gateway: gateway); await pumpSchedules(tester, gateway: gateway);
final list = find.byKey(scheduleListKey); final list = find.byKey(scheduleListKey);
await tester.drag(list, const Offset(0, -700)); await tester.drag(list, const Offset(0, -700));
@@ -104,7 +104,7 @@ void main() {
if (fail) throw StateError('refresh failed'); if (fail) throw StateError('refresh failed');
return schedulesReply([scheduleRecord(), pausedRecord()]); return schedulesReply([scheduleRecord(), pausedRecord()]);
}); });
await pumpSchedules(tester, cupertino: false, gateway: gateway); await pumpSchedules(tester, gateway: gateway);
fail = true; fail = true;
await tester.tap(find.byKey(scheduleRefreshKey)); await tester.tap(find.byKey(scheduleRefreshKey));
@@ -14,7 +14,7 @@ void main() {
(type, fields) async => (type, fields) async =>
schedulesReply([scheduleRecord(), pausedRecord()]), schedulesReply([scheduleRecord(), pausedRecord()]),
); );
await pumpSchedules(tester, cupertino: false, gateway: gateway); await pumpSchedules(tester, gateway: gateway);
await tester.enterText(find.byKey(scheduleSearchFieldKey), 'pipeline 7'); await tester.enterText(find.byKey(scheduleSearchFieldKey), 'pipeline 7');
await tester.pump(); await tester.pump();
@@ -41,7 +41,7 @@ void main() {
(type, fields) async => (type, fields) async =>
schedulesReply([scheduleRecord(), pausedRecord()]), schedulesReply([scheduleRecord(), pausedRecord()]),
); );
await pumpSchedules(tester, cupertino: false, gateway: gateway); await pumpSchedules(tester, gateway: gateway);
await tester.tap( await tester.tap(
find.descendant( find.descendant(
@@ -65,12 +65,7 @@ void main() {
(type, fields) async => schedulesReply([record]), (type, fields) async => schedulesReply([record]),
); );
final opened = <SavedSchedule>[]; final opened = <SavedSchedule>[];
await pumpSchedules( await pumpSchedules(tester, gateway: gateway, onOpen: opened.add);
tester,
cupertino: false,
gateway: gateway,
onOpen: opened.add,
);
expect(opened, isEmpty); expect(opened, isEmpty);
expect(find.text('Add schedule'), findsNothing); expect(find.text('Add schedule'), findsNothing);
@@ -92,14 +87,14 @@ void main() {
final empty = FakeSchedulesGateway( final empty = FakeSchedulesGateway(
(type, fields) async => {'type': 'schedules'}, (type, fields) async => {'type': 'schedules'},
); );
await pumpSchedules(tester, cupertino: false, gateway: empty); await pumpSchedules(tester, gateway: empty);
expect(find.text('No schedules yet.'), findsOneWidget); expect(find.text('No schedules yet.'), findsOneWidget);
expect(find.byKey(scheduleRetryKey), findsNothing); expect(find.byKey(scheduleRetryKey), findsNothing);
final unsupported = FakeSchedulesGateway( final unsupported = FakeSchedulesGateway(
(type, fields) async => {'type': 'runs'}, (type, fields) async => {'type': 'runs'},
); );
await pumpSchedules(tester, cupertino: false, gateway: unsupported); await pumpSchedules(tester, gateway: unsupported);
expect( expect(
find.textContaining('does not support saved schedules'), find.textContaining('does not support saved schedules'),
findsOneWidget, findsOneWidget,
@@ -110,7 +105,7 @@ void main() {
final failed = FakeSchedulesGateway( final failed = FakeSchedulesGateway(
(type, fields) async => throw StateError('socket closed'), (type, fields) async => throw StateError('socket closed'),
); );
await pumpSchedules(tester, cupertino: false, gateway: failed); await pumpSchedules(tester, gateway: failed);
expect(find.textContaining('socket closed'), findsOneWidget); expect(find.textContaining('socket closed'), findsOneWidget);
expect(find.byKey(scheduleRetryKey), findsOneWidget); expect(find.byKey(scheduleRetryKey), findsOneWidget);
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
@@ -122,7 +117,7 @@ void main() {
final gateway = FakeSchedulesGateway( final gateway = FakeSchedulesGateway(
(type, fields) async => schedulesReply([pausedRecord()]), (type, fields) async => schedulesReply([pausedRecord()]),
); );
await pumpSchedules(tester, cupertino: false, gateway: gateway); await pumpSchedules(tester, gateway: gateway);
await tester.tap( await tester.tap(
find.descendant( find.descendant(
@@ -147,12 +142,7 @@ void main() {
tester, tester,
) async { ) async {
final gateway = ControlledSchedulesGateway(); final gateway = ControlledSchedulesGateway();
await pumpSchedules( await pumpSchedules(tester, gateway: gateway, settle: false);
tester,
cupertino: false,
gateway: gateway,
settle: false,
);
expect(find.byKey(scheduleRefreshKey), findsNothing); expect(find.byKey(scheduleRefreshKey), findsNothing);
await tester.pumpWidget(const SizedBox.shrink()); await tester.pumpWidget(const SizedBox.shrink());
@@ -14,7 +14,6 @@ void main() {
'row', (tester) async { 'row', (tester) async {
await pumpSchedules( await pumpSchedules(
tester, tester,
cupertino: false,
size: const Size(1200, 800), size: const Size(1200, 800),
gateway: FakeSchedulesGateway( gateway: FakeSchedulesGateway(
(type, fields) async => schedulesReply([ (type, fields) async => schedulesReply([
@@ -378,37 +378,31 @@ void main() {
expect(find.text('socket closed'), findsNothing); expect(find.text('socket closed'), findsNothing);
}); });
testWidgets('320px at 2x text stays usable on both native hosts', ( testWidgets('320px at 2x text stays usable', (tester) async {
tester, final gateway = SectionGateway(
) async { (type, fields) async => schedulesReply([
for (final cupertino in [false, true]) { sectionRecord(
final gateway = SectionGateway( name: 'A very long schedule name that must wrap without overflow',
(type, fields) async => schedulesReply([ prompt:
sectionRecord( 'A long prompt that also wraps instead of forcing a fixed row '
name: 'A very long schedule name that must wrap without overflow', 'height or a horizontal scroll.',
prompt: ),
'A long prompt that also wraps instead of forcing a fixed row ' ]),
'height or a horizontal scroll.', );
), await pumpScheduleSection(
]), tester,
); gateway: gateway,
await pumpScheduleSection( width: 320,
tester, height: 844,
gateway: gateway, textScale: 2,
cupertino: cupertino, );
dark: cupertino,
width: 320,
height: 844,
textScale: 2,
);
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
expect(find.byKey(scheduleAddKey), findsOneWidget); expect(find.byKey(scheduleAddKey), findsOneWidget);
await _openMenu(tester, 8); await _openMenu(tester, 8);
expect(find.byKey(scheduleRowEditKey(8)), findsOneWidget); expect(find.byKey(scheduleRowEditKey(8)), findsOneWidget);
expect(find.byKey(scheduleRowToggleKey(8)), findsOneWidget); expect(find.byKey(scheduleRowToggleKey(8)), findsOneWidget);
expect(find.byKey(scheduleRowDeleteKey(8)), findsOneWidget); expect(find.byKey(scheduleRowDeleteKey(8)), findsOneWidget);
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
}
}); });
} }
@@ -1,6 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/cupertino.dart';
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/core/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
@@ -83,12 +82,7 @@ JsonMap sectionRecord({
}, },
}; };
Widget sectionApp( Widget sectionApp(Widget section, {bool dark = false, double textScale = 1}) {
Widget section, {
required bool cupertino,
bool dark = false,
double textScale = 1,
}) {
Widget media(BuildContext context, Widget? app) => MediaQuery( Widget media(BuildContext context, Widget? app) => MediaQuery(
data: MediaQuery.of( data: MediaQuery.of(
context, context,
@@ -98,16 +92,6 @@ Widget sectionApp(
final body = SafeArea( final body = SafeArea(
child: ListView(children: [section, const SizedBox(height: 24)]), child: ListView(children: [section, const SizedBox(height: 24)]),
); );
if (cupertino) {
return CupertinoApp(
debugShowCheckedModeBanner: false,
theme: CupertinoThemeData(
brightness: dark ? Brightness.dark : Brightness.light,
),
builder: media,
home: CupertinoPageScaffold(child: body),
);
}
return MaterialApp( return MaterialApp(
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
theme: ThemeData(brightness: dark ? Brightness.dark : Brightness.light), theme: ThemeData(brightness: dark ? Brightness.dark : Brightness.light),
@@ -119,7 +103,6 @@ Widget sectionApp(
Future<void> pumpScheduleSection( Future<void> pumpScheduleSection(
WidgetTester tester, { WidgetTester tester, {
required SectionGateway gateway, required SectionGateway gateway,
bool cupertino = false,
bool dark = false, bool dark = false,
double width = 390, double width = 390,
double height = 844, double height = 844,
@@ -137,7 +120,7 @@ Future<void> pumpScheduleSection(
settingsStore: MemorySettingsStore(workspace: '/srv/research'), settingsStore: MemorySettingsStore(workspace: '/srv/research'),
); );
await tester.pumpWidget( await tester.pumpWidget(
sectionApp(section, cupertino: cupertino, dark: dark, textScale: textScale), sectionApp(section, dark: dark, textScale: textScale),
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
} }
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
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/core/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
@@ -68,23 +67,15 @@ JsonMap restrictedRunFixture() => {
'output_format': 'json', 'output_format': 'json',
}; };
Future<void> pumpAction( Future<void> pumpAction(WidgetTester tester, Widget child) async {
WidgetTester tester,
Widget child, {
bool cupertino = false,
}) async {
tester.view.physicalSize = const Size(390, 1600); tester.view.physicalSize = const Size(390, 1600);
tester.view.devicePixelRatio = 1; tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio); addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget( await tester.pumpWidget(
cupertino MaterialApp(
? CupertinoApp( home: Scaffold(body: SafeArea(child: child)),
home: CupertinoPageScaffold(child: SafeArea(child: child)), ),
)
: MaterialApp(
home: Scaffold(body: SafeArea(child: child)),
),
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
} }
@@ -225,38 +216,4 @@ void main() {
await openMenu(runFixture(pipelineId: null)); await openMenu(runFixture(pipelineId: null));
expect(find.text(scheduleRunActionLabel), findsNothing); expect(find.text(scheduleRunActionLabel), findsNothing);
}); });
testWidgets('Cupertino uses the native action and fields', (tester) async {
final gateway = SaveGateway();
await pumpAction(
tester,
ScheduleRunAction(run: runFixture(), gateway: gateway),
cupertino: true,
);
final action = find.byKey(scheduleRunActionKey);
expect(
find.widgetWithText(CupertinoButton, scheduleRunActionLabel),
findsOne,
);
await tester.tap(action);
await tester.pumpAndSettle();
expect(gateway.calls, isEmpty);
expect(find.byKey(scheduleEditorSubmitKey), findsOneWidget);
expect(
tester
.widget<CupertinoTextField>(find.byKey(scheduleEditorVersionKey))
.controller
?.text,
'5',
);
expect(
tester
.widget<CupertinoTextField>(find.byKey(scheduleEditorWorkspaceKey))
.controller
?.text,
'/srv/run-workspace',
);
});
} }