Table
Use a table to compare the same facts across several items. Short column labels help readers move between a value and the item it belongs to.
Compare costs
#Compare the two costs. Switch between one and two orders and check how both amounts change.
components/table/appliance/compare_costs.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class CompareCosts extends StatefulWidget {
const CompareCosts({super.key});
@override
State<CompareCosts> createState() => _CompareCostsState();
}
class _CompareCostsState extends State<CompareCosts> {
bool doubleOrder = false;
@override
Widget build(BuildContext context) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 760),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ApplianceTable(
columns: const [
ApplianceTableColumn('Item'),
ApplianceTableColumn('Cost', numeric: true),
],
rows: [
['Paper', doubleOrder ? '£8' : '£4'],
['Ink', doubleOrder ? '£14' : '£7'],
],
),
const SizedBox(height: 12),
ApplianceButton(
doubleOrder ? 'One order' : 'Two orders',
onPressed: () => setState(() => doubleOrder = !doubleOrder),
),
],
),
),
);
}
Parameters
ApplianceTable API ↗columns- The columns.
rows- The rows, a text for each column.
style- Its style, over ApplianceThemeData.tableStyle.
Shared behaviour
- Keyboard and focus. Tab to the quantity action to change the figures. Reading the cells takes no keyboard activation.
- Screen readers. Read each item with its amount. Look for the same association after changing the quantity.
- Direction and type. Compare the wide columns with the phone layout, then switch direction. Larger type may wrap labels or make a table scroll.