226 lines
6.9 KiB
Dart
226 lines
6.9 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../../ui/adaptive/host.dart';
|
|
|
|
import '../../domain/saved_schedule.dart';
|
|
import '../list/schedule_list_format.dart';
|
|
import 'schedule_pipeline_styles.dart';
|
|
import 'schedule_pipeline_wording.dart';
|
|
|
|
/// One saved schedule in the pipeline Summary: name, state, pinned version and
|
|
/// timer words, the recorded due time, and its Edit/Pause-Enable/Delete actions.
|
|
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,
|
|
});
|
|
|
|
final SavedSchedule schedule;
|
|
final bool busy;
|
|
final String? error;
|
|
final VoidCallback onEdit;
|
|
final VoidCallback onToggle;
|
|
final VoidCallback onDelete;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final id = schedule.id;
|
|
final body = schedulePipelineBodyStyle(context);
|
|
final title = body?.copyWith(fontWeight: FontWeight.w700);
|
|
return Padding(
|
|
key: scheduleRowKey(id),
|
|
padding: const EdgeInsets.fromLTRB(16, 12, 16, 8),
|
|
child: Semantics(
|
|
container: true,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
// The name, bold, with its state as a coloured pill.
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Expanded(
|
|
child: Text(scheduleDisplayName(schedule), style: title),
|
|
),
|
|
const SizedBox(width: 8),
|
|
_StatusPill(enabled: schedule.enabled),
|
|
],
|
|
),
|
|
const SizedBox(height: 8),
|
|
// Labelled facts several to a line: when, which version, next.
|
|
Wrap(
|
|
spacing: 16,
|
|
runSpacing: 6,
|
|
children: [
|
|
_Fact(
|
|
icon: Icons.schedule,
|
|
cupertinoIcon: CupertinoIcons.clock,
|
|
label: 'When',
|
|
value: scheduleRuleSummary(schedule),
|
|
),
|
|
_Fact(
|
|
icon: Icons.push_pin_outlined,
|
|
cupertinoIcon: CupertinoIcons.pin,
|
|
label: 'Version',
|
|
value: schedulePinnedVersionValue(schedule),
|
|
),
|
|
_Fact(
|
|
icon: Icons.event_outlined,
|
|
cupertinoIcon: CupertinoIcons.calendar,
|
|
label: 'Next',
|
|
value: scheduleNextDueValue(schedule),
|
|
),
|
|
],
|
|
),
|
|
if (schedule.prompt.isNotEmpty) ...[
|
|
const SizedBox(height: 8),
|
|
// The prompt it sends, as a quote under the facts.
|
|
_Quote(text: schedule.prompt, style: body),
|
|
],
|
|
const SizedBox(height: 4),
|
|
Wrap(
|
|
spacing: 8,
|
|
runSpacing: 4,
|
|
children: [
|
|
schedulePipelineTextButton(
|
|
context,
|
|
key: scheduleRowEditKey(id),
|
|
label: scheduleEditLabel,
|
|
onPressed: busy ? null : onEdit,
|
|
),
|
|
schedulePipelineTextButton(
|
|
context,
|
|
key: scheduleRowToggleKey(id),
|
|
label: schedule.enabled
|
|
? schedulePauseLabel
|
|
: scheduleEnableLabel,
|
|
onPressed: busy ? null : onToggle,
|
|
),
|
|
schedulePipelineTextButton(
|
|
context,
|
|
key: scheduleRowDeleteKey(id),
|
|
label: scheduleDeleteLabel,
|
|
onPressed: busy ? null : onDelete,
|
|
),
|
|
],
|
|
),
|
|
if (error case final text?)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 4),
|
|
child: Semantics(
|
|
liveRegion: true,
|
|
child: Text(
|
|
text,
|
|
key: scheduleRowErrorKey(id),
|
|
style: schedulePipelineErrorStyle(context),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Enabled (green) or Paused (grey).
|
|
class _StatusPill extends StatelessWidget {
|
|
const _StatusPill({required this.enabled});
|
|
|
|
final bool enabled;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cupertino = usesCupertinoHost(context);
|
|
final color = enabled
|
|
? (cupertino
|
|
? CupertinoColors.systemGreen.resolveFrom(context)
|
|
: Colors.green.shade700)
|
|
: (cupertino
|
|
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
|
: Theme.of(context).colorScheme.onSurfaceVariant);
|
|
return DecoratedBox(
|
|
decoration: ShapeDecoration(
|
|
color: color.withValues(alpha: 0.14),
|
|
shape: const StadiumBorder(),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
|
child: Text(
|
|
enabled ? 'Enabled' : 'Paused',
|
|
style: TextStyle(
|
|
color: color,
|
|
fontWeight: FontWeight.w700,
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// One labelled fact: an icon, a bold label and its value.
|
|
class _Fact extends StatelessWidget {
|
|
const _Fact({
|
|
required this.icon,
|
|
required this.cupertinoIcon,
|
|
required this.label,
|
|
required this.value,
|
|
});
|
|
|
|
final IconData icon;
|
|
final IconData cupertinoIcon;
|
|
final String label;
|
|
final String value;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final muted = schedulePipelineMutedStyle(context);
|
|
final cupertino = usesCupertinoHost(context);
|
|
return Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(cupertino ? cupertinoIcon : icon, size: 16, color: muted?.color),
|
|
const SizedBox(width: 4),
|
|
Text('$label ', style: muted?.copyWith(fontWeight: FontWeight.w700)),
|
|
Flexible(child: Text(value, style: muted)),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
/// The schedule's prompt as a quote: a side bar and up to three lines.
|
|
class _Quote extends StatelessWidget {
|
|
const _Quote({required this.text, required this.style});
|
|
|
|
final String text;
|
|
final TextStyle? style;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final line = usesCupertinoHost(context)
|
|
? CupertinoColors.separator.resolveFrom(context)
|
|
: Theme.of(context).colorScheme.outlineVariant;
|
|
return DecoratedBox(
|
|
decoration: BoxDecoration(
|
|
border: Border(left: BorderSide(color: line, width: 3)),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsetsDirectional.only(start: 10),
|
|
child: Text(
|
|
text,
|
|
maxLines: 3,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: style,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|