Files
pipelines/app/lib/features/pipelines/widgets/pipeline_scope_control.dart
T
alan d1b05217c9 Remove Cupertino pipeline branches
Keep the pipeline feature on its existing Material path because the app runs under MaterialApp and never selects Cupertino hosts. Preserve public cupertino parameters and required Cupertino icon values for later cleanup and shared controls.
2026-11-11 04:53:12 +00:00

80 lines
2.4 KiB
Dart

import 'package:flutter/material.dart';
/// The list's scope: every active pipeline, only scheduled ones, or the
/// archived pipelines (which the other two never show).
enum PipelineScope {
all('All'),
scheduled('Scheduled'),
archived('Archived');
const PipelineScope(this.label);
final String label;
}
/// Uses a standard dropdown when the segmented labels cannot fit at the user's
/// text scale. The decision is content-measured, not a fixed pane width.
class PipelineScopeControl extends StatelessWidget {
const PipelineScopeControl({
super.key,
required this.scope,
required this.onSelected,
});
final PipelineScope scope;
final ValueChanged<PipelineScope> onSelected;
static final labels = {
for (final scope in PipelineScope.values) scope: scope.label,
};
@override
Widget build(BuildContext context) {
final style = Theme.of(context).textTheme.labelLarge;
var requiredWidth = kMinInteractiveDimension * labels.length;
for (final label in labels.values) {
final painter = TextPainter(
text: TextSpan(text: label, style: style),
textDirection: Directionality.of(context),
textScaler: MediaQuery.textScalerOf(context),
)..layout();
requiredWidth += painter.width;
painter.dispose();
}
return LayoutBuilder(
builder: (context, constraints) {
if (constraints.maxWidth >= requiredWidth) {
return SegmentedButton<PipelineScope>(
key: const Key('pipeline-scope'),
showSelectedIcon: false,
segments: [
for (final entry in labels.entries)
ButtonSegment(value: entry.key, label: Text(entry.value)),
],
selected: {scope},
onSelectionChanged: (value) => onSelected(value.single),
);
}
return DropdownButton<PipelineScope>(
key: const Key('pipeline-scope'),
value: scope,
isExpanded: true,
items: [
for (final entry in labels.entries)
DropdownMenuItem(
value: entry.key,
child: Text(
entry.value,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
onChanged: (value) {
if (value != null) onSelected(value);
},
);
},
);
}
}