KChartWidget class

An interactive candlestick chart.

Pass the candles positionally along with a ChartColors. Run DataUtil.calculate over the list first so the indicator fields are populated, otherwise the overlays and sub-charts have nothing to draw.

The chart supports pinch-to-zoom, fling scrolling, a long-press crosshair with an info dialog, and — when isTrendLine is set and a currentDrawingTool is selected — placing trend, horizontal and vertical lines that the user can then select, drag, restyle and delete. The onAdd* and onRemove* callbacks let you persist those.

DataUtil.calculate(candles);

KChartWidget(
  candles,
  ChartColors(),
  isTrendLine: false,
  watermarkAssetPath: 'assets/logo.svg',
  timeFrame: const Duration(minutes: 15),
  indicators: [MaIndicator(period: 20), MacdIndicator()],
);
Inheritance

Constructors

KChartWidget(List<KLineEntity>? candles, ChartColors chartColors, {required bool isTrendLine, required String watermarkAssetPath, required Duration timeFrame, double xFrontPadding = 80, List<SignalEntity> signals = const <SignalEntity>[], List<VerticalLine> verticalLines = const <VerticalLine>[], List<HorizontalLine> horizontalLines = const <HorizontalLine>[], List<TrendLine> trendLines = const <TrendLine>[], List<Indicator> indicators = const <Indicator>[], DrawingTool currentDrawingTool = DrawingTool.none, ValueChanged<TrendLine>? onAddTrendLine, ValueChanged<HorizontalLine>? onAddHorizontalLine, ValueChanged<VerticalLine>? onAddVerticalLine, ValueChanged<TrendLine>? onRemoveTrendLine, ValueChanged<HorizontalLine>? onRemoveHorizontalLine, ValueChanged<VerticalLine>? onRemoveVerticalLine, bool volHidden = false, bool isLine = false, bool isTapShowInfoDialog = false, bool hideGrid = false, bool showNowPrice = true, bool showInfoDialog = true, bool materialInfoDialog = true, ChartStyle chartStyle = const ChartStyle(), DrawingStyle drawingStyle = const DrawingStyle(), ChartTranslations chartTranslations = const ChartTranslations(), List<String> timeFormat = TimeFormat.YEAR_MONTH_DAY, Widget? infoDialogBuilder(BuildContext, KLineEntity?, KLineEntity?)?, String dateFormatter(KLineEntity, bool)?, ValueChanged<bool>? onLoadMore, int fixedLength = 2, int flingTime = 600, double flingRatio = 0.5, Curve flingCurve = Curves.decelerate, ValueChanged<bool>? isOnDrag, VerticalTextAlignment verticalTextAlignment = VerticalTextAlignment.left, double? mBaseHeight, double infoDialogWidth = 132, double infoDialogMaxWidth = 240, Key? key})
Creates a candlestick chart over candles, coloured by chartColors.
const

Properties

candles List<KLineEntity>?
The candles to draw, oldest first. Null renders a loading indicator.
final
chartColors ChartColors
Every colour the chart paints with.
final
chartStyle ChartStyle
Geometry: paddings, stroke widths and text sizes.
final
chartTranslations ChartTranslations
Labels used by the info dialog and on-chart text.
final
currentDrawingTool DrawingTool
The active drawing mode; see DrawingTool.
final
dateFormatter String Function(KLineEntity, bool)?
Overrides axis date formatting; the flag marks the long form.
final
drawingStyle DrawingStyle
How the drawing tools look and what their editor offers.
final
fixedLength int
Decimal places used for every price shown.
final
flingCurve Curve
Easing applied to the fling animation.
final
flingRatio double
Multiplier applied to fling velocity.
final
flingTime int
Duration of the fling animation, in milliseconds.
final
hashCode int
The hash code for this object.
no setterinherited
hideGrid bool
Hides the background grid.
final
horizontalLines List<HorizontalLine>
Horizontal lines to draw, typically restored from storage.
final
indicators List<Indicator>
The indicators to draw, in the order they were added.
final
infoDialogBuilder Widget? Function(BuildContext, KLineEntity?, KLineEntity?)?
Replaces the built-in long-press info dialog.
final
infoDialogMaxWidth double
Widest the long-press info dialog may grow before its rows ellipsise.
final
infoDialogWidth double
Narrowest the long-press info dialog may be.
final
isLine bool
Draws a filled close-price line instead of candles.
final
isOnDrag ValueChanged<bool>?
Reports whether the user is currently dragging the chart.
final
isTapShowInfoDialog bool
Opens the info dialog on tap as well as on long press.
final
isTrendLine bool
Enables the drawing tools and their edit panel.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
materialInfoDialog bool
Uses the Material info dialog rather than the Cupertino-styled one.
final
mBaseHeight double?
Height of the candle area, before the volume and indicator panes are added below it.
final
onAddHorizontalLine ValueChanged<HorizontalLine>?
Called when the user places or edits a horizontal line.
final
onAddTrendLine ValueChanged<TrendLine>?
Called when the user finishes drawing or edits a trend line.
final
onAddVerticalLine ValueChanged<VerticalLine>?
Called when the user places or edits a vertical line.
final
onLoadMore ValueChanged<bool>?
Fires when the user scrolls past an edge; the flag is true at the right.
final
onRemoveHorizontalLine ValueChanged<HorizontalLine>?
Called when the user deletes a horizontal line.
final
onRemoveTrendLine ValueChanged<TrendLine>?
Called when the user deletes a trend line.
final
onRemoveVerticalLine ValueChanged<VerticalLine>?
Called when the user deletes a vertical line.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
showInfoDialog bool
Enables the long-press info dialog.
final
showNowPrice bool
Draws the current price line and its countdown to the candle close.
final
signals List<SignalEntity>
Price markers painted over the candles.
final
timeFormat List<String>
Date pattern for axis labels; see TimeFormat.
final
timeFrame Duration
Duration of one candle, used to place lines and count down the close.
final
trendLines List<TrendLine>
Trend lines to draw, typically restored from storage.
final
verticalLines List<VerticalLine>
Vertical lines to draw, typically restored from storage.
final
verticalTextAlignment VerticalTextAlignment
Which side the price axis labels sit on.
final
volHidden bool
Hides the volume pane.
final
watermarkAssetPath String
Asset path of an SVG watermark; a missing asset is ignored.
final
xFrontPadding double
Empty space kept to the right of the newest candle.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<KChartWidget>
Creates the mutable state for this widget at a given location in the tree.
override
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