Narrow list panes: readable bar title, More overflow menu, rows keep status and actions
The floating bar keeps the title at its own width (up to half the bar) and moves overflowable actions into one More menu instead of squeezing them below their touch targets. List rows keep their leading status avatar and More actions at any list-pane width; the time moves under the subtitle.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import '../../../../ui/adaptive/segmented_bar_overflow.dart';
|
||||
import '../../../../ui/theme/app_theme.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -13,7 +14,7 @@ ChatControlsStyle chatControlsStyleOf(BuildContext context) =>
|
||||
? ChatControlsStyle.cupertino
|
||||
: ChatControlsStyle.material;
|
||||
|
||||
class ChatBarAction extends StatelessWidget {
|
||||
class ChatBarAction extends StatelessWidget implements SegmentedOverflowable {
|
||||
const ChatBarAction({
|
||||
super.key,
|
||||
required this.label,
|
||||
@@ -27,6 +28,14 @@ class ChatBarAction extends StatelessWidget {
|
||||
final IconData materialIcon;
|
||||
final IconData cupertinoIcon;
|
||||
|
||||
/// A narrow bar moves it into its More menu, under the bar's host's icon.
|
||||
@override
|
||||
SegmentedOverflowEntry get overflowEntry => SegmentedOverflowEntry(
|
||||
label: label,
|
||||
icon: materialIcon,
|
||||
onPressed: onPressed,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
|
||||
|
||||
@@ -62,7 +62,6 @@ class ChatSessionRow extends StatelessWidget {
|
||||
selected: selected,
|
||||
emphasized: unread,
|
||||
divider: divider,
|
||||
keepMenuWhenCompact: true,
|
||||
onTap: () => onOpen(session),
|
||||
onLongPress: onLongPress,
|
||||
accent: chatColorShade(context, chatSessionColor(session)),
|
||||
|
||||
@@ -327,24 +327,14 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
|
||||
Widget _settingsButton(BuildContext context) =>
|
||||
pipelineSettingsButton(context, widget.onOpenSettings);
|
||||
|
||||
Widget _refreshButton(BuildContext context) {
|
||||
if (useCupertinoControls(context)) {
|
||||
return Semantics(
|
||||
button: true,
|
||||
label: 'Refresh',
|
||||
child: CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: _controller.load,
|
||||
child: const Icon(CupertinoIcons.refresh),
|
||||
),
|
||||
);
|
||||
}
|
||||
return IconButton(
|
||||
tooltip: 'Refresh',
|
||||
onPressed: _controller.load,
|
||||
icon: const Icon(Icons.refresh),
|
||||
);
|
||||
}
|
||||
Widget _refreshButton(BuildContext context) => pipelineBarIconButton(
|
||||
context,
|
||||
key: const Key('pipelines-refresh'),
|
||||
label: 'Refresh',
|
||||
icon: Icons.refresh,
|
||||
cupertinoIcon: CupertinoIcons.refresh,
|
||||
onPressed: _controller.load,
|
||||
);
|
||||
|
||||
Widget _materialShell(BuildContext context, Widget body) {
|
||||
return Scaffold(
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/adaptive/segmented_bar_overflow.dart';
|
||||
import 'pipeline_controls.dart';
|
||||
|
||||
/// One icon action in the Pipelines bar's actions pill: a Material
|
||||
/// [IconButton] with its tooltip, or a Cupertino button named for
|
||||
/// accessibility.
|
||||
/// accessibility. A narrow bar moves it into its More menu.
|
||||
Widget pipelineBarIconButton(
|
||||
BuildContext context, {
|
||||
required Key key,
|
||||
@@ -15,7 +16,8 @@ Widget pipelineBarIconButton(
|
||||
required VoidCallback? onPressed,
|
||||
}) {
|
||||
final Widget button;
|
||||
if (useCupertinoControls(context)) {
|
||||
final cupertino = useCupertinoControls(context);
|
||||
if (cupertino) {
|
||||
button = CupertinoButton(
|
||||
key: key,
|
||||
padding: EdgeInsets.zero,
|
||||
@@ -30,10 +32,17 @@ Widget pipelineBarIconButton(
|
||||
icon: Icon(icon),
|
||||
);
|
||||
}
|
||||
return Semantics(
|
||||
button: true,
|
||||
label: label,
|
||||
child: ExcludeSemantics(child: button),
|
||||
return SegmentedOverflowAction(
|
||||
overflowEntry: SegmentedOverflowEntry(
|
||||
label: label,
|
||||
icon: cupertino ? cupertinoIcon : icon,
|
||||
onPressed: onPressed,
|
||||
),
|
||||
child: Semantics(
|
||||
button: true,
|
||||
label: label,
|
||||
child: ExcludeSemantics(child: button),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../shell/shell_list_shortcuts.dart';
|
||||
import '../../../ui/adaptive/floating_bar_layout.dart';
|
||||
import '../../../ui/adaptive/segmented_bar_overflow.dart';
|
||||
import '../../../ui/status/run_status_icon.dart';
|
||||
import '../pipeline_format.dart';
|
||||
import '../pipeline_models.dart';
|
||||
@@ -322,7 +323,13 @@ List<Widget> pipelineListActions(
|
||||
final label = filters.count == 0
|
||||
? 'Filter pipelines'
|
||||
: '${filters.count} active ${filters.count == 1 ? 'filter' : 'filters'}';
|
||||
final filter = useCupertinoControls(context)
|
||||
final cupertino = useCupertinoControls(context);
|
||||
final filterIcon = cupertino
|
||||
? (filters.count > 0
|
||||
? CupertinoIcons.line_horizontal_3_decrease_circle_fill
|
||||
: CupertinoIcons.line_horizontal_3_decrease_circle)
|
||||
: (filters.count > 0 ? Icons.filter_alt : Icons.filter_alt_outlined);
|
||||
final filter = cupertino
|
||||
? Semantics(
|
||||
button: true,
|
||||
label: label,
|
||||
@@ -332,11 +339,7 @@ List<Widget> pipelineListActions(
|
||||
padding: EdgeInsets.zero,
|
||||
minimumSize: const Size.square(kMinInteractiveDimensionCupertino),
|
||||
onPressed: openFilters,
|
||||
child: Icon(
|
||||
filters.count > 0
|
||||
? CupertinoIcons.line_horizontal_3_decrease_circle_fill
|
||||
: CupertinoIcons.line_horizontal_3_decrease_circle,
|
||||
),
|
||||
child: Icon(filterIcon),
|
||||
),
|
||||
)
|
||||
: IconButton(
|
||||
@@ -344,17 +347,38 @@ List<Widget> pipelineListActions(
|
||||
tooltip: label,
|
||||
isSelected: filters.count > 0,
|
||||
onPressed: openFilters,
|
||||
icon: Icon(
|
||||
filters.count > 0 ? Icons.filter_alt : Icons.filter_alt_outlined,
|
||||
),
|
||||
icon: Icon(filterIcon),
|
||||
);
|
||||
// A narrow bar moves either into its More menu; sorting is then a
|
||||
// submenu (Material) or a second action sheet (Cupertino).
|
||||
return [
|
||||
filter,
|
||||
PipelineSortButton(
|
||||
key: const Key('pipeline-sort'),
|
||||
sort: controller.sort,
|
||||
onSelected: controller.setSort,
|
||||
icon: true,
|
||||
SegmentedOverflowAction(
|
||||
overflowEntry: SegmentedOverflowEntry(
|
||||
label: label,
|
||||
icon: filterIcon,
|
||||
onPressed: openFilters,
|
||||
),
|
||||
child: filter,
|
||||
),
|
||||
SegmentedOverflowAction(
|
||||
overflowEntry: SegmentedOverflowEntry(
|
||||
label: 'Sort pipelines: ${controller.sort.label}',
|
||||
icon: cupertino ? CupertinoIcons.arrow_up_arrow_down : Icons.sort,
|
||||
choices: [
|
||||
for (final option in PipelineSort.values)
|
||||
SegmentedMenuChoice(
|
||||
label: option.label,
|
||||
selected: option == controller.sort,
|
||||
onSelected: () => controller.setSort(option),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: PipelineSortButton(
|
||||
key: const Key('pipeline-sort'),
|
||||
sort: controller.sort,
|
||||
onSelected: controller.setSort,
|
||||
icon: true,
|
||||
),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -113,8 +113,8 @@ class RunListRow extends StatelessWidget {
|
||||
: RelativeTimeLabel(instant: createdAt, now: now),
|
||||
subtitle: Text(subtitle),
|
||||
compactSubtitle: Text(compactSubtitle),
|
||||
// A narrow list pane beside the open run leaves the row no room for a
|
||||
// second control; the open run's detail beside it carries the same menu.
|
||||
// Kept in a narrow list pane too, so every run's actions stay one tap
|
||||
// away from the list.
|
||||
menu:
|
||||
!selecting &&
|
||||
gateway != null &&
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../../../ui/adaptive/segmented_bar_overflow.dart';
|
||||
import '../../../ui/layout/app_sheet_header.dart';
|
||||
import '../../pipelines/pipeline_format.dart' show runStateLabel;
|
||||
import 'runs_controller.dart';
|
||||
@@ -160,8 +161,9 @@ class RunsBarActions {
|
||||
VoidCallback onPressed, {
|
||||
bool active = false,
|
||||
}) {
|
||||
final Widget button;
|
||||
if (cupertino) {
|
||||
return Semantics(
|
||||
button = Semantics(
|
||||
button: true,
|
||||
label: label,
|
||||
excludeSemantics: true,
|
||||
@@ -175,13 +177,23 @@ class RunsBarActions {
|
||||
child: Icon(ios),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
button = IconButton(
|
||||
key: key,
|
||||
tooltip: label,
|
||||
isSelected: active,
|
||||
onPressed: onPressed,
|
||||
icon: Icon(material),
|
||||
);
|
||||
}
|
||||
return IconButton(
|
||||
key: key,
|
||||
tooltip: label,
|
||||
isSelected: active,
|
||||
onPressed: onPressed,
|
||||
icon: Icon(material),
|
||||
// A narrow bar moves it into its More menu.
|
||||
return SegmentedOverflowAction(
|
||||
overflowEntry: SegmentedOverflowEntry(
|
||||
label: label,
|
||||
icon: cupertino ? ios : material,
|
||||
onPressed: onPressed,
|
||||
),
|
||||
child: button,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../../../ui/adaptive/segmented_bar_overflow.dart';
|
||||
import '../../../ui/layout/section_heading.dart';
|
||||
import '../actions/delete_runs_action.dart';
|
||||
import '../domain/run_deletion.dart';
|
||||
@@ -24,29 +25,39 @@ ValueKey<String> runsDaySelectKey(String day) =>
|
||||
/// The Runs bar's `Select` action, entering multi-select.
|
||||
Widget runsSelectAction(BuildContext context, RunsController controller) {
|
||||
void enter() => controller.selection.enter();
|
||||
if (usesCupertinoHost(context)) {
|
||||
return Semantics(
|
||||
button: true,
|
||||
final cupertino = usesCupertinoHost(context);
|
||||
// A narrow bar moves it into its More menu.
|
||||
return SegmentedOverflowAction(
|
||||
overflowEntry: SegmentedOverflowEntry(
|
||||
label: 'Select',
|
||||
excludeSemantics: true,
|
||||
onTap: enter,
|
||||
child: CupertinoButton(
|
||||
key: runsSelectKey,
|
||||
padding: EdgeInsets.zero,
|
||||
minimumSize: const Size.square(kMinInteractiveDimensionCupertino),
|
||||
onPressed: enter,
|
||||
child: const Icon(CupertinoIcons.checkmark_circle),
|
||||
),
|
||||
);
|
||||
}
|
||||
return IconButton(
|
||||
key: runsSelectKey,
|
||||
tooltip: 'Select',
|
||||
onPressed: enter,
|
||||
icon: const Icon(Icons.checklist),
|
||||
icon: cupertino ? CupertinoIcons.checkmark_circle : Icons.checklist,
|
||||
onPressed: enter,
|
||||
),
|
||||
child: cupertino
|
||||
? _selectButtonCupertino(enter)
|
||||
: IconButton(
|
||||
key: runsSelectKey,
|
||||
tooltip: 'Select',
|
||||
onPressed: enter,
|
||||
icon: const Icon(Icons.checklist),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _selectButtonCupertino(VoidCallback enter) => Semantics(
|
||||
button: true,
|
||||
label: 'Select',
|
||||
excludeSemantics: true,
|
||||
onTap: enter,
|
||||
child: CupertinoButton(
|
||||
key: runsSelectKey,
|
||||
padding: EdgeInsets.zero,
|
||||
minimumSize: const Size.square(kMinInteractiveDimensionCupertino),
|
||||
onPressed: enter,
|
||||
child: const Icon(CupertinoIcons.checkmark_circle),
|
||||
),
|
||||
);
|
||||
|
||||
/// What the bar shows in select mode: `N selected` over the selection's size,
|
||||
/// then Delete and Done.
|
||||
({String title, String? subtitle, List<Widget> actions}) runsSelectionBar(
|
||||
|
||||
@@ -52,7 +52,6 @@ class SchedulePipelineRow extends StatelessWidget {
|
||||
'${scheduleRuleSummary(schedule)}',
|
||||
),
|
||||
// A narrow Summary still needs a way to pause or delete.
|
||||
keepMenuWhenCompact: true,
|
||||
menu: AppOverflowMenu<_ScheduleAction>(
|
||||
key: scheduleRowMenuKey(id),
|
||||
cupertino: cupertino,
|
||||
|
||||
@@ -0,0 +1,289 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// A bar's actions in one row, each at its natural width, with a trailing
|
||||
/// [more] button that shows only when they do not all fit.
|
||||
///
|
||||
/// When the actions are wider than [overflowWidth] (the room the bar leaves
|
||||
/// them beside a readable title), the [overflowable] ones leave the row from
|
||||
/// its trailing end until the rest and [more] fit in it, so
|
||||
/// every action left keeps its own (touch-target) width instead of being
|
||||
/// squeezed. [onHidden] hears which actions left (by index) after a layout
|
||||
/// that changes them, so the bar can list them in its More menu. Only when
|
||||
/// the actions that stay are wider than the row may be at all (a long model
|
||||
/// name, which cannot move) does the first of them shrink, as a [Flexible]
|
||||
/// would, so the row never overflows.
|
||||
class SegmentedActionRow extends MultiChildRenderObjectWidget {
|
||||
SegmentedActionRow({
|
||||
super.key,
|
||||
required List<Widget> actions,
|
||||
required Widget more,
|
||||
required this.overflowable,
|
||||
required this.overflowWidth,
|
||||
required this.onHidden,
|
||||
}) : assert(actions.length == overflowable.length),
|
||||
super(children: [...actions, more]);
|
||||
|
||||
/// Whether each action may move into the More menu.
|
||||
final List<bool> overflowable;
|
||||
|
||||
/// Past this width, [overflowable] actions move into the More menu.
|
||||
final double overflowWidth;
|
||||
final ValueChanged<List<int>> onHidden;
|
||||
|
||||
@override
|
||||
RenderSegmentedActionRow createRenderObject(BuildContext context) =>
|
||||
RenderSegmentedActionRow(
|
||||
overflowable: overflowable,
|
||||
overflowWidth: overflowWidth,
|
||||
onHidden: onHidden,
|
||||
textDirection: Directionality.of(context),
|
||||
);
|
||||
|
||||
@override
|
||||
void updateRenderObject(
|
||||
BuildContext context,
|
||||
RenderSegmentedActionRow renderObject,
|
||||
) {
|
||||
renderObject
|
||||
..overflowable = overflowable
|
||||
..overflowWidth = overflowWidth
|
||||
..onHidden = onHidden
|
||||
..textDirection = Directionality.of(context);
|
||||
}
|
||||
}
|
||||
|
||||
class _ActionParentData extends ContainerBoxParentData<RenderBox> {
|
||||
bool shown = true;
|
||||
}
|
||||
|
||||
/// The render object of [SegmentedActionRow].
|
||||
class RenderSegmentedActionRow extends RenderBox
|
||||
with
|
||||
ContainerRenderObjectMixin<RenderBox, _ActionParentData>,
|
||||
RenderBoxContainerDefaultsMixin<RenderBox, _ActionParentData> {
|
||||
RenderSegmentedActionRow({
|
||||
required this._overflowable,
|
||||
required this._overflowWidth,
|
||||
required this.onHidden,
|
||||
required this._textDirection,
|
||||
});
|
||||
|
||||
List<bool> _overflowable;
|
||||
set overflowable(List<bool> value) {
|
||||
if (listEquals(value, _overflowable)) return;
|
||||
_overflowable = value;
|
||||
markNeedsLayout();
|
||||
}
|
||||
|
||||
double _overflowWidth;
|
||||
set overflowWidth(double value) {
|
||||
if (value == _overflowWidth) return;
|
||||
_overflowWidth = value;
|
||||
markNeedsLayout();
|
||||
}
|
||||
|
||||
ValueChanged<List<int>> onHidden;
|
||||
|
||||
TextDirection _textDirection;
|
||||
set textDirection(TextDirection value) {
|
||||
if (value == _textDirection) return;
|
||||
_textDirection = value;
|
||||
markNeedsLayout();
|
||||
}
|
||||
|
||||
/// What the last layout reported to [onHidden]; nothing is hidden at
|
||||
/// first, so a bar whose actions fit reports nothing.
|
||||
List<int> _reported = const [];
|
||||
|
||||
@override
|
||||
void setupParentData(RenderBox child) {
|
||||
if (child.parentData is! _ActionParentData) {
|
||||
child.parentData = _ActionParentData();
|
||||
}
|
||||
}
|
||||
|
||||
List<RenderBox> get _children {
|
||||
final list = <RenderBox>[];
|
||||
var child = firstChild;
|
||||
while (child != null) {
|
||||
list.add(child);
|
||||
child = childAfter(child);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/// Which actions show, whether More shows, and the most the first shown
|
||||
/// action may take (infinite when everything fits at its natural width).
|
||||
({List<bool> shown, bool more, double firstMax}) _plan(
|
||||
List<double> widths,
|
||||
double moreWidth,
|
||||
double maxWidth,
|
||||
) {
|
||||
final count = widths.length;
|
||||
final shown = List.filled(count, true);
|
||||
var total = widths.fold(0.0, (sum, width) => sum + width);
|
||||
var more = false;
|
||||
final soft = math.min(_overflowWidth, maxWidth);
|
||||
if (total > soft && _overflowable.contains(true)) {
|
||||
more = true;
|
||||
for (var index = count - 1; index >= 0; index--) {
|
||||
if (total + moreWidth <= soft) break;
|
||||
if (!_overflowable[index]) continue;
|
||||
shown[index] = false;
|
||||
total -= widths[index];
|
||||
}
|
||||
}
|
||||
final room = maxWidth - (more ? moreWidth : 0);
|
||||
final first = shown.indexOf(true);
|
||||
if (total <= room || first < 0) {
|
||||
return (shown: shown, more: more, firstMax: double.infinity);
|
||||
}
|
||||
return (
|
||||
shown: shown,
|
||||
more: more,
|
||||
firstMax: math.max(0, room - (total - widths[first])),
|
||||
);
|
||||
}
|
||||
|
||||
Size _layout(BoxConstraints constraints, {required bool dry}) {
|
||||
final children = _children;
|
||||
final actions = children.sublist(0, children.length - 1);
|
||||
final moreChild = children.last;
|
||||
final loose = BoxConstraints(maxHeight: constraints.maxHeight);
|
||||
Size size(RenderBox child, BoxConstraints box) => dry
|
||||
? child.getDryLayout(box)
|
||||
: (child..layout(box, parentUsesSize: true)).size;
|
||||
final sizes = [for (final child in actions) size(child, loose)];
|
||||
final moreSize = size(moreChild, loose);
|
||||
final plan = _plan(
|
||||
[for (final s in sizes) s.width],
|
||||
moreSize.width,
|
||||
constraints.maxWidth,
|
||||
);
|
||||
final first = plan.shown.indexOf(true);
|
||||
if (first >= 0 && plan.firstMax.isFinite) {
|
||||
sizes[first] = size(
|
||||
actions[first],
|
||||
loose.copyWith(maxWidth: plan.firstMax),
|
||||
);
|
||||
}
|
||||
final placed = [
|
||||
for (final (index, s) in sizes.indexed)
|
||||
if (plan.shown[index]) (actions[index], s),
|
||||
if (plan.more) (moreChild, moreSize),
|
||||
];
|
||||
final height = placed.fold(
|
||||
0.0,
|
||||
(most, entry) => math.max(most, entry.$2.height),
|
||||
);
|
||||
final width = placed.fold(0.0, (sum, entry) => sum + entry.$2.width);
|
||||
final result = constraints.constrain(Size(width, height));
|
||||
if (dry) return result;
|
||||
for (final child in children) {
|
||||
(child.parentData! as _ActionParentData).shown = false;
|
||||
}
|
||||
var x = 0.0;
|
||||
for (final (child, s) in placed) {
|
||||
final data = child.parentData! as _ActionParentData;
|
||||
data.shown = true;
|
||||
final dx = _textDirection == TextDirection.ltr
|
||||
? x
|
||||
: result.width - x - s.width;
|
||||
data.offset = Offset(dx, (result.height - s.height) / 2);
|
||||
x += s.width;
|
||||
}
|
||||
final hidden = [
|
||||
for (final (index, shown) in plan.shown.indexed)
|
||||
if (!shown) index,
|
||||
];
|
||||
if (!listEquals(hidden, _reported)) {
|
||||
_reported = hidden;
|
||||
final report = onHidden;
|
||||
// The bar rebuilds its More menu from this, which it may not do in
|
||||
// the middle of a layout.
|
||||
SchedulerBinding.instance.addPostFrameCallback((_) => report(hidden));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
void performLayout() {
|
||||
size = _layout(constraints, dry: false);
|
||||
}
|
||||
|
||||
@override
|
||||
Size computeDryLayout(covariant BoxConstraints constraints) =>
|
||||
_layout(constraints, dry: true);
|
||||
|
||||
Iterable<RenderBox> get _actionChildren =>
|
||||
_children.sublist(0, childCount - 1);
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicWidth(double height) {
|
||||
final children = _children;
|
||||
// At its narrowest: the actions that cannot move, and More.
|
||||
var width = children.last.getMinIntrinsicWidth(height);
|
||||
for (final (index, child) in _actionChildren.indexed) {
|
||||
if (!_overflowable[index]) width += child.getMinIntrinsicWidth(height);
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicWidth(double height) => _actionChildren.fold(
|
||||
0.0,
|
||||
(sum, child) => sum + child.getMaxIntrinsicWidth(height),
|
||||
);
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicHeight(double width) => _children.fold(
|
||||
0.0,
|
||||
(most, child) => math.max(most, child.getMinIntrinsicHeight(width)),
|
||||
);
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicHeight(double width) => _children.fold(
|
||||
0.0,
|
||||
(most, child) => math.max(most, child.getMaxIntrinsicHeight(width)),
|
||||
);
|
||||
|
||||
bool _shown(RenderBox child) =>
|
||||
(child.parentData! as _ActionParentData).shown;
|
||||
|
||||
@override
|
||||
void paint(PaintingContext context, Offset offset) {
|
||||
for (final child in _children) {
|
||||
if (!_shown(child)) continue;
|
||||
final data = child.parentData! as _ActionParentData;
|
||||
context.paintChild(child, offset + data.offset);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool hitTestChildren(BoxHitTestResult result, {required Offset position}) {
|
||||
for (final child in _children.reversed) {
|
||||
if (!_shown(child)) continue;
|
||||
final data = child.parentData! as _ActionParentData;
|
||||
final hit = result.addWithPaintOffset(
|
||||
offset: data.offset,
|
||||
position: position,
|
||||
hitTest: (result, transformed) =>
|
||||
child.hitTest(result, position: transformed),
|
||||
);
|
||||
if (hit) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
void visitChildrenForSemantics(RenderObjectVisitor visitor) {
|
||||
for (final child in _children) {
|
||||
if (_shown(child)) visitor(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,23 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'pop_entrance.dart';
|
||||
import 'segmented_action_row.dart';
|
||||
import 'segmented_bar_entrance.dart';
|
||||
import 'segmented_bar_overflow.dart';
|
||||
import 'segmented_bar_motion.dart';
|
||||
import 'segmented_bar_pieces.dart';
|
||||
|
||||
export 'segmented_bar_overflow.dart'
|
||||
show
|
||||
SegmentedMenuChoice,
|
||||
SegmentedOverflowAction,
|
||||
SegmentedOverflowEntry,
|
||||
SegmentedOverflowable,
|
||||
segmentedMoreKey;
|
||||
export 'segmented_bar_pieces.dart' show SegmentedBackButton, SegmentedPill;
|
||||
|
||||
/// The app's top bar: separate frosted-glass pieces floating over the page's
|
||||
@@ -17,9 +27,11 @@ export 'segmented_bar_pieces.dart' show SegmentedBackButton, SegmentedPill;
|
||||
/// Back, implied as the stock bars do when [automaticallyImplyLeading]), a
|
||||
/// pill with the [title] and an optional one-line [subtitle] that runs
|
||||
/// [onTitlePressed] when given, and a pill holding the [actions] at the
|
||||
/// trailing edge. The actions take their natural width first and the title
|
||||
/// shrinks; only when the title is down to [minTitleShare] of the bar does
|
||||
/// the first action ellipsise.
|
||||
/// trailing edge. The title keeps its own width (up to [maxTitleShare] of the
|
||||
/// bar, and never under [minTitleShare]); the actions take their natural
|
||||
/// width beside it, and those that do not fit move into one More menu
|
||||
/// (when they are [SegmentedOverflowable]) rather than shrink below their
|
||||
/// touch targets. Only actions that cannot move ellipsise the first of them.
|
||||
///
|
||||
/// A page whose bar is mainly an input (Search) passes [titleWidget] instead:
|
||||
/// it takes the title pill's place as one pill that fills the space beside
|
||||
@@ -123,9 +135,14 @@ class SegmentedBar extends StatefulWidget
|
||||
|
||||
static const double _topPadding = 8;
|
||||
|
||||
/// The share of the bar the title keeps before the actions shrink.
|
||||
/// The share of the bar the title always keeps beside the actions.
|
||||
static const double minTitleShare = 0.25;
|
||||
|
||||
/// The most of the bar the title's own width claims before the actions:
|
||||
/// a short title (a destination's name) shows whole, a long one leaves
|
||||
/// the actions room.
|
||||
static const double maxTitleShare = 0.5;
|
||||
|
||||
/// Bar text grows with the reader's setting up to this factor, like the
|
||||
/// stock app bar caps its title, so the bar never takes over the page.
|
||||
static const double maxTextScale = 2;
|
||||
@@ -262,42 +279,70 @@ class _SegmentedBarState extends State<SegmentedBar> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Which actions (by identity) a narrow bar moved into its More menu.
|
||||
Set<Object> _overflowed = const {};
|
||||
|
||||
void _hidden(List<Object> ids, List<int> indexes) {
|
||||
if (!mounted) return;
|
||||
final next = {
|
||||
for (final index in indexes)
|
||||
if (index < ids.length) ids[index],
|
||||
};
|
||||
if (setEquals(next, _overflowed)) return;
|
||||
setState(() => _overflowed = next);
|
||||
}
|
||||
|
||||
/// The actions, each keyed by its identity ([segmentedActionIds]) so one
|
||||
/// arriving or leaving leaves the others be, each popping in on its own.
|
||||
/// Only the first shrinks (ellipsises); the rest keep their natural width
|
||||
/// as inflexible (flex 0) children, up to an even share of [maxWidth] (the
|
||||
/// pill's widest): a long control (a permission mode's name beside the
|
||||
/// model) leaves room for the first, and icons in a narrow pane squeeze
|
||||
/// together rather than overflow the pill.
|
||||
List<Widget> _actionIslands(
|
||||
/// arriving or leaving leaves the others be, each popping in on its own,
|
||||
/// at its natural width. Those that do not fit leave for the trailing More
|
||||
/// button ([SegmentedActionRow]), so none is squeezed below its touch
|
||||
/// target; one moved there is out of the focus order too.
|
||||
Widget _actionRow(
|
||||
List<Widget> actions,
|
||||
List<Object> ids,
|
||||
List<SegmentedActionEntrance> entrances, {
|
||||
required bool cupertino,
|
||||
required double maxWidth,
|
||||
}) => [
|
||||
for (final (index, action) in actions.indexed)
|
||||
Flexible(
|
||||
key: ValueKey(ids[index]),
|
||||
flex: index == 0 ? 1 : 0,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: index == 0 ? double.infinity : maxWidth / actions.length,
|
||||
),
|
||||
child: PopEntrance(
|
||||
play: entrances[index].play,
|
||||
delay: entrances[index].delay,
|
||||
glass: false,
|
||||
child: SegmentedPress(
|
||||
cupertino: cupertino,
|
||||
tint: widget.foregroundColor,
|
||||
enabled: actions.length > 1,
|
||||
child: action,
|
||||
),
|
||||
),
|
||||
required double overflowWidth,
|
||||
}) {
|
||||
final entries = [
|
||||
for (final (index, action) in actions.indexed)
|
||||
if (action is SegmentedOverflowable && _overflowed.contains(ids[index]))
|
||||
(action as SegmentedOverflowable).overflowEntry,
|
||||
];
|
||||
return SegmentedActionRow(
|
||||
overflowable: [
|
||||
for (final action in actions) action is SegmentedOverflowable,
|
||||
],
|
||||
overflowWidth: overflowWidth,
|
||||
onHidden: (indexes) => _hidden(ids, indexes),
|
||||
more: ExcludeFocus(
|
||||
excluding: entries.isEmpty,
|
||||
child: SegmentedPress(
|
||||
cupertino: cupertino,
|
||||
tint: widget.foregroundColor,
|
||||
child: SegmentedMoreButton(cupertino: cupertino, entries: entries),
|
||||
),
|
||||
),
|
||||
];
|
||||
actions: [
|
||||
for (final (index, action) in actions.indexed)
|
||||
ExcludeFocus(
|
||||
key: ValueKey(ids[index]),
|
||||
excluding: _overflowed.contains(ids[index]),
|
||||
child: PopEntrance(
|
||||
play: entrances[index].play,
|
||||
delay: entrances[index].delay,
|
||||
glass: false,
|
||||
child: SegmentedPress(
|
||||
cupertino: cupertino,
|
||||
tint: widget.foregroundColor,
|
||||
enabled: actions.length > 1,
|
||||
child: action,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -349,15 +394,39 @@ class _SegmentedBarState extends State<SegmentedBar> {
|
||||
final Widget bar = LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
// The actions keep to the trailing edge at their natural width, so
|
||||
// a model name shows whole while the title has room; only past the
|
||||
// title's minimum share does the first action ellipsise.
|
||||
// a model name shows whole while the title has room. The title keeps
|
||||
// at least [SegmentedBar.minTitleShare] of the bar, and its own
|
||||
// width (a destination's name) up to [SegmentedBar.maxTitleShare];
|
||||
// actions that do not fit beside it move into the More menu.
|
||||
final width = constraints.maxWidth;
|
||||
final titleMinimum = titleWidget != null || !showTitle
|
||||
? width * SegmentedBar.minTitleShare
|
||||
: math.max(
|
||||
width * SegmentedBar.minTitleShare,
|
||||
math.min(
|
||||
segmentedTitleWidth(
|
||||
context,
|
||||
cupertino: cupertino,
|
||||
title: title,
|
||||
subtitle: subtitle,
|
||||
subtitleIcon: subtitleIcon,
|
||||
foreground: foregroundColor,
|
||||
),
|
||||
width * SegmentedBar.maxTitleShare,
|
||||
),
|
||||
);
|
||||
final besideTitle =
|
||||
width -
|
||||
(leading == null ? 0 : segmentedPieceHeight(cupertino) + 8) -
|
||||
8;
|
||||
// Actions that cannot move (a model picker) may take the room down
|
||||
// to the title's minimum share; the rest leave for the More menu
|
||||
// before the title goes under its own width.
|
||||
final actionsMaxWidth = math.max(
|
||||
0.0,
|
||||
constraints.maxWidth -
|
||||
(leading == null ? 0 : segmentedPieceHeight(cupertino) + 8) -
|
||||
8 -
|
||||
constraints.maxWidth * SegmentedBar.minTitleShare,
|
||||
besideTitle - width * SegmentedBar.minTitleShare,
|
||||
);
|
||||
final overflowWidth = math.max(0.0, besideTitle - titleMinimum);
|
||||
return Row(
|
||||
children: [
|
||||
if (leading != null) ...[
|
||||
@@ -411,15 +480,12 @@ class _SegmentedBarState extends State<SegmentedBar> {
|
||||
child: SegmentedPill(
|
||||
cupertino: cupertino,
|
||||
fill: pillColor,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: _actionIslands(
|
||||
actions,
|
||||
actionIds,
|
||||
entrances.actions,
|
||||
cupertino: cupertino,
|
||||
maxWidth: actionsMaxWidth,
|
||||
),
|
||||
child: _actionRow(
|
||||
actions,
|
||||
actionIds,
|
||||
entrances.actions,
|
||||
cupertino: cupertino,
|
||||
overflowWidth: overflowWidth,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,24 +1,34 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../motion/motion.dart';
|
||||
import 'segmented_bar_overflow.dart';
|
||||
|
||||
/// The identity of each of a bar's [actions]: its own key, or its type and
|
||||
/// place among actions of that type, within [group] (whoever supplied the
|
||||
/// actions). An action keeps its identity, and so its entrance, while the
|
||||
/// bar rebuilds; a new [group] makes every action new.
|
||||
/// bar rebuilds; a new [group] makes every action new. A
|
||||
/// [SegmentedOverflowAction] is known by the action it wraps.
|
||||
List<Object> segmentedActionIds(List<Widget> actions, Object? group) {
|
||||
final seen = <Type, int>{};
|
||||
return [
|
||||
for (final action in actions)
|
||||
(
|
||||
'segmented.action',
|
||||
group,
|
||||
action.key ??
|
||||
(
|
||||
action.runtimeType,
|
||||
seen.update(action.runtimeType, (n) => n + 1, ifAbsent: () => 0),
|
||||
),
|
||||
),
|
||||
if ((action is SegmentedOverflowAction && action.key == null
|
||||
? action.child
|
||||
: action)
|
||||
case final identity)
|
||||
(
|
||||
'segmented.action',
|
||||
group,
|
||||
identity.key ??
|
||||
(
|
||||
identity.runtimeType,
|
||||
seen.update(
|
||||
identity.runtimeType,
|
||||
(n) => n + 1,
|
||||
ifAbsent: () => 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// The key of a [SegmentedBar]'s More button, shown when its actions do not
|
||||
/// all fit.
|
||||
const segmentedMoreKey = ValueKey<String>('segmented.more');
|
||||
|
||||
/// One choice under a [SegmentedOverflowEntry] (a sort order): a submenu on
|
||||
/// Material, a second action sheet on Cupertino.
|
||||
class SegmentedMenuChoice {
|
||||
const SegmentedMenuChoice({
|
||||
required this.label,
|
||||
required this.onSelected,
|
||||
this.selected = false,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final VoidCallback onSelected;
|
||||
final bool selected;
|
||||
}
|
||||
|
||||
/// How a bar action reads in the bar's More menu once a narrow bar moves it
|
||||
/// there: its label and icon, and what choosing it does.
|
||||
class SegmentedOverflowEntry {
|
||||
const SegmentedOverflowEntry({
|
||||
required this.label,
|
||||
required this.icon,
|
||||
this.onPressed,
|
||||
this.choices = const [],
|
||||
});
|
||||
|
||||
final String label;
|
||||
final IconData icon;
|
||||
|
||||
/// What choosing the entry does; null (with no [choices]) disables it.
|
||||
final VoidCallback? onPressed;
|
||||
|
||||
/// Choices offered under the entry instead of [onPressed].
|
||||
final List<SegmentedMenuChoice> choices;
|
||||
}
|
||||
|
||||
/// A bar action the bar may move into its More menu. An action that is not
|
||||
/// [SegmentedOverflowable] always stays in the bar.
|
||||
abstract interface class SegmentedOverflowable {
|
||||
SegmentedOverflowEntry get overflowEntry;
|
||||
}
|
||||
|
||||
/// Marks any bar action as [SegmentedOverflowable]: it draws [child] in the
|
||||
/// bar and [overflowEntry] in the More menu.
|
||||
class SegmentedOverflowAction extends StatelessWidget
|
||||
implements SegmentedOverflowable {
|
||||
const SegmentedOverflowAction({
|
||||
super.key,
|
||||
required this.overflowEntry,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
@override
|
||||
final SegmentedOverflowEntry overflowEntry;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => child;
|
||||
}
|
||||
|
||||
/// The bar's More button: the host's overflow icon at the platform's touch
|
||||
/// target, opening a Material menu or a Cupertino action sheet of [entries].
|
||||
class SegmentedMoreButton extends StatelessWidget {
|
||||
const SegmentedMoreButton({
|
||||
super.key,
|
||||
required this.cupertino,
|
||||
required this.entries,
|
||||
});
|
||||
|
||||
final bool cupertino;
|
||||
final List<SegmentedOverflowEntry> entries;
|
||||
|
||||
static const String label = 'More actions';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (cupertino) {
|
||||
return Semantics(
|
||||
button: true,
|
||||
label: label,
|
||||
excludeSemantics: true,
|
||||
child: CupertinoButton(
|
||||
key: segmentedMoreKey,
|
||||
padding: EdgeInsets.zero,
|
||||
minimumSize: const Size.square(kMinInteractiveDimensionCupertino),
|
||||
onPressed: () => _showSheet(context),
|
||||
child: const Icon(CupertinoIcons.ellipsis),
|
||||
),
|
||||
);
|
||||
}
|
||||
return MenuAnchor(
|
||||
menuChildren: [
|
||||
for (final entry in entries)
|
||||
if (entry.choices.isEmpty)
|
||||
MenuItemButton(
|
||||
leadingIcon: Icon(entry.icon),
|
||||
onPressed: entry.onPressed,
|
||||
child: Text(entry.label),
|
||||
)
|
||||
else
|
||||
SubmenuButton(
|
||||
leadingIcon: Icon(entry.icon),
|
||||
menuChildren: [
|
||||
for (final choice in entry.choices)
|
||||
MenuItemButton(
|
||||
leadingIcon: Icon(
|
||||
Icons.check,
|
||||
color: choice.selected ? null : Colors.transparent,
|
||||
),
|
||||
onPressed: choice.onSelected,
|
||||
child: Semantics(
|
||||
selected: choice.selected,
|
||||
child: Text(choice.label),
|
||||
),
|
||||
),
|
||||
],
|
||||
child: Text(entry.label),
|
||||
),
|
||||
],
|
||||
builder: (context, menu, _) => IconButton(
|
||||
key: segmentedMoreKey,
|
||||
tooltip: label,
|
||||
onPressed: () => menu.isOpen ? menu.close() : menu.open(),
|
||||
icon: const Icon(Icons.more_vert),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _showSheet(BuildContext context) async {
|
||||
final picked = await _sheet<SegmentedOverflowEntry>(context, [
|
||||
for (final entry in entries)
|
||||
if (entry.onPressed != null || entry.choices.isNotEmpty)
|
||||
(entry.label, false, entry),
|
||||
]);
|
||||
if (picked == null || !context.mounted) return;
|
||||
if (picked.choices.isEmpty) {
|
||||
picked.onPressed?.call();
|
||||
return;
|
||||
}
|
||||
final choice = await _sheet<SegmentedMenuChoice>(context, [
|
||||
for (final choice in picked.choices)
|
||||
(choice.label, choice.selected, choice),
|
||||
], title: picked.label);
|
||||
choice?.onSelected();
|
||||
}
|
||||
|
||||
Future<T?> _sheet<T>(
|
||||
BuildContext context,
|
||||
List<(String, bool, T)> items, {
|
||||
String? title,
|
||||
}) => showCupertinoModalPopup<T>(
|
||||
context: context,
|
||||
builder: (sheet) => CupertinoActionSheet(
|
||||
title: title == null ? null : Text(title),
|
||||
actions: [
|
||||
for (final (label, selected, value) in items)
|
||||
CupertinoActionSheetAction(
|
||||
// The current choice is the sheet's default (bold) action.
|
||||
isDefaultAction: selected,
|
||||
onPressed: () => Navigator.of(sheet).pop(value),
|
||||
child: Semantics(selected: selected, child: Text(label)),
|
||||
),
|
||||
],
|
||||
cancelButton: CupertinoActionSheetAction(
|
||||
onPressed: () => Navigator.of(sheet).pop(),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -83,6 +83,81 @@ Widget? impliedSegmentedLeading(BuildContext context, bool cupertino) {
|
||||
return dialog ? const CloseButton() : const BackButton();
|
||||
}
|
||||
|
||||
/// The title pill's title and subtitle styles, from the host's type scale.
|
||||
(TextStyle, TextStyle) segmentedTitleStyles(
|
||||
BuildContext context, {
|
||||
required bool cupertino,
|
||||
Color? foreground,
|
||||
}) {
|
||||
if (cupertino) {
|
||||
final text = CupertinoTheme.of(context).textTheme;
|
||||
return (
|
||||
text.textStyle.copyWith(fontWeight: FontWeight.w600, color: foreground),
|
||||
text.textStyle.copyWith(
|
||||
fontSize: 13,
|
||||
color:
|
||||
foreground ?? CupertinoColors.secondaryLabel.resolveFrom(context),
|
||||
),
|
||||
);
|
||||
}
|
||||
final theme = Theme.of(context);
|
||||
return (
|
||||
(theme.textTheme.titleSmall ?? const TextStyle()).copyWith(
|
||||
color: foreground ?? theme.colorScheme.onSurface,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
(theme.textTheme.labelSmall ?? const TextStyle()).copyWith(
|
||||
color: foreground ?? theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// The title pill's horizontal padding on each side.
|
||||
const double segmentedTitlePadding = 16;
|
||||
|
||||
/// The width the title pill needs to show [title] and [subtitle] whole (at
|
||||
/// the text scale at [context]).
|
||||
double segmentedTitleWidth(
|
||||
BuildContext context, {
|
||||
required bool cupertino,
|
||||
required String title,
|
||||
String? subtitle,
|
||||
IconData? subtitleIcon,
|
||||
Color? foreground,
|
||||
}) {
|
||||
final (titleStyle, subtitleStyle) = segmentedTitleStyles(
|
||||
context,
|
||||
cupertino: cupertino,
|
||||
foreground: foreground,
|
||||
);
|
||||
final scaler = MediaQuery.textScalerOf(context);
|
||||
final direction = Directionality.of(context);
|
||||
double measure(String text, TextStyle style) {
|
||||
if (text.isEmpty) return 0;
|
||||
final painter = TextPainter(
|
||||
text: TextSpan(text: text, style: style),
|
||||
textDirection: direction,
|
||||
textScaler: scaler,
|
||||
maxLines: 1,
|
||||
)..layout();
|
||||
final width = painter.width;
|
||||
painter.dispose();
|
||||
return width;
|
||||
}
|
||||
|
||||
final sub = subtitle ?? '';
|
||||
final subWidth = sub.isEmpty
|
||||
? 0.0
|
||||
: measure(sub, subtitleStyle) +
|
||||
(subtitleIcon == null
|
||||
? 0
|
||||
: scaler.scale(subtitleStyle.fontSize ?? 12) +
|
||||
measure(' ', subtitleStyle));
|
||||
final text = measure(title, titleStyle);
|
||||
return (text > subWidth ? text : subWidth).ceilToDouble() +
|
||||
segmentedTitlePadding * 2;
|
||||
}
|
||||
|
||||
/// The title, with an optional one-line subtitle, in one pill; pressing it
|
||||
/// runs [onPressed] when given.
|
||||
class SegmentedTitlePill extends StatelessWidget {
|
||||
@@ -117,31 +192,17 @@ class SegmentedTitlePill extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final TextStyle titleStyle;
|
||||
final TextStyle subtitleStyle;
|
||||
if (cupertino) {
|
||||
final text = CupertinoTheme.of(context).textTheme;
|
||||
titleStyle = text.textStyle.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: foreground,
|
||||
);
|
||||
subtitleStyle = text.textStyle.copyWith(
|
||||
fontSize: 13,
|
||||
color:
|
||||
foreground ?? CupertinoColors.secondaryLabel.resolveFrom(context),
|
||||
);
|
||||
} else {
|
||||
final theme = Theme.of(context);
|
||||
titleStyle = (theme.textTheme.titleSmall ?? const TextStyle()).copyWith(
|
||||
color: foreground ?? theme.colorScheme.onSurface,
|
||||
fontWeight: FontWeight.w600,
|
||||
);
|
||||
subtitleStyle = (theme.textTheme.labelSmall ?? const TextStyle())
|
||||
.copyWith(color: foreground ?? theme.colorScheme.onSurfaceVariant);
|
||||
}
|
||||
final (titleStyle, subtitleStyle) = segmentedTitleStyles(
|
||||
context,
|
||||
cupertino: cupertino,
|
||||
foreground: foreground,
|
||||
);
|
||||
final subtitle = this.subtitle ?? '';
|
||||
final content = Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: segmentedTitlePadding,
|
||||
vertical: 4,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
|
||||
@@ -5,13 +5,20 @@ import '../adaptive/host.dart';
|
||||
import 'app_list_avatar.dart';
|
||||
|
||||
/// Below this row width (a list pane squeezed beside its detail) a row is
|
||||
/// compact: no avatar, no time and (by default) no menu, so the title keeps
|
||||
/// the width and a tap on the row never lands on a second control.
|
||||
/// compact: it keeps its avatar (a run's status) and its menu, so no row
|
||||
/// loses its state or its actions, and moves the time under the subtitle,
|
||||
/// leaving the title the line's width.
|
||||
const double kAppListRowCompactWidth = 280;
|
||||
|
||||
/// Below this row width (narrower than any list pane, as in a row squeezed
|
||||
/// by its host) the avatar and the menu would leave the text no room, so the
|
||||
/// row drops them rather than overflow.
|
||||
const double kAppListRowMinimalWidth = 160;
|
||||
|
||||
/// The rows' horizontal inset and the gap after the avatar.
|
||||
const double kAppListRowInset = 16;
|
||||
const double _avatarGap = 12;
|
||||
const double _compactAvatarGap = 8;
|
||||
|
||||
/// Keys on a row's highlight surface and inset divider, for tests.
|
||||
const appListRowSurfaceKey = ValueKey<String>('app-list-row-surface');
|
||||
@@ -29,8 +36,9 @@ bool _darkSurface(BuildContext context, bool cupertino) => cupertino
|
||||
/// the [time] at its trailing edge, then one muted [subtitle] line (with an
|
||||
/// optional [subtitleLeading] dot/prefix and [subtitleTrailing] mark), then
|
||||
/// the optional [menu] (an `AppOverflowMenu`). A row in a multi-select list
|
||||
/// puts its checkbox in [selectionControl], which leads the row even when it
|
||||
/// is compact. An inset hairline [divider]
|
||||
/// puts its checkbox in [selectionControl], which leads the row. A compact
|
||||
/// row (narrower than [compactWidth]) keeps all of these and shows the time
|
||||
/// on a line of its own under the subtitle. An inset hairline [divider]
|
||||
/// under the text column separates rows. Nothing has a fixed height: the row
|
||||
/// grows with text scaling and every line ellipsises.
|
||||
///
|
||||
@@ -57,7 +65,6 @@ class AppListRow extends StatelessWidget {
|
||||
this.selected = false,
|
||||
this.emphasized = false,
|
||||
this.divider = true,
|
||||
this.keepMenuWhenCompact = false,
|
||||
this.compactWidth = kAppListRowCompactWidth,
|
||||
this.cupertino,
|
||||
this.accent,
|
||||
@@ -84,7 +91,7 @@ class AppListRow extends StatelessWidget {
|
||||
/// A touch long-press on the row (for example, entering a select mode).
|
||||
final VoidCallback? onLongPress;
|
||||
|
||||
/// A checkbox leading the row in a multi-select list; kept when compact.
|
||||
/// A checkbox leading the row in a multi-select list.
|
||||
final Widget? selectionControl;
|
||||
|
||||
/// Placed on the tap target ([InkWell] / [GestureDetector]).
|
||||
@@ -92,10 +99,6 @@ class AppListRow extends StatelessWidget {
|
||||
final bool selected;
|
||||
final bool emphasized;
|
||||
final bool divider;
|
||||
|
||||
/// Keeps the menu in a compact row when the list has no other way to reach
|
||||
/// the row's actions.
|
||||
final bool keepMenuWhenCompact;
|
||||
final double compactWidth;
|
||||
|
||||
/// Overrides the host detection (some features pick a style per platform).
|
||||
@@ -123,9 +126,11 @@ class AppListRow extends StatelessWidget {
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final compact = constraints.maxWidth < compactWidth;
|
||||
final showLeading = leading != null && !compact;
|
||||
final showMenu = menu != null && (!compact || keepMenuWhenCompact);
|
||||
final minimal = constraints.maxWidth < kAppListRowMinimalWidth;
|
||||
final showLeading = leading != null && !minimal;
|
||||
final showMenu = menu != null && !minimal;
|
||||
final start = compact ? 12.0 : kAppListRowInset;
|
||||
final avatarGap = compact ? _compactAvatarGap : _avatarGap;
|
||||
final content = Padding(
|
||||
padding: EdgeInsetsDirectional.only(
|
||||
start: start,
|
||||
@@ -142,7 +147,7 @@ class AppListRow extends StatelessWidget {
|
||||
),
|
||||
if (showLeading)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.only(end: _avatarGap),
|
||||
padding: EdgeInsetsDirectional.only(end: avatarGap),
|
||||
child: leading,
|
||||
),
|
||||
Expanded(child: _text(styles, compact)),
|
||||
@@ -198,7 +203,7 @@ class AppListRow extends StatelessWidget {
|
||||
// not known here, so a selectable row's divider starts at the inset.
|
||||
final textStart = selectionControl != null
|
||||
? start
|
||||
: start + (showLeading ? kAppListAvatarSize + _avatarGap : 0);
|
||||
: start + (showLeading ? kAppListAvatarSize + avatarGap : 0);
|
||||
final line = Padding(
|
||||
padding: EdgeInsetsDirectional.only(start: textStart),
|
||||
child: SizedBox(
|
||||
@@ -227,8 +232,27 @@ class AppListRow extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// The time, one ellipsised line in the time style, or null without one.
|
||||
Widget? _time(_RowStyles styles) {
|
||||
if (timeWidget == null && (time == null || time!.isEmpty)) return null;
|
||||
return timeWidget == null
|
||||
? Text(
|
||||
time!,
|
||||
style: styles.time,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)
|
||||
: DefaultTextStyle(
|
||||
style: styles.time,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
child: timeWidget!,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _text(_RowStyles styles, bool compact) {
|
||||
final line = compact ? (compactSubtitle ?? subtitle) : subtitle;
|
||||
final time = _time(styles);
|
||||
final titleLine = LayoutBuilder(
|
||||
// The time keeps at most 40% of the line, so very large text in a
|
||||
// narrow row ellipsises instead of overflowing.
|
||||
@@ -242,32 +266,27 @@ class AppListRow extends StatelessWidget {
|
||||
child: title,
|
||||
),
|
||||
),
|
||||
if (!compact &&
|
||||
(timeWidget != null || (time != null && time!.isNotEmpty)))
|
||||
if (!compact && time != null)
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: constraints.maxWidth * 0.4),
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 8),
|
||||
child: timeWidget == null
|
||||
? Text(
|
||||
time!,
|
||||
style: styles.time,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)
|
||||
: DefaultTextStyle(
|
||||
style: styles.time,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
child: timeWidget!,
|
||||
),
|
||||
child: time,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
// A compact row has no room beside its title: the time takes a line of
|
||||
// its own under the subtitle.
|
||||
final timeLine = compact ? time : null;
|
||||
if (line == null && subtitleLeading == null && subtitleTrailing == null) {
|
||||
return titleLine;
|
||||
if (timeLine == null) return titleLine;
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [titleLine, const SizedBox(height: 2), timeLine],
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -297,6 +316,7 @@ class AppListRow extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
?timeLine,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user