import "package:flutter/widgets.dart"; import "surface.dart"; import "theme/garage_theme.dart"; import "theme/theme_data.dart"; /// The heading a page wears above its content. /// /// The name a step up, a muted line under it saying what youre looking at, /// both left aligned on the same margin as whatever follows. Promoted out of /// the hub, where it was drawn over every section, because A&A's licence page /// wanted the same thing and a lookalike drifts from the real one within a day /// of being written. /// /// Its a heading, not a bar - nothing chrome coloured, no rule under it, no /// height of its own beyond what the two lines need. A pane that wants a strip /// across the top of it wants [ChromeBar] instead. class PageHeading extends StatelessWidget { /// How tall this comes out, for a page that needs to know what room is /// left under it. /// /// Derived rather than measured: title on [Density.textLg] over a subtitle /// on the ambient font, both on Geist's own line box, with a gapXs between. /// A layout that has to wait for a frame to find this out cant use it on /// the frame it needs it. static double heightIn(Density d) => (d.textLg * Density.geistLineRatio).roundToDouble() + d.gapXs + (d.fontSize * Density.geistLineRatio).roundToDouble(); const PageHeading({ required this.title, this.subtitle, this.trailing, super.key, }); final String title; final String? subtitle; /// Sits at the far end of the heading, vertically centred on the whole /// block rather than on the title line. /// /// For the one action that belongs to the SUBJECT rather than to a section /// of it - Disconnect on an agent, and the like. final Widget? trailing; @override Widget build(BuildContext context) { final theme = GarageTheme.of(context); final density = theme.density; final heading = Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Text(title, style: theme.typography.normal).large(), if (subtitle != null) ...[ const Gap.xs(), Text( subtitle!, style: TextStyle(color: theme.colorScheme.mutedForeground), ), ], ], ); // Nudged in by gapXs: thats the side margin a PropertiesSection carries on // itself, and without it a heading starts LEFT of the sections it // introduces - the sort of thing you cant unsee once youve seen it. return Padding( padding: EdgeInsets.symmetric(horizontal: density.gapXs), child: trailing == null ? heading : Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded(child: heading), Gap(density.gapMd), trailing!, ], ), ); } }