76 lines
2.3 KiB
Dart
76 lines
2.3 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'change_style.dart';
|
|
|
|
/// The recorded raw patch bytes, one recorded line per line, in the host's own
|
|
/// selectable body.
|
|
///
|
|
/// Material uses [SelectionArea]; a Cupertino host has no
|
|
/// [MaterialLocalizations], so it renders the same text in the read-only
|
|
/// [CupertinoTextField] the run detail already uses for plain selectable text.
|
|
/// Both forms keep their intrinsic line width, so long lines scroll sideways
|
|
/// instead of wrapping a continuation under a new line.
|
|
class RawPatchView extends StatefulWidget {
|
|
const RawPatchView({super.key, required this.patch, required this.style});
|
|
|
|
final String patch;
|
|
final TextStyle style;
|
|
|
|
@override
|
|
State<RawPatchView> createState() => _RawPatchViewState();
|
|
}
|
|
|
|
class _RawPatchViewState extends State<RawPatchView> {
|
|
late final TextEditingController _text = TextEditingController(
|
|
text: widget.patch,
|
|
);
|
|
|
|
@override
|
|
void didUpdateWidget(RawPatchView oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (widget.patch != _text.text) _text.text = widget.patch;
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_text.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cupertino = usesCupertino(context);
|
|
return SingleChildScrollView(
|
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
|
|
child: SingleChildScrollView(
|
|
scrollDirection: Axis.horizontal,
|
|
child: cupertino
|
|
? IntrinsicWidth(
|
|
child: ExcludeSemantics(
|
|
child: CupertinoTextField(
|
|
key: const ValueKey('raw-patch-field'),
|
|
controller: _text,
|
|
readOnly: true,
|
|
maxLines: null,
|
|
padding: EdgeInsets.zero,
|
|
decoration: const BoxDecoration(),
|
|
style: widget.style,
|
|
),
|
|
),
|
|
)
|
|
: ExcludeSemantics(
|
|
child: SelectionArea(
|
|
child: Text(
|
|
widget.patch,
|
|
style: widget.style,
|
|
softWrap: false,
|
|
overflow: TextOverflow.visible,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|