Pie or donut chart
A pie or donut chart shows how a small number of categories divide a whole. Keep category names and amounts close to the slices.
Compare budget shares
#The budget totals 100 in both plans. Switch to Plan B to see ten move from Supplies to Travel while Fees stays at twenty.
components/pie-chart/appliance/compare_budgets.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class CompareBudgets extends StatefulWidget {
const CompareBudgets({super.key});
@override
State<CompareBudgets> createState() => _CompareBudgetsState();
}
class _CompareBudgetsState extends State<CompareBudgets> {
bool alternate = false;
String get period => alternate ? 'Plan B' : 'Plan A';
List<double> get amounts =>
alternate ? const [40, 40, 20] : const [50, 30, 20];
@override
Widget build(BuildContext context) => SingleChildScrollView(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 420),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('$period · budget by category'),
const SizedBox(height: 12),
ApplianceDonutChart(
slices: [
('Supplies', amounts[0]),
('Travel', amounts[1]),
('Fees', amounts[2]),
],
semanticLabel: '$period budget by category',
),
const SizedBox(height: 12),
ApplianceButton(
alternate ? 'Show Plan A' : 'Show Plan B',
onPressed: () => setState(() => alternate = !alternate),
),
],
),
),
);
}
Parameters
ApplianceDonutChart API ↗slices- Names each category and its share of the total.
semanticLabel- Names the budget and plan.
size- Sets the diameter of the chart.
Shared behaviour
- Keyboard and focus. Tab to the plan button and activate it. In a look with keyboard selection on the chart, use the arrows to inspect slices.
- Screen readers. Read the period and the chart’s description. The value or summary provided by the look changes with the data.
- Direction and type. The surrounding text follows reading direction. Check the plot’s own ordering, labels and legend in RTL and at larger type.