Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions lib/widgets/refreshable_data_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,31 @@ class _ViamRefreshableDataTableState extends State<ViamRefreshableDataTable> {
Widget build(BuildContext context) {
return Column(
children: [
DataTable(
columns: const <DataColumn>[DataColumn(label: Text('Reading')), DataColumn(label: Text('Value'))],
rows: readings.keys.map((e) => DataRow(cells: [DataCell(Text(e)), DataCell(Text(readings[e].toString()))])).toList()),
if (readings.isEmpty)
const Text('No sensor readings available')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

else
DataTable(
columns: const <DataColumn>[DataColumn(label: Text('Reading')), DataColumn(label: Text('Value'))],
rows: readings.keys
.map((e) => DataRow(cells: [
DataCell(Text(e)),
DataCell(
SizedBox(
width: MediaQuery.of(context).size.width * 0.5,
height: 120,
child: Align(
alignment: Alignment.centerLeft,
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(readings[e].toString()),
),
),
),
),
)
]))
.toList()),
if (widget.showLastRefreshed && lastRefreshed != null)
Column(children: [
const SizedBox(height: 8),
Expand Down
14 changes: 14 additions & 0 deletions test/widget_tests/refreshable_data_table_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,26 @@ void main() {
testWidgets('displays data', (tester) async {
final widget = TestableWidget(child: ViamRefreshableDataTable(getData: FakeSensor('sensor').readings));
await tester.pumpWidget(widget);
await tester.pumpAndSettle();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to wait for async getReadings to complete so we added this


final dataTable = find.byType(DataTable);

expect(dataTable, findsOneWidget);
});

testWidgets('displays no sensor readings available', (tester) async {
final widget = TestableWidget(
child: ViamRefreshableDataTable(
getData: ({Map<String, dynamic>? extra}) async => <String, dynamic>{},
),
);
await tester.pumpWidget(widget);

final noSensorReadingsAvailable = find.textContaining(RegExp(r'No sensor readings available'));

expect(noSensorReadingsAvailable, findsOneWidget);
});

testWidgets('shows last refresh time', (tester) async {
final widget = TestableWidget(child: ViamRefreshableDataTable(getData: FakeSensor('sensor').readings, showLastRefreshed: true));
await tester.pumpWidget(widget);
Expand Down