Files
pipelines/app/lib/ui/layout/section_heading.dart
T

117 lines
3.4 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../adaptive/host.dart';
/// The look every section title shares: a quiet, grouped-list label rather than
/// another filled row.
class SectionHeadingStyle {
const SectionHeadingStyle({
required this.background,
required this.body,
required this.accent,
required this.title,
required this.line,
});
final Color background;
/// The page surface used behind pinned headings and section content.
final Color body;
final Color accent;
final TextStyle title;
final Color line;
static SectionHeadingStyle of(BuildContext context) {
if (usesCupertinoHost(context)) {
final theme = CupertinoTheme.of(context);
final base = theme.textTheme.textStyle;
// The detail pages (run, stage, pipeline) are flat on the page colour,
// as on Material, so a pinned heading's scrim is the page itself rather
// than a grey grouped band (black in dark mode).
final page = theme.scaffoldBackgroundColor;
return SectionHeadingStyle(
background: page,
body: page,
accent: CupertinoTheme.of(context).primaryColor,
title: base.copyWith(
fontSize: 13,
fontWeight: FontWeight.w600,
letterSpacing: 0.4,
color: CupertinoColors.secondaryLabel.resolveFrom(context),
),
line: CupertinoColors.separator.resolveFrom(context),
);
}
final scheme = Theme.of(context).colorScheme;
return SectionHeadingStyle(
background: scheme.surface,
body: scheme.surface,
accent: scheme.primary,
title: (Theme.of(context).textTheme.labelLarge ?? const TextStyle())
.copyWith(
fontWeight: FontWeight.w600,
letterSpacing: 0.4,
color: scheme.onSurfaceVariant,
),
line: scheme.outlineVariant,
);
}
}
/// A section title strip: [title], then any [trailing] controls.
class SectionHeading extends StatelessWidget {
const SectionHeading({
super.key,
required this.title,
this.leading,
this.trailing = const [],
this.titleColor,
this.padding = const EdgeInsetsDirectional.only(start: 12, end: 8),
this.minHeight = 40,
this.header = false,
});
final String title;
final Widget? leading;
final List<Widget> trailing;
final Color? titleColor;
final EdgeInsetsGeometry padding;
final double minHeight;
/// Announces the title as a heading to assistive tech (the trailing
/// controls stay separate nodes).
final bool header;
@override
Widget build(BuildContext context) {
final style = SectionHeadingStyle.of(context);
return ConstrainedBox(
constraints: BoxConstraints(minHeight: minHeight),
child: Padding(
padding: padding,
child: Row(
children: [
if (leading != null) ...[leading!, const SizedBox(width: 8)],
Expanded(
child: Semantics(
header: header,
container: header,
child: Text(
title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: titleColor == null
? style.title
: style.title.copyWith(color: titleColor),
),
),
),
...trailing,
],
),
),
);
}
}