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

112 lines
3.3 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../adaptive/host.dart';
/// The look every section title shares, so it reads as a divider and not as
/// another row: a tinted strip with an accent bar, a bold title and a hairline
/// underneath.
class SectionHeadingStyle {
const SectionHeadingStyle({
required this.background,
required this.body,
required this.accent,
required this.title,
required this.line,
});
final Color background;
/// The surface under a section's content: between the page and the title,
/// so the content reads as belonging to its section.
final Color body;
final Color accent;
final TextStyle title;
final Color line;
static SectionHeadingStyle of(BuildContext context) {
if (usesCupertinoHost(context)) {
final base = CupertinoTheme.of(context).textTheme.textStyle;
return SectionHeadingStyle(
background: CupertinoColors.tertiarySystemGroupedBackground.resolveFrom(
context,
),
body: CupertinoColors.secondarySystemGroupedBackground.resolveFrom(
context,
),
accent: CupertinoTheme.of(context).primaryColor,
title: base.copyWith(
fontWeight: FontWeight.w700,
color: CupertinoColors.label.resolveFrom(context),
),
line: CupertinoColors.separator.resolveFrom(context),
);
}
final scheme = Theme.of(context).colorScheme;
return SectionHeadingStyle(
background: scheme.surfaceContainerHighest,
body: scheme.surfaceContainerLow,
accent: scheme.primary,
title: (Theme.of(context).textTheme.titleSmall ?? const TextStyle())
.copyWith(fontWeight: FontWeight.w700, color: scheme.onSurface),
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,
});
final String title;
final Widget? leading;
final List<Widget> trailing;
final Color? titleColor;
final EdgeInsetsGeometry padding;
final double minHeight;
@override
Widget build(BuildContext context) {
final style = SectionHeadingStyle.of(context);
return DecoratedBox(
decoration: BoxDecoration(
color: style.background,
border: Border(
left: BorderSide(color: style.accent, width: 3),
bottom: BorderSide(color: style.line, width: 0.5),
),
),
child: ConstrainedBox(
constraints: BoxConstraints(minHeight: minHeight),
child: Padding(
padding: padding,
child: Row(
children: [
if (leading != null) ...[leading!, const SizedBox(width: 8)],
Expanded(
child: Text(
title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: titleColor == null
? style.title
: style.title.copyWith(color: titleColor),
),
),
...trailing,
],
),
),
),
);
}
}