DonutChart class
A donut/ring chart widget that displays data segments as colored arcs.
The DonutChart widget visualizes a dataset as a donut chart with optional features including title, center text, labels, legend, and interactive tap handlers.
Features:
- Customizable title and data labels
- Optional legend display
- Optional center text showing total value
- Optional connecting lines from center to labels
- Tap handling for individual sectors
- Optional dataset sorting (ascending/descending)
Example:
DonutChart(
title: 'Sales Distribution',
dataset: dataItems,
showLabels: true,
showLegend: true,
onSectorTap: (item) => print('${item.label}: ${item.value}'),
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- DonutChart
Constructors
-
DonutChart({Key? key, required List<
DataItem> dataset, String title = '', bool showTitle = true, bool showCenterText = true, bool showLabels = true, bool showLegend = true, bool showLines = true, dynamic onSectorTap(DataItem) = _defaultOnTap, DatasetOrdering? datasetOrdering}) -
Creates a DonutChart widget.
const
Properties
-
dataset
→ List<
DataItem> -
The data items to display in the chart.
Each DataItem represents a sector in the donut chart.
final
- datasetOrdering → DatasetOrdering?
-
Optional sorting order for the dataset.
Can be DatasetOrdering.crescent, DatasetOrdering.decrescent, or null.
When null, items display in their original order.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- onSectorTap → dynamic Function(DataItem)
-
Callback function triggered when a sector is tapped.
Called with the DataItem corresponding to the tapped sector.
Defaults to a no-op function.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- showCenterText → bool
-
Whether to display text in the center of the donut.
When true, displays the total value of all items.
Defaults to true.
final
- showLabels → bool
-
Whether to display labels on each sector of the donut.
Defaults to true.
final
- showLegend → bool
-
Whether to display a legend below the chart.
The legend shows each item's label, value, and percentage.
Defaults to true.
final
- showLines → bool
-
Whether to display connecting lines from center to labels.
Defaults to true.
final
- showTitle → bool
-
Whether to display the chart title.
Defaults to true.
final
- title → String
-
The title text displayed at the top of the chart.
Defaults to an empty string.
final
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited