搜索插件、代码仓与 APP 分类

candlesticks 封面
插件详情v3.0.1

candlesticks

高性能、交互式的Flutter蜡烛图,适用于金融应用。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1490
喜欢数
141
Pub 分数
160

安装插件

flutter pub add candlesticks

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个高性能、交互式的蜡烛图包,专为Flutter中的金融应用设计。它能够实现实时价格走势可视化,并在Android、iOS、Web、macOS、Windows和Linux上实现平滑渲染。该包支持触摸交互,如平移和缩放,非常适合交易平台和金融仪表板。基于Dart构建,可无缝集成到Flutter应用中,并利用高效的渲染技术处理大型数据集而不会导致性能下降。

适合场景

  • 实时股票价格跟踪
  • 加密货币市场分析
  • 交易平台UI
  • 财务数据仪表板
  • 历史价格可视化

主要特点

  • 交互式平移和缩放
  • 高性能渲染
  • 跨平台支持
  • 实时数据更新
  • 可自定义的图表外观

适合对象

  • 金融应用开发者
  • 交易界面设计师
  • 数据可视化工程师
  • 加密分析工具
  • 股票市场监控应用

使用建议

  • 需要理解金融数据结构
  • 最适合时间序列价格数据
  • 可能需要额外的状态管理来实现动态更新
  • 仅限蜡烛图特定的可视化
  • 依赖外部数据源以获取实时数据流

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Candlesticks

A high-performance, interactive Flutter candlestick chart for financial apps.

Flutter Dart pub package version

iOS supported Android supported Web supported macOS supported Windows supported Linux supported

Web Demo · pub.dev · GitHub


candlesticks is a Flutter package for rendering interactive OHLCV candlestick charts.

It supports mobile and desktop gestures, crosshair interaction, panning, zooming, switching between logarithmic and linear price scales, volume bars, controller-based viewport control, lazy loading, and custom chart styling.

Preview

Web Preview

Try the live web demo:

https://r-mzy47.github.io/candlesticks/master/

On the web, use Alt/Option + scroll for anchored zoom.

Note: Ctrl + scroll is currently avoided on web because browsers may intercept it for page zoom.

Mobile Preview
Linear and logarithmic scales
Logarithmic and linear scale demo
Long press for crosshair
Long press crosshair demo
Advanced gestures: pan in any direction
Advanced chart gesture demo
Anchored and regular zoom
Anchored and regular zoom demo

Installation

Add this to your pubspec.yaml:

dependencies:
  candlesticks: ^3.0.1

Then run:

flutter pub get

Import

import 'package:candlesticks/candlesticks.dart';

Basic Usage

import 'package:candlesticks/candlesticks.dart';
import 'package:flutter/material.dart';

class ChartPage extends StatelessWidget {
  const ChartPage({super.key});

  List<Candle> get candles {
    return [
      Candle(
        date: DateTime(2024, 1, 2),
        open: 105,
        high: 115,
        low: 101,
        close: 108,
        volume: 1500,
      ),
      Candle(
        date: DateTime(2024, 1, 1),
        open: 100,
        high: 110,
        low: 95,
        close: 105,
        volume: 1200,
      ),
    ];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Candlesticks(
          candles: candles,
        ),
      ),
    );
  }
}

The candle list must be ordered from newest to oldest. The newest candle should be at index 0.

final candles = [
  newestCandle,
  previousCandle,
  olderCandle,
];

Candle Model

Candle represents one OHLCV data point.

final candle = Candle(
  date: DateTime.now(),
  open: 100,
  high: 120,
  low: 90,
  close: 110,
  volume: 5000,
);
Candle Fields
Field Type Description
date DateTime Candle timestamp. Usually the opening time of the candle interval.
open double Opening price.
high double Highest price during the candle period.
low double Lowest price during the candle period.
close double Closing price.
volume double Traded volume.
isBull bool Returns true when open <= close.

Candlesticks Widget

Constructor
const Candlesticks({
  super.key,
  required this.candles,
  this.onLoadMoreCandles,
  this.loadingWidget,
  this.controller,
  this.style,
});
Properties
Property Type Description
candles List<Candle> Candle data. The list must be ordered from newest to oldest.
onLoadMoreCandles Future<void> Function()? Called when the chart scroll position is close to the oldest loaded candle.
loadingWidget Widget? Widget displayed when candles is empty.
controller CandlesticksController? Optional controller for programmatic viewport control.
style CandleSticksStyle? Optional visual style for the chart.
Loading State

When candles is empty, the chart shows a loading indicator by default.

Candlesticks(
  candles: const [],
)

Use loadingWidget to customize it:

Candlesticks(
  candles: const [],
  loadingWidget: const Text('Loading candles...'),
)
Load More Candles

Use onLoadMoreCandles to fetch older candles when the user scrolls near the end of the loaded history.

Candlesticks(
  candles: candles,
  onLoadMoreCandles: () async {
    final olderCandles = await repository.fetchOlderCandles();

    setState(() {
      candles.addAll(olderCandles);
    });
  },
)

Older candles should be added to the end of the list.

candles = [
  newestCandle,
  previousCandle,
  olderCandle,
  evenOlderCandle,
];
Controller

Use CandlesticksController when you want to control the chart viewport manually.

final controller = CandlesticksController();
Candlesticks(
  candles: candles,
  controller: controller,
)

Dispose the controller if you create it inside a State object:

@override
void dispose() {
  controller.dispose();
  super.dispose();
}
Controller Example
class ControlledChartPage extends StatefulWidget {
  const ControlledChartPage({super.key});

  @override
  State<ControlledChartPage> createState() => _ControlledChartPageState();
}

class _ControlledChartPageState extends State<ControlledChartPage> {
  final CandlesticksController controller = CandlesticksController();

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Row(
          children: [
            IconButton(
              onPressed: controller.zoomIn,
              icon: const Icon(Icons.zoom_in),
            ),
            IconButton(
              onPressed: controller.zoomOut,
              icon: const Icon(Icons.zoom_out),
            ),
            IconButton(
              onPressed: () => controller.animateTo(-10),
              icon: const Icon(Icons.keyboard_double_arrow_right),
            ),
          ],
        ),
        Expanded(
          child: Candlesticks(
            candles: candles,
            controller: controller,
          ),
        ),
      ],
    );
  }
}
Common Controller Members
Member Description
isNearEnd Whether the visible range is close to the oldest loaded candle.
jumpTo(double index) Jumps to a scroll index without animation.
animateTo(double index) Animates to a scroll index.
setZoom(double width) Sets candle width directly.
zoomBy(double factor) Multiplies the current candle width by a factor.
zoomIn() Zooms in by a fixed step.
zoomOut() Zooms out by a fixed step.
scrollByPixels(...) Scrolls horizontally by a pixel delta.

Styling

By default, the chart chooses a light or dark style based on the current Flutter theme.

Candlesticks(
  candles: candles,
)

You can pass your own style:

Candlesticks(
  candles: candles,
  style: CandleSticksStyle.dark(
    chartBackgroundColor: const Color(0xFF0F0F0F),
    candleBullColor: const Color(0xFF26A69A),
    candleBearColor: const Color(0xFFEF5350),
  ),
)

Or use the light style:

Candlesticks(
  candles: candles,
  style: CandleSticksStyle.light(),
)
Style Fields
Field Description
chartBackgroundColor Main chart background.
gridLineColor Horizontal and vertical grid lines.
axisTextColor Price and time axis text.
candleBullColor Bullish candle body and wick.
candleBearColor Bearish candle body and wick.
volumeBullColor Bullish volume bar.
volumeBearColor Bearish volume bar.
crosshairLineColor Dashed crosshair line.
crosshairLabelBackgroundColor Crosshair price/time label background.
crosshairLabelTextColor Crosshair price/time label text.
ohlcInfoTextColor OHLC info label text.
ohlcInfoBullColor Bullish OHLC value text.
ohlcInfoBearColor Bearish OHLC value text.
priceIndicatorBullBackgroundColor Last price label background when the latest candle is bullish.
priceIndicatorBearBackgroundColor Last price label background when the latest candle is bearish.
priceIndicatorTextColor Last price label text.
scaleButtonActiveBackgroundColor Active scale button background.
scaleButtonActiveTextColor Active scale button text.
scaleButtonInactiveBackgroundColor Inactive scale button background.
scaleButtonInactiveTextColor Inactive scale button text.
loadingIndicatorColor Default loading indicator color.

Example App

The repository includes a complete example app that demonstrates the core features of this package in a real project.

The example app uses the Binance API and includes:

  • Symbol search
  • Timeframe selection
  • Historical candle loading
  • Real-time price updates

Run it locally:

cd example
flutter run

Live web example:

https://r-mzy47.github.io/candlesticks/master/

Migration Guide

See MIGRATION.md for the migration guide from version 2.x to version 3.0.0.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。