Skip to content
Get started
Menu
Get started

Sparkline

PaymentSparkline adds a small trend beside a host-provided amount.

It answers “which way is this going?” at a glance. It has no axes, labels or value at rest, so it always sits in a row next to a KPI that states the exact amount. For a chart someone reads point by point, use Line chart.

Two rows. Spending, October, Rp2,010,000 with a small single-line trend to its right. This month vs last month, with the note 'Dashed line: last month', beside a two-line trend: a solid line for this month above a lower, flatter dashed line for last month.Two rows. Spending, October, Rp2,010,000 with a small single-line trend to its right. This month vs last month, with the note 'Dashed line: last month', beside a two-line trend: a solid line for this month above a lower, flatter dashed line for last month.
A one-series trend beside the October total, and a two-series comparison of this month and last month.
example/lib/screens/gallery_charts.dart
PaymentSparkline(points: points);

Use onSelectionChanged to receive each new selected period index and null on return to rest. The index addresses points or the series’ shared periods. Repeated events within one period do not notify or rebuild. New periods reset selection silently. The kit plays no haptics; add them in your callback if you want them.

import 'package:flutter/services.dart';
PaymentSparkline(
points: points,
inspectable: true,
onSelectionChanged: (i) {
if (i != null) HapticFeedback.selectionClick();
},
);

Variants: money, percentage, number; optional inspection.

Settled marks are solid, pending marks are outlined or dashed, and unknown marks are hatched or dotted. A null point is a gap, never zero. Use one currency per chart. Bar and meter amounts must be non-negative; line charts accept negative amounts.

Use named series with identical period labels and ordering. Line and bar charts accept up to three series; sparklines accept two. Series use an accent ramp and distinct dash patterns, never status tones. All series share a scale. showLegend controls the legend for multiple series.

axis and grid each take x, y, both or none. Colors come from named PaymentChartSeries. unit is money, percent or number.

Use a line for direction, bars for period comparisons, a meter for category proportions and a sparkline beside a KPI. Percent and number units read measure; money reads value. A measure of 45 means 45 percent. Missing readings remain gaps.

Sparklines can opt into inspectable, giving a 48 dp target. Press and hold to read a value. Unlike line and bar charts, a sparkline has no value label at rest: it sits beside a KPI that already states the amount. Meter onSegmentPressed activates full-width legend rows; the painted bar takes no taps.

Breaking: MeterSegment.color is removed. Use the semantic category ramp. MeterSegment.value is optional; supply measure for numeric units. Point value and chart points are optional when using measures or series.

PaymentChartSeries

class PaymentChartSeries · lib/src/charts/chart_models.dart

Named points sharing the same periods with the other series.

ParameterTypeDefaultDescription
label:requiredString—Legend and spoken name.
points:requiredList<ChartPoint>—One point per period.

PaymentChartAxis

enum PaymentChartAxis · lib/src/charts/chart_models.dart

Axes to label or grid.

ValueDescription
xHorizontal axis.
yVertical axis.
bothBoth axes.
noneNeither axis.

PaymentChartUnit

enum PaymentChartUnit · lib/src/charts/chart_models.dart

How a chart reads its values.

ValueDescription
moneyCurrency amounts.
percentHost-computed percentages, where 45 means 45 percent.
numberPlain counts or quantities.

ChartPoint

class ChartPoint · lib/src/charts/chart_models.dart

One period reading, with missing values distinct from zero.

ParameterTypeDefaultDescription
label:requiredString—Visible period or category label.
value:Money?—Null is missing data, never zero.
status:ChartPointStatusChartPointStatus.settledSettlement state; never encoded by a series color.
spokenLabel:String?—Optional expanded period name for spoken summaries.
measure:num?—Host-computed quantity; null is missing data.

MeterSegment

class MeterSegment · lib/src/charts/chart_models.dart

One non-negative category in a meter.

ParameterTypeDefaultDescription
label:requiredString—Visible period or category label.
value:Money?—Money reading when using currency units.
status:ChartPointStatusChartPointStatus.settledSettlement state; never encoded by a series color.
measure:num?—Host-computed non-negative quantity.

Parameters: points, series, width, height, inspectable, unit, semanticLabel, onSelectionChanged.

Situation Variant / composition Payment example
Compact spending trend money Use as a supporting trend; put exact values elsewhere when they matter.

Use Line chart for axes and detailed reading.

Missing readings leave gaps. Keep the host amount beside the trend; the sparkline does not compute a payment total.

Do: Use as a supporting trend; put exact values elsewhere when they matter.

Don’t: Use a sparkline alone to explain an exact payable amount.

Use short period labels and a clear title. Explain what is settled in the headline caption. The host supplies the headline; the kit never adds plotted values to produce a customer total.

A single generated summary announces settled lowest, highest and latest amounts plus pending, unknown and missing counts. Supply semanticLabel for a host-authored equivalent. Pointer inspection on line/bar charts is supplemental; it has no keyboard focus target. Status is conveyed by shape and words as well as color.

PaymentSparkline

class PaymentSparkline extends StatelessWidget · lib/src/charts/charts.dart

Compact trend with optional pointer inspection.

ParameterTypeDefaultDescription
points:List<ChartPoint>const []Single-series points; leave empty when providing series.
series:List<PaymentChartSeries>const []Named series with matching period labels; at most three.
unit:PaymentChartUnitPaymentChartUnit.moneyWhich reading to display and announce.
inspectable:boolfalseWhether pointer gestures select a reading.
width:double80Width.
height:double24Height.
semanticLabel:String?—Host-authored replacement for the generated summary.
onSelectionChanged:ValueChanged<int?>?—Called with the index of the period a tap or hover selects (only when inspectable); a second tap on the same period, or the pointer leaving, reports null. Not called when new points or series reset the selection. Use it to play a selection haptic (D73); the kit plays none.
  • Chart layout for height, state and headline composition.
  • Money for precise and compact amounts.