开源一个两年前写的flutter的K线分时图

ace_chart

两年前做的股票项目,用了一些开源的插件有些数据卡顿,有些滚动卡顿,参考了几个开源的库,具体名字忘了哪些。。股票K线图/分时图/vol图/mac的图/双极图,在币圈的行情下使用的话,有些地方需要修改。已发不到pub.dev pub.dev/packages/ac...

Screenshot

Demo

dart 复制代码
import 'dart:async';

import 'package:ace_chart/ace_chart.dart';
import 'package:demo/data.dart'; // 数据list,文章字数有限制,请从github获取
import 'package:demo/data2.dart'; // 数据list2,,文章字数有限制,请从github获取
import 'package:flutter/material.dart';

const Color backgroundColor = Color(0xff151924);
const Color textColor = Colors.white;
const TextStyle style = TextStyle(color: textColor);

class Home extends StatefulWidget {
  const Home({super.key});

  @override
  State<Home> createState() => _HomeState();
}

int ii = 0;

class _HomeState extends State<Home> {
  final AceStockMetricController container = AceStockMetricController(
    useVOLMA: true,
    useMACD: true,
    maxLength: list.length,
    // maDays: [5],
    pointWidth: 7,
    useKdj: true,
  );
  final AceStockMetricController container3 = AceStockMetricController(
    useVOLMA: true,
    useMACD: true,
    maxLength: list2.length,
    maDays: [],
    useKdj: true,
  );

  @override
  void initState() {
    super.initState();
    int i = 60;
    container.addAll(list.sublist(0, i));
    Timer.periodic(const Duration(milliseconds: 10), (timer) {
      if (i < list.length) {
        container.addValue(list[i]);
      } else {
        timer.cancel();
      }
      i++;
    });
    Timer.periodic(const Duration(milliseconds: 10), (timer) {
      if (ii < list2.length) {
        container3.addValue(list2[ii]);
      } else {
        timer.cancel();
      }
      ii++;
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          "DEMO",
          style: style,
        ),
        backgroundColor: backgroundColor,
      ),
      backgroundColor: backgroundColor,
      body: SingleChildScrollView(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            AceContainer(
              controller: container3,
              child: Builder(
                builder: (context) {
                  return Column(
                    children: [
                      SizedBox(
                        height: 150,
                        child: LineChart(
                          transformTime: (time) {
                            return millisToHM(time);
                          },
                          lineColor: const Color(0xff697abc),
                          lastClose: 255.90,
                          gridVerticalGrids: 1,
                          gridHorizontalGrids: 2,
                          paddingTop: 20,
                          centralAxisStyle: const TextStyle(
                            color: Colors.white,
                            fontSize: 8,
                          ),
                          gridLineColor: Colors.white12,
                          crossLineColor: const Color(0xffd13e51),
                          crossTextBgColor: const Color(0xffd13e51),
                          horizontalTextStyle: const TextStyle(
                            color: Color(0xff959FAE),
                            fontSize: 8,
                          ),
                        ),
                      ),
                      Container(
                        height: 10,
                        color: Colors.black,
                      ),
                      const SizedBox(
                        height: 40,
                        child: VolChart(
                          showMaLine: true,
                          showText: false,
                          upperStyle: PaintingStyle.stroke,
                        ),
                      ),
                      Container(
                        height: 10,
                        color: Colors.black,
                      ),
                      const SizedBox(
                        height: 80,
                        child: MacdChart(
                          textStyle: TextStyle(
                            color: Colors.white,
                            fontSize: 8,
                          ),
                        ),
                      ),
                    ],
                  );
                },
              ),
            ),
            Container(
              height: 10,
              margin: const EdgeInsets.symmetric(vertical: 3),
              color: Colors.black,
            ),
            Container(
              color: Colors.black12,
              child: AceContainer(
                controller: container,
                child: Builder(
                  builder: (context) {
                    return Column(
                      children: [
                        SizedBox(
                          height: 150,
                          child: KChart(
                            highMarkColor: Colors.white,
                            lowMarkColor: Colors.white,
                            crossLineColor: const Color(0xffd13e51),
                            crossTextBgColor: const Color(0xffd13e51),
                            gridTextStyle: const TextStyle(
                              color: Colors.white,
                              fontSize: 8,
                            ),
                            gridLineColor: Colors.white12,
                            horizontalTextStyle: const TextStyle(
                              color: Color(0xff959FAE),
                              fontSize: 8,
                            ),
                            transformTime: (time) {
                              return millisToMD(time);
                            },
                            onCrossChange: (index, alignment) {
                              if (index == -1) {
                                return;
                              }
                            },
                          ),
                        ),
                        Container(
                          height: 10,
                          margin: const EdgeInsets.symmetric(vertical: 3),
                          color: Colors.black,
                        ),
                        const SizedBox(
                          height: 40,
                          child: VolChart(
                            showMaLine: true,
                            showText: false,
                            upperStyle: PaintingStyle.stroke,
                            textStyle: TextStyle(
                              color: Colors.white,
                              fontSize: 8,
                            ),
                          ),
                        ),
                        Container(
                          height: 10,
                          margin: const EdgeInsets.symmetric(vertical: 3),
                          color: Colors.black,
                        ),
                        const SizedBox(
                          height: 80,
                          child: MacdChart(
                            textStyle: TextStyle(
                              color: Colors.white,
                              fontSize: 8,
                            ),
                          ),
                        ),
                        Container(
                          height: 10,
                          margin: const EdgeInsets.symmetric(vertical: 3),
                          color: Colors.black,
                        ),
                        Padding(
                          padding: const EdgeInsets.all(20),
                          child: SizedBox(
                            height: 199,
                            width: 199,
                            child: CircularProgressIndicator(
                              value: (ii + 1) / list2.length,
                              strokeWidth: 10,
                              color: const Color(0xff9096FF),
                              backgroundColor: Colors.white54,
                            ),
                          ),
                        ),
                      ],
                    );
                  },
                ),
              ),
            ),
            const SizedBox(
              height: 10,
            ),
          ],
        ),
      ),
    );
  }
}
相关推荐
王二蛋与他的张大花1 天前
后台内存 827MB,我一行业务逻辑都没改就砍到 100MB
android·flutter·性能优化
恋猫de小郭1 天前
Flutter 的FFI/JNI 插件终于能区分不同的 FlutterEngine 了
android·前端·flutter
晚霞的不甘2 天前
Flutter/OpenHarmony 三方库适配实战:google_maps_flutter 地图
flutter·macos·华为·cocoa·harmonyos·1024程序员节
恋猫de小郭2 天前
Flutter HC 旋转 ANR,而且还和之前的 HCPP 问题类似
android·前端·flutter
恋猫de小郭3 天前
Flutter Perfetto:Dart Heap Sampling 终于要接入 Android 原生内存分析了
android·前端·flutter
程序员老刘4 天前
Flutter版本选择指南:尽早升级3.47.9 | 2026年11月
flutter·ai编程·客户端
恋猫de小郭4 天前
Android Keep Rules 解读,直接影响 Google Play 上架和曝光
android·前端·flutter
恋猫de小郭5 天前
Flutter A2UI 1.0 ,原来的 genui 也正式换成了这一套 SDK 了
android·前端·flutter
LinXunFeng5 天前
A2UI 1.0 详解:让 AI 生成 Flutter 界面,还不怕它乱写
前端·flutter·agent
好的佩奇6 天前
Dart 之元数据与注解
android·flutter·dart