e43cc867f9
Shared AppSheetHeader (title + Done) for the Runs filter/sort and Needs you sheets; Runs filter single-choice groups as check rows and statuses in sentence case; Cupertino decision options as a check list; run action sheet titled with the run; usage page without the duplicate title and with honest empty states; Settings Reconnect wording, compact notifications row and a tinted Cupertino Save workspace; friendly artifact preview failures with Retry.
107 lines
3.4 KiB
Dart
107 lines
3.4 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../adaptive/host.dart';
|
|
|
|
/// The label of every sheet's close action.
|
|
const appSheetDoneLabel = 'Done';
|
|
|
|
/// The app's one sheet header: the sheet's [title] at the start, then any
|
|
/// extra [actions] (Clear all), then Done, which closes the sheet.
|
|
///
|
|
/// Material shows the title in `titleLarge` and a [TextButton]; Cupertino
|
|
/// shows the navigation title style and a bold [CupertinoButton], like a
|
|
/// modal's navigation bar. The title is a header that names the route, so a
|
|
/// screen reader announces the sheet by it. Nothing has a fixed height and the
|
|
/// title wraps at large text. Used by the Runs filter and sort sheets and the
|
|
/// Needs you sheet, so every sheet closes the same way, not only by its drag
|
|
/// handle.
|
|
class AppSheetHeader extends StatelessWidget {
|
|
const AppSheetHeader({
|
|
super.key,
|
|
required this.title,
|
|
this.actions = const [],
|
|
this.onDone,
|
|
this.doneKey,
|
|
this.cupertino,
|
|
});
|
|
|
|
final String title;
|
|
|
|
/// Controls before Done, in the host's style.
|
|
final List<Widget> actions;
|
|
|
|
/// Closes the sheet; the default pops the route the header is in.
|
|
final VoidCallback? onDone;
|
|
final Key? doneKey;
|
|
|
|
/// Overrides the host detection.
|
|
final bool? cupertino;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cupertino = this.cupertino ?? usesCupertinoHost(context);
|
|
final done = onDone ?? () => Navigator.of(context).maybePop();
|
|
final titleStyle = cupertino
|
|
? CupertinoTheme.of(context).textTheme.navTitleTextStyle
|
|
: Theme.of(context).textTheme.titleLarge;
|
|
final Widget doneButton = cupertino
|
|
? CupertinoButton(
|
|
key: doneKey,
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
minimumSize: const Size.square(kMinInteractiveDimensionCupertino),
|
|
onPressed: done,
|
|
child: const Text(
|
|
appSheetDoneLabel,
|
|
style: TextStyle(fontWeight: FontWeight.w600),
|
|
),
|
|
)
|
|
: TextButton(
|
|
key: doneKey,
|
|
onPressed: done,
|
|
child: const Text(appSheetDoneLabel),
|
|
);
|
|
return Padding(
|
|
padding: EdgeInsetsDirectional.fromSTEB(
|
|
cupertino ? 20 : 24,
|
|
cupertino ? 8 : 0,
|
|
8,
|
|
4,
|
|
),
|
|
child: LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
final heading = Expanded(
|
|
child: Semantics(
|
|
header: true,
|
|
namesRoute: true,
|
|
child: Text(title, style: titleStyle),
|
|
),
|
|
);
|
|
// A narrow sheet at large text moves the extra actions to a line
|
|
// of their own under the title, so nothing is squeezed off.
|
|
final narrow =
|
|
constraints.maxWidth <
|
|
MediaQuery.textScalerOf(context).scale(_wideHeaderWidth);
|
|
if (actions.isEmpty || !narrow) {
|
|
return Row(children: [heading, ...actions, doneButton]);
|
|
}
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Row(children: [heading, doneButton]),
|
|
Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: Wrap(children: actions),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Below this width (scaled with the text) the extra actions wrap under the
|
|
/// title.
|
|
const double _wideHeaderWidth = 360;
|