42a2378ecb
Use Material popup menus for file actions and anchor Runs sorting choices to the sort button while retaining the phone fallback. Update callers, tests, and implementation notes to match the desktop behavior.
106 lines
3.4 KiB
Dart
106 lines
3.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../../../ui/adaptive/host.dart';
|
|
import '../../../../ui/layout/app_list_row.dart';
|
|
import '../../../../ui/layout/app_overflow_menu.dart';
|
|
import '../../domain/saved_schedule.dart';
|
|
import '../list/schedule_list_format.dart';
|
|
import '../list/schedule_list_row.dart';
|
|
import 'schedule_pipeline_styles.dart';
|
|
import 'schedule_pipeline_wording.dart';
|
|
|
|
enum _ScheduleAction { edit, toggle, delete }
|
|
|
|
/// One saved schedule in the pipeline Summary, in the app's shared row: the
|
|
/// clock avatar, the name with its next run (or `Paused`), one muted line with
|
|
/// the pinned version and timer words, and an overflow menu with Edit,
|
|
/// Pause/Enable and Delete. A tap on the row edits it; a refused action's
|
|
/// message sits under the row.
|
|
class SchedulePipelineRow extends StatelessWidget {
|
|
const SchedulePipelineRow({
|
|
super.key,
|
|
required this.schedule,
|
|
required this.busy,
|
|
required this.onEdit,
|
|
required this.onToggle,
|
|
required this.onDelete,
|
|
this.error,
|
|
this.divider = false,
|
|
});
|
|
|
|
final SavedSchedule schedule;
|
|
final bool busy;
|
|
final String? error;
|
|
final VoidCallback onEdit;
|
|
final VoidCallback onToggle;
|
|
final VoidCallback onDelete;
|
|
final bool divider;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final id = schedule.id;
|
|
final cupertino = usesCupertinoHost(context);
|
|
final row = AppListRow(
|
|
cupertino: cupertino,
|
|
divider: divider && error == null,
|
|
onTap: busy ? null : onEdit,
|
|
leading: ScheduleAvatar(schedule: schedule, cupertino: cupertino),
|
|
title: Text(scheduleDisplayName(schedule)),
|
|
time: scheduleNextDueShort(schedule),
|
|
subtitle: Text(
|
|
'${schedulePinnedVersionValue(schedule)} · '
|
|
'${scheduleRuleSummary(schedule)}',
|
|
),
|
|
// A narrow Summary still needs a way to pause or delete.
|
|
menu: AppOverflowMenu<_ScheduleAction>(
|
|
key: scheduleRowMenuKey(id),
|
|
enabled: !busy,
|
|
label: 'Schedule actions for ${scheduleDisplayName(schedule)}',
|
|
sheetTitle: scheduleDisplayName(schedule),
|
|
actions: [
|
|
AppMenuAction(
|
|
key: scheduleRowEditKey(id),
|
|
value: _ScheduleAction.edit,
|
|
label: scheduleEditLabel,
|
|
),
|
|
AppMenuAction(
|
|
key: scheduleRowToggleKey(id),
|
|
value: _ScheduleAction.toggle,
|
|
label: schedule.enabled ? schedulePauseLabel : scheduleEnableLabel,
|
|
),
|
|
AppMenuAction(
|
|
key: scheduleRowDeleteKey(id),
|
|
value: _ScheduleAction.delete,
|
|
label: scheduleDeleteLabel,
|
|
destructive: true,
|
|
),
|
|
],
|
|
onSelected: (_, action) => switch (action) {
|
|
_ScheduleAction.edit => onEdit(),
|
|
_ScheduleAction.toggle => onToggle(),
|
|
_ScheduleAction.delete => onDelete(),
|
|
},
|
|
),
|
|
);
|
|
return Column(
|
|
key: scheduleRowKey(id),
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
row,
|
|
if (error case final text?)
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
|
|
child: Semantics(
|
|
liveRegion: true,
|
|
child: Text(
|
|
text,
|
|
key: scheduleRowErrorKey(id),
|
|
style: schedulePipelineErrorStyle(context),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|