49 lines
1.3 KiB
Dart
49 lines
1.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
/// A single line of the text/code viewer: a right-aligned, non-selectable line
|
|
/// number gutter plus the selectable line content, with zebra striping.
|
|
class CodeLine extends StatelessWidget {
|
|
final int number;
|
|
final String text;
|
|
final double gutterWidth;
|
|
const CodeLine({
|
|
super.key,
|
|
required this.number,
|
|
required this.text,
|
|
required this.gutterWidth,
|
|
});
|
|
|
|
static const TextStyle _codeStyle = TextStyle(
|
|
fontFamily: 'monospace',
|
|
fontSize: 13,
|
|
height: 1.4,
|
|
);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
final isEven = number.isEven;
|
|
return Container(
|
|
color: isEven ? theme.colorScheme.surfaceContainerLow : null,
|
|
padding: const EdgeInsets.only(left: 4, right: 12),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
SelectionContainer.disabled(
|
|
child: SizedBox(
|
|
width: gutterWidth,
|
|
child: Text(
|
|
'$number',
|
|
textAlign: TextAlign.right,
|
|
style: _codeStyle.copyWith(color: theme.hintColor),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(child: Text(text.isEmpty ? ' ' : text, style: _codeStyle)),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|