Enlarge viewer controls and respect safe areas

This commit is contained in:
2026-11-02 17:50:27 +00:00
parent e2ba091f7d
commit e65e2800e6
7 changed files with 188 additions and 152 deletions
@@ -257,16 +257,18 @@ class ArtifactIconAction extends StatelessWidget {
label: label,
child: CupertinoButton(
padding: inBar ? EdgeInsets.zero : const EdgeInsets.all(8),
minimumSize: const Size(44, 44),
onPressed: onPressed,
child: busy
? const CupertinoActivityIndicator(radius: 9)
: Icon(cupertinoIcon),
: Icon(cupertinoIcon, size: 30),
),
);
}
return IconButton(
tooltip: label,
visualDensity: inBar ? null : VisualDensity.compact,
constraints: const BoxConstraints(minWidth: 48, minHeight: 48),
padding: EdgeInsets.zero,
onPressed: onPressed,
icon: busy
? const SizedBox(
@@ -274,7 +276,7 @@ class ArtifactIconAction extends StatelessWidget {
height: 18,
child: CircularProgressIndicator(strokeWidth: 2),
)
: Icon(icon),
: Icon(icon, size: 28),
);
}
}
@@ -116,11 +116,12 @@ Widget copyPatchControl(
if (usesCupertino(context)) {
return CupertinoButton(
padding: EdgeInsets.zero,
minimumSize: const Size(44, 44),
onPressed: enabled ? onPressed : null,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(CupertinoIcons.doc_on_doc),
const Icon(CupertinoIcons.doc_on_doc, size: 30),
const SizedBox(width: 8),
Text(label),
],
@@ -128,8 +129,9 @@ Widget copyPatchControl(
);
}
return TextButton.icon(
style: TextButton.styleFrom(minimumSize: const Size(0, 48)),
onPressed: enabled ? onPressed : null,
icon: const Icon(Icons.copy_all_outlined),
icon: const Icon(Icons.copy_all_outlined, size: 28),
label: Text(label),
);
}
@@ -143,14 +145,17 @@ Widget closeDiffControl(BuildContext context, VoidCallback onClose) {
onTap: onClose,
child: CupertinoButton(
padding: EdgeInsets.zero,
minimumSize: const Size(44, 44),
onPressed: onClose,
child: const Icon(CupertinoIcons.xmark),
child: const Icon(CupertinoIcons.xmark, size: 30),
),
);
}
return IconButton(
constraints: const BoxConstraints(minWidth: 48, minHeight: 48),
padding: EdgeInsets.zero,
tooltip: 'Close diff',
onPressed: onClose,
icon: const Icon(Icons.close),
icon: const Icon(Icons.close, size: 28),
);
}
@@ -234,19 +234,23 @@ class _ChangesViewerState extends State<ChangesViewer> {
child: MediaQuery.removePadding(
context: context,
removeBottom: true,
child: Padding(
// The inherited bottom inset belongs to the shell bar. Include it
// in this overlay's measured bar height so the pager is stacked
// above it rather than translating into a constrained layout.
padding: EdgeInsets.only(
bottom: MediaQuery.paddingOf(context).bottom,
),
child: SafeArea(
top: false,
minimum: const EdgeInsets.symmetric(horizontal: 8),
child: Padding(
padding: const EdgeInsets.all(8),
child: IntrinsicWidth(
child: GlassPill(
cupertino: usesCupertinoHost(context),
child: pager,
// The inherited bottom inset belongs to the shell bar. Include it
// in this overlay's measured bar height so the pager is stacked
// above it rather than translating into a constrained layout.
padding: EdgeInsets.only(
bottom: MediaQuery.paddingOf(context).bottom,
),
child: Padding(
padding: const EdgeInsets.all(8),
child: IntrinsicWidth(
child: GlassPill(
cupertino: usesCupertinoHost(context),
child: pager,
),
),
),
),
@@ -48,14 +48,18 @@ Widget diffFormControl(
},
children: {
for (final entry in diffFormLabels.entries)
entry.key: Padding(
padding: const EdgeInsets.all(6),
child: Text(entry.value),
entry.key: ConstrainedBox(
constraints: const BoxConstraints(minHeight: 44),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 6),
child: Center(child: Text(entry.value)),
),
),
},
);
}
return SegmentedButton<DiffForm>(
style: ButtonStyle(minimumSize: const WidgetStatePropertyAll(Size(0, 48))),
segments: [
for (final entry in diffFormLabels.entries)
ButtonSegment(value: entry.key, label: Text(entry.value)),
@@ -80,6 +84,7 @@ Widget diffFormMenu(
button: true,
child: CupertinoButton(
padding: EdgeInsets.zero,
minimumSize: const Size(44, 44),
onPressed: () => showCupertinoModalPopup<void>(
context: context,
builder: (sheetContext) => CupertinoActionSheet(
@@ -97,13 +102,15 @@ Widget diffFormMenu(
],
),
),
child: const Icon(CupertinoIcons.ellipsis),
child: const Icon(CupertinoIcons.ellipsis, size: 30),
),
);
}
return IconButton(
tooltip: 'Diff form',
icon: const Icon(Icons.more_vert),
constraints: const BoxConstraints(minWidth: 48, minHeight: 48),
padding: EdgeInsets.zero,
icon: const Icon(Icons.more_vert, size: 28),
onPressed: () => showModalBottomSheet<void>(
context: context,
showDragHandle: true,
@@ -75,130 +75,136 @@ class _FileDiffViewerState extends State<FileDiffViewer> {
final mono = nativeDiffText(base);
final stat = changeStat(file.added, file.removed);
final tags = changeEntryTags(file);
return ConstrainedBox(
key: const ValueKey('file-diff-viewer'),
constraints: BoxConstraints(
maxWidth: 900,
maxHeight: MediaQuery.sizeOf(context).height * 0.85,
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: widget.floatBehindTopBar
? withTopBarClearance(
context,
const EdgeInsets.fromLTRB(16, 12, 16, 8),
)
: const EdgeInsets.fromLTRB(16, 12, 16, 8),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Semantics(
container: true,
header: true,
excludeSemantics: true,
label: [
changeKindTitle(file.kind),
if (stat.isNotEmpty) stat,
if (tags.isNotEmpty) tags.join(' · '),
'for ${file.path}',
if (file.steps.isNotEmpty)
'changed by ${file.steps.join(' → ')}',
if (file.modeChanged && !file.binary)
'mode ${file.beforeMode ?? ''}→'
'${file.afterMode ?? ''}',
].join(', '),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Wrap(
spacing: 12,
runSpacing: 4,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Text(
changeKindTitle(file.kind),
style: Theme.of(context).textTheme.titleMedium,
),
if (stat.isNotEmpty)
ChangeStatText(stat, style: mono),
if (tags.isNotEmpty)
Text(
tags.join(' · '),
style: Theme.of(context).textTheme.bodySmall,
),
],
),
const SizedBox(height: 4),
Text(file.path, style: mono),
return SafeArea(
top: false,
minimum: const EdgeInsets.symmetric(horizontal: 8),
child: ConstrainedBox(
key: const ValueKey('file-diff-viewer'),
constraints: BoxConstraints(
maxWidth: 900,
maxHeight: MediaQuery.sizeOf(context).height * 0.85,
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: widget.floatBehindTopBar
? withTopBarClearance(
context,
const EdgeInsets.fromLTRB(16, 12, 16, 8),
)
: const EdgeInsets.fromLTRB(16, 12, 16, 8),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Semantics(
container: true,
header: true,
excludeSemantics: true,
label: [
changeKindTitle(file.kind),
if (stat.isNotEmpty) stat,
if (tags.isNotEmpty) tags.join(' · '),
'for ${file.path}',
if (file.steps.isNotEmpty)
Text(
'changed by ${file.steps.join(' → ')}',
style: Theme.of(context).textTheme.bodySmall,
),
'changed by ${file.steps.join(' → ')}',
if (file.modeChanged && !file.binary)
Text(
'mode ${file.beforeMode ?? ''}→'
'${file.afterMode ?? ''}',
style: Theme.of(context).textTheme.bodySmall,
'mode ${file.beforeMode ?? ''}→'
'${file.afterMode ?? ''}',
].join(', '),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Wrap(
spacing: 12,
runSpacing: 4,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Text(
changeKindTitle(file.kind),
style: Theme.of(context).textTheme.titleMedium,
),
if (stat.isNotEmpty)
ChangeStatText(stat, style: mono),
if (tags.isNotEmpty)
Text(
tags.join(' · '),
style: Theme.of(context).textTheme.bodySmall,
),
],
),
],
const SizedBox(height: 4),
Text(file.path, style: mono),
if (file.steps.isNotEmpty)
Text(
'changed by ${file.steps.join(' → ')}',
style: Theme.of(context).textTheme.bodySmall,
),
if (file.modeChanged && !file.binary)
Text(
'mode ${file.beforeMode ?? ''}→'
'${file.afterMode ?? ''}',
style: Theme.of(context).textTheme.bodySmall,
),
],
),
),
),
),
],
],
),
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Wrap(
spacing: 8,
runSpacing: 8,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
if (file.hasPatch)
LayoutBuilder(
builder: (context, constraints) {
// Two native segmented-control segments cannot show both
// fixed words at 2x text on a narrow host; their menu
// shows the same labels whole, one per row.
final control =
diffFormSegmentsFit(context, constraints.maxWidth)
? diffFormControl(
context,
form: _form,
onChanged: _selectForm,
)
: diffFormMenu(
context,
form: _form,
onChanged: _selectForm,
);
return control;
},
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Wrap(
spacing: 8,
runSpacing: 8,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
if (file.hasPatch)
LayoutBuilder(
builder: (context, constraints) {
// Two native segmented-control segments cannot show both
// fixed words at 2x text on a narrow host; their menu
// shows the same labels whole, one per row.
final control =
diffFormSegmentsFit(context, constraints.maxWidth)
? diffFormControl(
context,
form: _form,
onChanged: _selectForm,
)
: diffFormMenu(
context,
form: _form,
onChanged: _selectForm,
);
return control;
},
),
_scrollsWhenTooWide(
copyPatchControl(
context,
enabled: file.hasPatch,
copied: _copied,
onPressed: _copy,
),
),
_scrollsWhenTooWide(
copyPatchControl(
context,
enabled: file.hasPatch,
copied: _copied,
onPressed: _copy,
),
),
],
if (widget.onClose != null)
closeDiffControl(context, widget.onClose!),
],
),
),
),
Divider(
height: 16,
color: cupertino
? CupertinoColors.separator.resolveFrom(context)
: Theme.of(context).dividerColor,
),
Flexible(child: _body(context, mono)),
],
Divider(
height: 16,
color: cupertino
? CupertinoColors.separator.resolveFrom(context)
: Theme.of(context).dividerColor,
),
Flexible(child: _body(context, mono)),
],
),
),
);
}
@@ -306,8 +312,9 @@ class _FileDiffPageState extends State<FileDiffPage> {
: Align(
alignment: AlignmentDirectional.centerEnd,
heightFactor: 1,
child: Padding(
padding: const EdgeInsets.all(8),
child: SafeArea(
top: false,
minimum: const EdgeInsets.all(8),
child: GlassPill(cupertino: cupertino, child: pager),
),
),
+16 -4
View File
@@ -48,12 +48,14 @@ class ChevronPager extends StatelessWidget {
excludeSemantics: true,
child: CupertinoButton(
key: key,
padding: const EdgeInsets.all(8),
padding: EdgeInsets.zero,
minimumSize: const Size(44, 44),
onPressed: onPressed,
child: Icon(
previous
? CupertinoIcons.chevron_left
: CupertinoIcons.chevron_right,
size: 30,
),
),
);
@@ -61,24 +63,34 @@ class ChevronPager extends StatelessWidget {
return IconButton(
key: key,
tooltip: label,
constraints: const BoxConstraints(minWidth: 48, minHeight: 48),
padding: EdgeInsets.zero,
onPressed: onPressed,
icon: Icon(previous ? Icons.chevron_left : Icons.chevron_right),
icon: Icon(
previous ? Icons.chevron_left : Icons.chevron_right,
size: 28,
),
);
}
return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 8, 4),
// The surrounding glass pill supplies the edge gap. Keeping this row's
// horizontal padding at zero also leaves room for four 48px controls on
// a narrow phone at large text sizes.
padding: EdgeInsets.zero,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Flexible(
fit: FlexFit.tight,
child: Text(
'${index + 1} of $count',
key: positionKey,
style: Theme.of(context).textTheme.labelLarge,
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 4),
const SizedBox(width: 0),
chevron(
key: previousKey,
previous: true,
@@ -428,12 +428,11 @@ void main() {
);
await tester.tap(find.text('Open diff'));
await tester.pumpAndSettle();
expect(
cupertino
? find.byType(CupertinoSlidingSegmentedControl<DiffForm>)
: find.byType(SegmentedButton<DiffForm>),
findsOneWidget,
);
final control = cupertino
? find.byType(CupertinoSlidingSegmentedControl<DiffForm>)
: find.byType(SegmentedButton<DiffForm>);
expect(control, findsOneWidget);
expect(tester.getSize(control).height, greaterThanOrEqualTo(44));
expect(find.text('Rendered'), findsOneWidget);
expect(find.text('Raw patch'), findsOneWidget);
expect(tester.takeException(), isNull);