feat(app): finish native run Changes wiring and scaled form menus

This commit is contained in:
2026-10-21 20:48:45 +01:00
parent 7b327f012b
commit 77c71eb45e
18 changed files with 1956 additions and 159 deletions
@@ -2,104 +2,52 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../domain/unified_patch.dart';
import 'diff_form_control.dart';
/// Which form of a recorded patch the viewer is showing.
enum DiffForm { rendered, raw }
export 'diff_form_control.dart';
/// The app's established platform switch: Material for Android/desktop/web,
/// Cupertino for iOS and macOS. Feature widgets stay portable across all three
/// targets instead of hard-coding one control set.
bool usesCupertino(BuildContext context) {
final platform = Theme.of(context).platform;
return platform == TargetPlatform.iOS || platform == TargetPlatform.macOS;
}
/// Patch text inherits the host's typography, including its font and scaler.
/// A diff is not an exception to the native-defaults requirement.
/// Patch text inherits the host's typography without a diff-specific font.
TextStyle nativeDiffText(TextStyle base) => base;
/// Native semantic colours, never a bespoke diff palette. The recorded +/-
/// markers carry meaning independently of colour. No background tint is added.
/// Keep Material-derived metadata roles readable inside a Cupertino host.
ThemeData hostTextTheme(BuildContext context) => ThemeData(
brightness: CupertinoTheme.brightnessOf(context),
platform: Theme.of(context).platform,
);
/// Native semantic roles, never a bespoke palette or added row tint. The exact
/// recorded +/- markers also distinguish changes without relying on colour.
({Color text, Color? background}) diffLineColors(
BuildContext context,
ChangeLineKind kind,
) {
return switch (kind) {
ChangeLineKind.add => (
text: usesCupertino(context)
? CupertinoColors.systemGreen.resolveFrom(context)
: Theme.of(context).colorScheme.primary,
background: null,
),
ChangeLineKind.remove => (
text: usesCupertino(context)
? CupertinoColors.destructiveRed.resolveFrom(context)
: Theme.of(context).colorScheme.error,
background: null,
),
ChangeLineKind.context => (text: labelColor(context), background: null),
};
}
) => switch (kind) {
ChangeLineKind.add => (
text: usesCupertino(context)
? CupertinoColors.systemGreen.resolveFrom(context)
: Theme.of(context).colorScheme.primary,
background: null,
),
ChangeLineKind.remove => (
text: usesCupertino(context)
? CupertinoColors.destructiveRed.resolveFrom(context)
: Theme.of(context).colorScheme.error,
background: null,
),
ChangeLineKind.context => (text: labelColor(context), background: null),
};
/// The plain body/label colour for non-diff text inside the viewer.
Color labelColor(BuildContext context) => usesCupertino(context)
? CupertinoColors.label.resolveFrom(context)
: Theme.of(context).colorScheme.onSurface;
/// The muted colour for gutters, notes and secondary metadata.
Color mutedColor(BuildContext context) => usesCupertino(context)
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant;
/// The hunk header's fill.
Color hunkHeaderColor(BuildContext context) => usesCupertino(context)
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
: Theme.of(context).colorScheme.surfaceContainerHighest;
/// The viewer's shared Rendered/Raw control: a native segmented control on each
/// platform, with the same two words the browser uses.
Widget diffFormControl(
BuildContext context, {
required DiffForm form,
required ValueChanged<DiffForm> onChanged,
}) {
if (usesCupertino(context)) {
return CupertinoSlidingSegmentedControl<DiffForm>(
groupValue: form,
onValueChanged: (value) {
if (value != null) onChanged(value);
},
children: const {
DiffForm.rendered: _SegmentLabel('Rendered'),
DiffForm.raw: _SegmentLabel('Raw patch'),
},
);
}
return SegmentedButton<DiffForm>(
segments: const [
ButtonSegment(value: DiffForm.rendered, label: Text('Rendered')),
ButtonSegment(value: DiffForm.raw, label: Text('Raw patch')),
],
selected: {form},
showSelectedIcon: false,
onSelectionChanged: (selection) {
if (selection.isNotEmpty) onChanged(selection.first);
},
);
}
class _SegmentLabel extends StatelessWidget {
const _SegmentLabel(this.label);
final String label;
@override
Widget build(BuildContext context) =>
Padding(padding: const EdgeInsets.all(6), child: Text(label));
}
/// Copy the server's raw patch exactly as recorded. Disabled when the entry has
/// no readable patch, so the action never copies a fabricated empty diff.
Widget copyPatchControl(
BuildContext context, {
required bool enabled,
@@ -128,7 +76,6 @@ Widget copyPatchControl(
);
}
/// The standard close action, labelled exactly on both platforms.
Widget closeDiffControl(BuildContext context, VoidCallback onClose) {
if (usesCupertino(context)) {
return Semantics(