Files
alan f46b82e207 Remove Cupertino branches from artifact features
Keep the Material implementation while preserving public parameters needed by callers. Remove Cupertino-only tests and variants because the app runs exclusively under MaterialApp.
2026-11-11 04:36:57 +00:00

78 lines
2.6 KiB
Dart

import 'package:flutter/material.dart';
import '../domain/artifact_table.dart';
/// The truncation note for a capped table preview.
String artifactTableNote(ArtifactTable table) =>
'Showing ${table.rows.length} of ${table.totalRows} rows. Open the file '
'for the rest.';
/// A CSV/TSV preview: the first row as the header, every cell selectable, and
/// the whole grid scrolling horizontally inside the viewer's own vertical
/// scroll. Short rows are padded with empty cells; nothing is invented.
class ArtifactTableView extends StatelessWidget {
const ArtifactTableView({
super.key,
required this.text,
required this.delimiter,
});
final String text;
final String delimiter;
@override
Widget build(BuildContext context) {
final table = parseArtifactTable(text, delimiter: delimiter);
if (table.rows.isEmpty) {
return const Padding(
padding: EdgeInsets.all(16),
child: Text('The table is empty.'),
);
}
final border = Theme.of(context).dividerColor;
final header = Theme.of(context).colorScheme.surfaceContainerHighest;
final columns = table.columnCount;
Widget cell(String value, {bool head = false}) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
child: SelectableText(
value,
style: head ? const TextStyle(fontWeight: FontWeight.w600) : null,
),
);
return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (table.truncated)
Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Text(artifactTableNote(table)),
),
SingleChildScrollView(
key: const Key('artifact-table'),
scrollDirection: Axis.horizontal,
child: Table(
defaultColumnWidth: const IntrinsicColumnWidth(),
border: TableBorder.all(color: border),
children: [
for (var r = 0; r < table.rows.length; r++)
TableRow(
decoration: r == 0 ? BoxDecoration(color: header) : null,
children: [
for (var c = 0; c < columns; c++)
cell(
c < table.rows[r].length ? table.rows[r][c] : '',
head: r == 0,
),
],
),
],
),
),
],
),
);
}
}