199 lines
5.6 KiB
Dart
199 lines
5.6 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../ui/adaptive/host.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;
|
|
|
|
/// Standard platform activity indicator with an accessible status label.
|
|
class PipelineProgress extends StatelessWidget {
|
|
const PipelineProgress({super.key, this.label = 'Loading'});
|
|
|
|
final String label;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Semantics(
|
|
label: label,
|
|
liveRegion: true,
|
|
child: useCupertinoControls(context)
|
|
? const CupertinoActivityIndicator()
|
|
: const CircularProgressIndicator(),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// A standard text action in the current platform's style.
|
|
class PipelineTextButton extends StatelessWidget {
|
|
const PipelineTextButton({
|
|
super.key,
|
|
required this.label,
|
|
required this.onPressed,
|
|
});
|
|
|
|
final String label;
|
|
final VoidCallback? onPressed;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (useCupertinoControls(context)) {
|
|
return CupertinoButton(
|
|
padding: EdgeInsets.zero,
|
|
onPressed: onPressed,
|
|
child: Text(label),
|
|
);
|
|
}
|
|
return TextButton(onPressed: onPressed, child: Text(label));
|
|
}
|
|
}
|
|
|
|
/// Native back affordance used by the narrow list/detail layout.
|
|
class PipelineBackButton extends StatelessWidget {
|
|
const PipelineBackButton({super.key, required this.onPressed});
|
|
|
|
final VoidCallback onPressed;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (useCupertinoControls(context)) {
|
|
return Semantics(
|
|
button: true,
|
|
label: 'Back to pipelines',
|
|
child: CupertinoButton(
|
|
padding: EdgeInsets.zero,
|
|
onPressed: onPressed,
|
|
child: const Icon(CupertinoIcons.back),
|
|
),
|
|
);
|
|
}
|
|
return IconButton(
|
|
tooltip: 'Back to pipelines',
|
|
onPressed: onPressed,
|
|
icon: const Icon(Icons.arrow_back),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// The list's sort control: a Material menu on Android/desktop, an action
|
|
/// sheet on iOS. The label is the current choice, exactly as on web.
|
|
class PipelineSortButton extends StatelessWidget {
|
|
const PipelineSortButton({
|
|
super.key,
|
|
required this.sort,
|
|
required this.onSelected,
|
|
this.icon = false,
|
|
});
|
|
|
|
final PipelineSort sort;
|
|
final ValueChanged<PipelineSort> onSelected;
|
|
|
|
/// An app-bar icon instead of a labelled button.
|
|
final bool icon;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final label = 'Sort: ${sort.label}';
|
|
if (useCupertinoControls(context)) {
|
|
return Semantics(
|
|
button: true,
|
|
label: icon ? 'Sort pipelines: ${sort.label}' : null,
|
|
excludeSemantics: icon,
|
|
child: CupertinoButton(
|
|
padding: icon
|
|
? const EdgeInsets.symmetric(horizontal: 6)
|
|
: EdgeInsets.zero,
|
|
onPressed: () => _showCupertinoSheet(context),
|
|
child: icon
|
|
? const Icon(CupertinoIcons.arrow_up_arrow_down)
|
|
: Text(label),
|
|
),
|
|
);
|
|
}
|
|
return MenuAnchor(
|
|
menuChildren: [
|
|
for (final option in PipelineSort.values)
|
|
MenuItemButton(
|
|
onPressed: () => onSelected(option),
|
|
child: Text(option.label),
|
|
),
|
|
],
|
|
builder: (context, menu, child) => icon
|
|
? IconButton(
|
|
tooltip: 'Sort pipelines: ${sort.label}',
|
|
onPressed: () => menu.isOpen ? menu.close() : menu.open(),
|
|
icon: const Icon(Icons.sort),
|
|
)
|
|
: TextButton(
|
|
onPressed: () => menu.isOpen ? menu.close() : menu.open(),
|
|
child: Text(label),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _showCupertinoSheet(BuildContext context) {
|
|
return showCupertinoModalPopup<void>(
|
|
context: context,
|
|
builder: (sheetContext) => CupertinoActionSheet(
|
|
title: const Text('Sort pipelines'),
|
|
actions: [
|
|
for (final option in PipelineSort.values)
|
|
CupertinoActionSheetAction(
|
|
onPressed: () {
|
|
Navigator.of(sheetContext).pop();
|
|
onSelected(option);
|
|
},
|
|
child: Text(option.label),
|
|
),
|
|
],
|
|
cancelButton: CupertinoActionSheetAction(
|
|
isDefaultAction: true,
|
|
onPressed: () => Navigator.of(sheetContext).pop(),
|
|
child: const Text('Cancel'),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// A truthful, non-blocking error line with an optional retry action.
|
|
class PipelineErrorBanner extends StatelessWidget {
|
|
const PipelineErrorBanner({
|
|
super.key,
|
|
required this.message,
|
|
this.retryLabel = 'Retry',
|
|
this.onRetry,
|
|
});
|
|
|
|
final String message;
|
|
final String retryLabel;
|
|
final VoidCallback? onRetry;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cupertino = useCupertinoControls(context);
|
|
final color = cupertino
|
|
? CupertinoColors.systemRed.resolveFrom(context)
|
|
: Theme.of(context).colorScheme.error;
|
|
return Semantics(
|
|
liveRegion: true,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(message, style: TextStyle(color: color)),
|
|
if (onRetry != null)
|
|
PipelineTextButton(label: retryLabel, onPressed: onRetry),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|