99 lines
2.9 KiB
Dart
99 lines
2.9 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../domain/unified_patch.dart';
|
|
import 'diff_form_control.dart';
|
|
|
|
export 'diff_form_control.dart';
|
|
|
|
/// Patch text inherits the host's typography without a diff-specific font.
|
|
TextStyle nativeDiffText(TextStyle base) => base;
|
|
|
|
/// 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,
|
|
) => 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),
|
|
};
|
|
|
|
Color labelColor(BuildContext context) => usesCupertino(context)
|
|
? CupertinoColors.label.resolveFrom(context)
|
|
: Theme.of(context).colorScheme.onSurface;
|
|
|
|
Color mutedColor(BuildContext context) => usesCupertino(context)
|
|
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
|
: Theme.of(context).colorScheme.onSurfaceVariant;
|
|
|
|
Color hunkHeaderColor(BuildContext context) => usesCupertino(context)
|
|
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
|
|
: Theme.of(context).colorScheme.surfaceContainerHighest;
|
|
|
|
Widget copyPatchControl(
|
|
BuildContext context, {
|
|
required bool enabled,
|
|
required bool copied,
|
|
required VoidCallback onPressed,
|
|
}) {
|
|
final label = copied ? 'Copied' : 'Copy patch';
|
|
if (usesCupertino(context)) {
|
|
return CupertinoButton(
|
|
padding: EdgeInsets.zero,
|
|
onPressed: enabled ? onPressed : null,
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Icon(CupertinoIcons.doc_on_doc),
|
|
const SizedBox(width: 8),
|
|
Text(label),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
return TextButton.icon(
|
|
onPressed: enabled ? onPressed : null,
|
|
icon: const Icon(Icons.copy_all_outlined),
|
|
label: Text(label),
|
|
);
|
|
}
|
|
|
|
Widget closeDiffControl(BuildContext context, VoidCallback onClose) {
|
|
if (usesCupertino(context)) {
|
|
return Semantics(
|
|
label: 'Close diff',
|
|
button: true,
|
|
excludeSemantics: true,
|
|
onTap: onClose,
|
|
child: CupertinoButton(
|
|
padding: EdgeInsets.zero,
|
|
onPressed: onClose,
|
|
child: const Icon(CupertinoIcons.xmark),
|
|
),
|
|
);
|
|
}
|
|
return IconButton(
|
|
tooltip: 'Close diff',
|
|
onPressed: onClose,
|
|
icon: const Icon(Icons.close),
|
|
);
|
|
}
|