开源一个两年前写的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,
            ),
          ],
        ),
      ),
    );
  }
}
相关推荐
九丝城主12 小时前
2025使用VM虚拟机安装配置Macos苹果系统下Flutter开发环境保姆级教程--上篇
服务器·flutter·macos·vmware
瓜子三百克17 小时前
七、性能优化
flutter·性能优化
恋猫de小郭1 天前
Flutter Widget Preview 功能已合并到 master,提前在体验毛坯的预览支持
android·flutter·ios
小蜜蜂嗡嗡1 天前
Android Studio flutter项目运行、打包时间太长
android·flutter·android studio
瓜子三百克1 天前
十、高级概念
flutter
帅次2 天前
Objective-C面向对象编程:类、对象、方法详解(保姆级教程)
flutter·macos·ios·objective-c·iphone·swift·safari
小蜜蜂嗡嗡2 天前
flutter flutter_vlc_player播放视频设置循环播放失效、初始化后获取不到视频宽高
flutter
孤鸿玉2 天前
[Flutter小技巧] Row中widget高度自适应的几种方法
flutter
bawomingtian1232 天前
FlutterView 源码解析
flutter
Zender Han2 天前
Flutter 进阶:实现带圆角的 CircularProgressIndicator
flutter