TradingChartController class

Top-level controller managing chart state, gestures, viewport, indicators, and live data stream.

Inheritance

Constructors

TradingChartController({required String symbol, required ChartDataSource dataSource, String exchange = 'NSE', String brandName = 'Im Charts', Timeframe initialTimeframe = Timeframe.fiveMinutes, CandleStyle initialCandleStyle = CandleStyle.candles, ChartTheme? theme})

Properties

activeDrawingTool ↔ DrawingTool
getter/setter pair
activeIndicators → List<Indicator>
no setter
alerts → List<ChartAlert>
no setter
allCandlesCount → int
no setter
brandName ↔ String
Brand name displayed in watermarks and institutional overlays (defaults to 'Im Charts').
getter/setter pair
candleCountdownText → String
Formatted countdown to current candle close (e.g. '04:12' or '00:23').
no setter
candles → List<Candle>
no setter
candleStyle → CandleStyle
no setter
canRedo → bool
Whether there is a subsequent drawing state available to redo.
no setter
canUndo → bool
Whether there is a previous drawing state available to undo.
no setter
crosshairPosition → Offset?
no setter
currentCandle → Candle?
no setter
currentPriceRange → PriceRange
Visible auto-scaled price range with vertical scale & pan applied.
no setter
dataSource → ChartDataSource
final
drawings → List<ChartDrawing>
no setter
exchange → String
no setter
hashCode → int
The hash code for this object.
no setterinherited
hasListeners → bool
Whether any listeners are currently registered.
no setterinherited
hasSubPane → bool
True when at least one sub-pane indicator (e.g. RSI, MACD) is active.
no setter
hoveredCandle → Candle?
no setter
isDarkTheme → bool
no setter
isDisposed → bool
no setter
isLoading → bool
no setter
isManualPriceScale → bool
no setter
isReplaying → bool
no setter
isReplayMode → bool
no setter
magnetMode → bool
Whether magnet mode is active (snapping drawing anchors to candle OHLC).
no setter
mainPaneHeight → double
Height of the main chart canvas pane (excluding sub-pane and bottom time axis).
no setter
onAlertTriggered ↔ void Function(ChartAlert alert)?
getter/setter pair
onDrawingAdded ↔ void Function(ChartDrawing drawing)?
getter/setter pair
onDrawingRemoved ↔ void Function(String drawingId)?
getter/setter pair
onOrderCancelled ↔ void Function(String drawingId)?
getter/setter pair
onOrderModified ↔ void Function(ChartOrder order)?
getter/setter pair
onOrderPlaced ↔ void Function(ChartOrder order)?
getter/setter pair
onPositionClosed ↔ void Function(ChartPosition position)?
getter/setter pair
onPositionOpened ↔ void Function(ChartPosition position)?
getter/setter pair
onSaveCallback ↔ Future<void> Function(String serializedData)?
getter/setter pair
orders → List<ChartOrder>
no setter
overlayResults → List<IndicatorResult>
no setter
positions → List<ChartPosition>
no setter
previewDrawing → ChartDrawing?
no setter
priceAxisWidth ↔ double
getter/setter pair
priceScaleMode → PriceScaleMode
Current price scale mode: normal, log, or percent.
no setter
replayIndex → int?
no setter
replaySpeed → double
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
saveState → ChartSaveState
no setter
selectedDrawing → ChartDrawing?
no setter
showCountdownTimer ↔ bool
getter/setter pair
showCrosshair → bool
no setter
showGrid → bool
no setter
showSma → bool
Whether SMA 20 is currently active on the chart.
no setter
showSMC ↔ bool
getter/setter pair
showSupertrend → bool
Whether Supertrend is currently active on the chart.
no setter
showVolume ↔ bool
getter/setter pair
showVolumeProfile ↔ bool
getter/setter pair
showWatermark ↔ bool
getter/setter pair
smc → SmartMoneyConcepts?
no setter
subPaneRatio ↔ double
Sub-pane height ratio (0.0–0.5). Default 0.25 = 25%.
getter/setter pair
subPaneResult → IndicatorResult?
no setter
subPaneResults → List<IndicatorResult>
no setter
symbol → String
no setter
syncGroup ↔ ChartSyncGroup?
getter/setter pair
theme ↔ ChartTheme
getter/setter pair
timeframe → Timeframe
no setter
verticalPan → double
no setter
verticalScale → double
no setter
viewport → ChartViewport
no setter
volumeProfile → VolumeProfile?
no setter

Methods

addAlert(ChartAlert alert) → void
addDrawing(ChartDrawing drawing) → void
Adds a new user drawing to the chart canvas.
addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
cancelActiveDrawing() → void
Cancels in-progress drawing, resets tool to pointer, and clears preview.
cancelOrder(String orderId) → void
Cancels an order and removes it from the chart canvas.
clearAlerts() → void
clearDrawings() → void
Clears all drawings from the chart canvas.
clearIndicators() → void
Clears all active indicators from the chart.
clearOrders() → void
Clears all active orders from the chart.
clearPositions() → void
Clears all open positions from the chart.
closePosition(String positionId) → void
Closes an open position and removes it from the chart canvas.
cyclePriceScaleMode() → void
Cycles the price scale mode: Normal → Log → Percent → Normal.
deleteSelectedDrawing() → void
Deletes the currently selected drawing.
dispose() → void
Discards any resources used by the object.
override
exitReplay() → void
exportDrawingsJson() → String
Serializes all current drawings into a JSON string.
exportSettingsJson() → String
Serializes chart layout, settings, timeframe, candle style, and drawings to JSON.
importDrawingsJson(String jsonString) → void
Imports drawings from a JSON string, restoring them onto the chart.
initialize() → Future<void>
Loads initial historical data and establishes real-time tick ingestion.
isIndicatorActive(String id) → bool
joinSyncGroup(ChartSyncGroup group) → void
leaveSyncGroup() → void
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
onPan(double deltaX) → void
Horizontal scroll / pan gesture handler.
onPinchZoom(double scaleFactor, Offset focalPoint, double panDeltaX) → void
Unified atomic pinch-to-zoom & pan method. Smoothly adjusts candleWidth clamped to 1.5, 60.0 while anchoring the zoom around focalPoint and translating by panDeltaX, preserving focal stability identical to TradingView.
onTimeScale(double deltaX) → void
Horizontal scale drag on time scale (X-axis zoom).
onVerticalPan(double deltaY, double paneHeight) → void
Vertical pan when manual price scaling is active.
onVerticalScale(double deltaY) → void
Vertical scale drag on price scale (Y-axis zoom).
onZoom(double scaleFactor, Offset focalPoint) → void
Focal-point aware horizontal zoom (pinch zoom or mouse wheel).
openPosition(ChartPosition position) → void
Opens an executed position on the chart.
pauseReplay() → void
placeOrder(ChartOrder order) → void
Places an active order on the chart canvas.
playReplay() → void
priceAtY(double y) → double
Converts screen Y coordinate inside main pane to financial price.
receiveSyncedCrosshair(DateTime? timestamp, double? yPriceRatio) → void
Handles crosshair synchronization from another chart in the ChartSyncGroup.
receiveSyncedPan(double deltaX) → void
Handles synchronized horizontal pan from ChartSyncGroup.
receiveSyncedZoom(double scaleFactor, double focalPointRatio) → void
Handles synchronized zoom from ChartSyncGroup.
recordDrawingSnapshot() → void
Records the current state of drawings to the undo stack.
redo() → void
Reapplies drawings to the next forward state in history.
refreshData() → Future<void>
Manually refreshes historical data and restarts stream.
removeAlert(String id) → void
removeDrawing(String id) → void
Removes a drawing from the chart canvas.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
removeSubPane(String indicatorId) → void
resetPriceScale() → void
Resets vertical price scale back to auto-scale.
resetTimeScale() → void
Resets horizontal time scale back to default.
resetView() → void
Resets both time and price scale to default view.
saveChart() → Future<void>
Persists the current chart configuration and drawings asynchronously.
scrollToLatest() → void
Jumps to the latest forming candle.
selectDrawing(String? id) → void
Selects a drawing by ID or deselects all if null.
setCandles(List<Candle> candles) → void
Directly sets the candle dataset and recalculates all active technical indicators.
setCandleStyle(CandleStyle style) → void
Changes the candle presentation style (Candles, Hollow, Heikin Ashi, Line, Area, Bars).
setCrosshairPosition(Offset? position) → void
Updates crosshair position and extracts hovered candle under pointer.
setExchange(String newExchange) → void
Switches exchange (NSE vs BSE).
setMagnetMode(bool enabled) → void
Sets magnet snapping mode directly.
setOrders(List<ChartOrder> orders) → void
Replaces active orders on the chart.
setPositions(List<ChartPosition> positions) → void
Replaces open positions on the chart.
setPreviewDrawing(ChartDrawing? preview) → void
Updates the live drawing preview while the user is actively drawing.
setReplaySpeed(double speed) → void
setScrollOffset(double offset) → void
Sets horizontal scroll offset directly with boundary clamping.
setSelectedDrawingColor(Color color) → void
Updates the color of the currently selected drawing.
setSelectedDrawingStrokeWidth(double strokeWidth) → void
Updates the stroke width of the currently selected drawing.
setSymbol(String newSymbol, {String? exchange}) → Future<void>
Sets a new symbol and reloads chart data.
setTheme(ChartTheme newTheme) → void
Sets an explicit theme.
setTimeframe(Timeframe newTimeframe) → Future<void>
Changes chart timeframe and refreshes historical candles.
snapPointToCandle(DrawingPoint rawPoint) → DrawingPoint
Snaps a drawing point's price to the closest candle Open, High, Low, or Close if magnet mode is enabled and candles exist at or near rawPoint.candleIndex.
startReplay([int? startIndex]) → void
stepReplayBackward() → void
stepReplayForward() → void
toggleCrosshair() → void
Toggles crosshair on/off.
toggleGrid() → void
Toggles grid lines on/off.
toggleIndicator(Indicator indicator) → void
Toggles an indicator on or off.
toggleMagnetMode() → void
Toggles magnet snapping mode on or off.
toggleReplayPlay() → void
toggleSelectedDrawingLocked() → void
Toggles the lock state of the currently selected drawing.
toggleSma([int period = 20]) → void
Toggles Simple Moving Average (SMA) on or off.
toggleSMC() → void
toggleSupertrend({int period = 10, double multiplier = 3.0}) → void
Toggles Supertrend trend-following indicator on or off.
toggleTheme() → void
Toggles dark / light theme.
toggleVolume() → void
Toggles volume histogram on/off.
toggleVolumeProfile() → void
toString() → String
A string representation of this object.
inherited
translateDrawing(String id, int deltaCandles, double deltaPrice) → void
Translates all points and prices of a drawing by a given candle and price delta.
triggerAutoSave() → void
Schedules an auto-save operation with debouncing.
undo() → void
Undoes the last drawing modification.
updateAlert(ChartAlert alert) → void
updateDimensions(double width, double height, [double? priceAxisWidth]) → void
Updates viewport canvas dimensions (called by LayoutBuilder in UI).
updateDrawing(ChartDrawing drawing) → void
Updates an existing drawing (e.g. dragging an anchor point).
updateDrawingPoint(String id, int pointIndex, DrawingPoint newPoint) → void
Updates a specific anchor point index of a drawing.
updateDrawingProperties(String id, Map<String, dynamic> newProperties) → void
Updates arbitrary metadata properties on a drawing (e.g. targetPrice, stopPrice, widthSpan).
updateOrderBrackets(String orderId, {double? takeProfitPrice, double? stopLossPrice, bool clearTakeProfit = false, bool clearStopLoss = false}) → void
Updates or attaches Take Profit and/or Stop Loss brackets to an order.
updateOrderPrice(String orderId, double newPrice) → void
Updates the limit price of an existing order.
updatePosition(ChartPosition position) → void
Updates an open position (e.g. adjust TP/SL or average price).
yAtPrice(double price) → double
Converts financial price to screen Y coordinate inside main pane.
zoomIn() → void
Zoom in horizontally by 25%.
zoomInPrice() → void
Zoom in price scale vertically.
zoomOut() → void
Zoom out horizontally by 20%.
zoomOutPrice() → void
Zoom out price scale vertically.

Operators

operator ==(Object other) → bool
The equality operator.
inherited