├── .gitignore ├── .metadata ├── CHANGELOG.md ├── LICENSE ├── README.md ├── example ├── .gitignore ├── .metadata ├── README.md ├── analysis_options.yaml ├── android │ ├── .gitignore │ ├── app │ │ ├── build.gradle │ │ └── src │ │ │ ├── debug │ │ │ └── AndroidManifest.xml │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── kotlin │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── example │ │ │ │ │ └── MainActivity.kt │ │ │ └── res │ │ │ │ ├── drawable-v21 │ │ │ │ └── launch_background.xml │ │ │ │ ├── drawable │ │ │ │ └── launch_background.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── values-night │ │ │ │ └── styles.xml │ │ │ │ └── values │ │ │ │ └── styles.xml │ │ │ └── profile │ │ │ └── AndroidManifest.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ └── gradle-wrapper.properties │ └── settings.gradle ├── assets │ ├── chatData.json │ └── depth.json ├── images │ ├── Screenshot1.jpg │ ├── Screenshot2.jpg │ ├── Screenshot3.jpeg │ ├── demo.gif │ └── demo2.gif ├── ios │ ├── .gitignore │ ├── Flutter │ │ ├── AppFrameworkInfo.plist │ │ ├── Debug.xcconfig │ │ └── Release.xcconfig │ ├── Runner.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ │ └── WorkspaceSettings.xcsettings │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ └── WorkspaceSettings.xcsettings │ └── Runner │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ ├── Contents.json │ │ │ ├── Icon-App-1024x1024@1x.png │ │ │ ├── Icon-App-20x20@1x.png │ │ │ ├── Icon-App-20x20@2x.png │ │ │ ├── Icon-App-20x20@3x.png │ │ │ ├── Icon-App-29x29@1x.png │ │ │ ├── Icon-App-29x29@2x.png │ │ │ ├── Icon-App-29x29@3x.png │ │ │ ├── Icon-App-40x40@1x.png │ │ │ ├── Icon-App-40x40@2x.png │ │ │ ├── Icon-App-40x40@3x.png │ │ │ ├── Icon-App-60x60@2x.png │ │ │ ├── Icon-App-60x60@3x.png │ │ │ ├── Icon-App-76x76@1x.png │ │ │ ├── Icon-App-76x76@2x.png │ │ │ └── Icon-App-83.5x83.5@2x.png │ │ └── LaunchImage.imageset │ │ │ ├── Contents.json │ │ │ ├── LaunchImage.png │ │ │ ├── LaunchImage@2x.png │ │ │ ├── LaunchImage@3x.png │ │ │ └── README.md │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ └── Runner-Bridging-Header.h ├── lib │ └── main.dart ├── linux │ ├── .gitignore │ ├── CMakeLists.txt │ ├── flutter │ │ ├── CMakeLists.txt │ │ ├── generated_plugin_registrant.cc │ │ ├── generated_plugin_registrant.h │ │ └── generated_plugins.cmake │ ├── main.cc │ ├── my_application.cc │ └── my_application.h ├── macos │ ├── .gitignore │ ├── Flutter │ │ ├── Flutter-Debug.xcconfig │ │ ├── Flutter-Release.xcconfig │ │ └── GeneratedPluginRegistrant.swift │ ├── Runner.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ └── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── Runner │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ ├── Contents.json │ │ │ ├── app_icon_1024.png │ │ │ ├── app_icon_128.png │ │ │ ├── app_icon_16.png │ │ │ ├── app_icon_256.png │ │ │ ├── app_icon_32.png │ │ │ ├── app_icon_512.png │ │ │ └── app_icon_64.png │ │ ├── Base.lproj │ │ └── MainMenu.xib │ │ ├── Configs │ │ ├── AppInfo.xcconfig │ │ ├── Debug.xcconfig │ │ ├── Release.xcconfig │ │ └── Warnings.xcconfig │ │ ├── DebugProfile.entitlements │ │ ├── Info.plist │ │ ├── MainFlutterWindow.swift │ │ └── Release.entitlements ├── pubspec.yaml ├── test │ └── widget_test.dart ├── web │ ├── favicon.png │ ├── icons │ │ ├── Icon-192.png │ │ ├── Icon-512.png │ │ ├── Icon-maskable-192.png │ │ └── Icon-maskable-512.png │ ├── index.html │ └── manifest.json └── windows │ ├── .gitignore │ ├── CMakeLists.txt │ ├── flutter │ ├── CMakeLists.txt │ ├── generated_plugin_registrant.cc │ ├── generated_plugin_registrant.h │ └── generated_plugins.cmake │ └── runner │ ├── CMakeLists.txt │ ├── Runner.rc │ ├── flutter_window.cpp │ ├── flutter_window.h │ ├── main.cpp │ ├── resource.h │ ├── resources │ └── app_icon.ico │ ├── runner.exe.manifest │ ├── utils.cpp │ ├── utils.h │ ├── win32_window.cpp │ └── win32_window.h ├── lib ├── chart_style.dart ├── chart_translations.dart ├── depth_chart.dart ├── entity │ ├── candle_entity.dart │ ├── cci_entity.dart │ ├── depth_entity.dart │ ├── index.dart │ ├── info_window_entity.dart │ ├── k_entity.dart │ ├── k_line_entity.dart │ ├── kdj_entity.dart │ ├── macd_entity.dart │ ├── rsi_entity.dart │ ├── rw_entity.dart │ └── volume_entity.dart ├── extension │ ├── map_ext.dart │ └── num_ext.dart ├── flutter_k_chart.dart ├── k_chart_widget.dart ├── renderer │ ├── base_chart_painter.dart │ ├── base_chart_renderer.dart │ ├── chart_painter.dart │ ├── index.dart │ ├── main_renderer.dart │ ├── secondary_renderer.dart │ └── vol_renderer.dart └── utils │ ├── data_util.dart │ ├── date_format_util.dart │ ├── index.dart │ └── number_util.dart └── pubspec.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # Visual Studio Code related 19 | .vscode/ 20 | 21 | # Flutter/Dart/Pub related 22 | **/doc/api/ 23 | .dart_tool/ 24 | .flutter-plugins 25 | .packages 26 | .pub-cache/ 27 | .pub/ 28 | build/ 29 | 30 | # Android related 31 | **/android/**/gradle-wrapper.jar 32 | **/android/.gradle 33 | **/android/captures/ 34 | **/android/gradlew 35 | **/android/gradlew.bat 36 | **/android/local.properties 37 | **/android/**/GeneratedPluginRegistrant.java 38 | 39 | # iOS/XCode related 40 | **/ios/**/*.mode1v3 41 | **/ios/**/*.mode2v3 42 | **/ios/**/*.moved-aside 43 | **/ios/**/*.pbxuser 44 | **/ios/**/*.perspectivev3 45 | **/ios/**/*sync/ 46 | **/ios/**/.sconsign.dblite 47 | **/ios/**/.tags* 48 | **/ios/**/.vagrant/ 49 | **/ios/**/DerivedData/ 50 | **/ios/**/Icon? 51 | **/ios/**/Pods/ 52 | **/ios/**/.symlinks/ 53 | **/ios/**/profile 54 | **/ios/**/xcuserdata 55 | **/ios/.generated/ 56 | **/ios/Flutter/App.framework 57 | **/ios/Flutter/Flutter.framework 58 | **/ios/Flutter/Generated.xcconfig 59 | **/ios/Flutter/app.flx 60 | **/ios/Flutter/app.zip 61 | **/ios/Flutter/flutter_assets/ 62 | **/ios/ServiceDefinitions.json 63 | **/ios/Runner/GeneratedPluginRegistrant.* 64 | 65 | # Exceptions to above rules. 66 | !**/ios/**/default.mode1v3 67 | !**/ios/**/default.mode2v3 68 | !**/ios/**/default.pbxuser 69 | !**/ios/**/default.perspectivev3 70 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages 71 | example/ios/Flutter/flutter_export_environment.sh 72 | *.lock 73 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: 7a4c33425ddd78c54aba07d86f3f9a4a0051769b 8 | channel: unknown 9 | 10 | project_type: package 11 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [0.1.1] 2 | 3 | * NEW: Initial Release. 4 | 5 | ## [0.1.2] 6 | 7 | * NEW: Add Hidden Volume 8 | 9 | ## [0.1.3] 10 | 11 | * NEW: Add CCI 12 | 13 | ## [0.1.4] 14 | 15 | * NEW: Add onSecondaryTap 16 | * Changed the k-line drawing logic 17 | 18 | ## [0.2.0] 19 | 20 | * NEW: Added real-time price display 21 | * Breaking Change: Ability to customise UI of KChartWidget.(The chartStyle and chartColors must be specified) 22 | 23 | ## [0.2.1] 24 | 25 | * Fix: Fixed some UI issues about zooming 26 | 27 | ## [0.3.0] 28 | 29 | * Breaking Change: null safety. 30 | * NEW: Add line under Touch Dialog. 31 | 32 | ## [0.3.1] 33 | 34 | * NEW: More color can change. 35 | 36 | ## [0.3.2] 37 | 38 | * NEW: You can show or hide the grid. 39 | * Changed the multi-language implementation.(Please migrate to the new way as soon as possible) 40 | * Changed the period of kdj from 14 to 9. 41 | 42 | ## [0.4.0] 43 | 44 | * Changed the way the marker values are displayed, from right to left. 45 | * Changed the UI when gridlines are hidden. 46 | * Upgraded the display of real-time prices. 47 | * More configurations are available. 48 | 49 | ## [0.4.1] 50 | 51 | * Fix a bug about NPE. 52 | 53 | ## [0.5.0] 54 | 55 | * Fixed Vertical text alignment and make amount nullable. 56 | * Fixed nowPrice text painting position. 57 | * Add click show detailed data. 58 | * View display area boundary value drawing. 59 | * Always show the now price. 60 | 61 | ## [0.6.0] 62 | 63 | * Delete `bgColor` api.('Use `chartColors.bgColor` instead.') 64 | * Add TradeLine. 65 | * Fixed about data not contain `change` or `radio`. 66 | 67 | ## [0.6.1] 68 | 69 | * Add `chartColors.lineFillInsideColor`. 70 | * Add `materialInfoDialog` config. 71 | * Fix: removes duplicate crossLine and crossLine text rendering. 72 | 73 | ## [0.7.0] 74 | 75 | * Add `xFrontPadding`. (padding in front. default 100) 76 | * Fix: KChart and DepthChart onPress selection when they don't fill the whole screen. 77 | 78 | ## [0.7.1] 79 | * Optimize performance on the web. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2019 Mafanwei 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 5 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 | 7 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | 9 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 10 | © 2019 GitHub, Inc. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # k_chart 2 | Maybe this is the best k chart in Flutter.Support drag,scale,long press,fling.And easy to use. 3 | 4 | ## display 5 | 6 | #### image 7 | 8 | Screenshot 9 | 10 | Screenshot 11 | 12 | Screenshot 13 | 14 | #### gif 15 | 16 | ![demo](https://github.com/mafanwei/k_chart/blob/master/example/images/demo.gif) 17 | 18 | ![demo](https://github.com/mafanwei/k_chart/blob/master/example/images/demo2.gif) 19 | 20 | ## Getting Started 21 | #### Install 22 | ``` 23 | dependencies: 24 | k_chart: ^0.7.1 25 | ``` 26 | or use latest: 27 | ``` 28 | k_chart: 29 | git: 30 | url: https://github.com/mafanwei/k_chart 31 | ``` 32 | #### Usage 33 | 34 | **When you change the data, you must call this:** 35 | ```dart 36 | DataUtil.calculate(datas); //This function has some optional parameters: n is BOLL N-day closing price. k is BOLL param. 37 | ``` 38 | 39 | use k line chart: 40 | ```dart 41 | Container( 42 | height: 450, 43 | width: double.infinity, 44 | child: KChartWidget( 45 | chartStyle, // Required for styling purposes 46 | chartColors,// Required for styling purposes 47 | datas,// Required,Data must be an ordered list,(history=>now) 48 | isLine: isLine,// Decide whether it is k-line or time-sharing 49 | mainState: _mainState,// Decide what the main view shows 50 | secondaryState: _secondaryState,// Decide what the sub view shows 51 | fixedLength: 2,// Displayed decimal precision 52 | timeFormat: TimeFormat.YEAR_MONTH_DAY, 53 | onLoadMore: (bool a) {},// Called when the data scrolls to the end. When a is true, it means the user is pulled to the end of the right side of the data. When a 54 | // is false, it means the user is pulled to the end of the left side of the data. 55 | maDayList: [5,10,20],// Display of MA,This parameter must be equal to DataUtil.calculate‘s maDayList 56 | translations: kChartTranslations,// Graphic language 57 | volHidden: false,// hide volume 58 | showNowPrice: true,// show now price 59 | isOnDrag: (isDrag){},// true is on Drag.Don't load data while Draging. 60 | onSecondaryTap:(){},// on secondary rect taped. 61 | isTrendLine: false, // You can use Trendline by long-pressing and moving your finger after setting true to isTrendLine property. 62 | xFrontPadding: 100 // padding in front 63 | ), 64 | ), 65 | ``` 66 | use depth chart: 67 | ```dart 68 | DepthChart(_bids, _asks, chartColors) //Note: Datas must be an ordered list, 69 | ``` 70 | 71 | #### Donate 72 | 73 | Buy a cup of coffee for the author. 74 | 75 | alipay 76 | wechat 77 | 78 | #### Thanks 79 | [gwhcn/flutter_k_chart](https://github.com/gwhcn/flutter_k_chart) 80 | 81 | #### Other 82 | Maybe there are some bugs in this k chart,or you want new indicators,you can create a pull request.I will happy to accept it and I hope we can make it better. 83 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | migrate_working_dir/ 12 | 13 | # IntelliJ related 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # The .vscode folder contains launch configuration and tasks you configure in 20 | # VS Code which you may wish to be included in version control, so this line 21 | # is commented out by default. 22 | #.vscode/ 23 | 24 | # Flutter/Dart/Pub related 25 | **/doc/api/ 26 | **/ios/Flutter/.last_build_id 27 | .dart_tool/ 28 | .flutter-plugins 29 | .flutter-plugins-dependencies 30 | .packages 31 | .pub-cache/ 32 | .pub/ 33 | /build/ 34 | 35 | # Symbolication related 36 | app.*.symbols 37 | 38 | # Obfuscation related 39 | app.*.map.json 40 | 41 | # Android Studio will place build artifacts here 42 | /android/app/debug 43 | /android/app/profile 44 | /android/app/release 45 | -------------------------------------------------------------------------------- /example/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled. 5 | 6 | version: 7 | revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 8 | channel: stable 9 | 10 | project_type: app 11 | 12 | # Tracks metadata for the flutter migrate command 13 | migration: 14 | platforms: 15 | - platform: root 16 | create_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 17 | base_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 18 | - platform: android 19 | create_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 20 | base_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 21 | - platform: ios 22 | create_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 23 | base_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 24 | - platform: linux 25 | create_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 26 | base_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 27 | - platform: macos 28 | create_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 29 | base_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 30 | - platform: web 31 | create_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 32 | base_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 33 | - platform: windows 34 | create_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 35 | base_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 36 | 37 | # User provided section 38 | 39 | # List of Local paths (relative to this file) that should be 40 | # ignored by the migrate tool. 41 | # 42 | # Files that are not part of the templates will be ignored by default. 43 | unmanaged_files: 44 | - 'lib/main.dart' 45 | - 'ios/Runner.xcodeproj/project.pbxproj' 46 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # example 2 | 3 | A new Flutter project. 4 | 5 | ## Getting Started 6 | 7 | This project is a starting point for a Flutter application. 8 | 9 | A few resources to get you started if this is your first Flutter project: 10 | 11 | - [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) 12 | - [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) 13 | 14 | For help getting started with Flutter development, view the 15 | [online documentation](https://docs.flutter.dev/), which offers tutorials, 16 | samples, guidance on mobile development, and a full API reference. 17 | -------------------------------------------------------------------------------- /example/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the analyzer, which statically analyzes Dart code to 2 | # check for errors, warnings, and lints. 3 | # 4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled 5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be 6 | # invoked from the command line by running `flutter analyze`. 7 | 8 | # The following line activates a set of recommended lints for Flutter apps, 9 | # packages, and plugins designed to encourage good coding practices. 10 | include: package:flutter_lints/flutter.yaml 11 | 12 | linter: 13 | # The lint rules applied to this project can be customized in the 14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml` 15 | # included above or to enable additional rules. A list of all available lints 16 | # and their documentation is published at 17 | # https://dart-lang.github.io/linter/lints/index.html. 18 | # 19 | # Instead of disabling a lint rule for the entire project in the 20 | # section below, it can also be suppressed for a single line of code 21 | # or a specific dart file by using the `// ignore: name_of_lint` and 22 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file 23 | # producing the lint. 24 | rules: 25 | # avoid_print: false # Uncomment to disable the `avoid_print` rule 26 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule 27 | 28 | # Additional information about this file can be found at 29 | # https://dart.dev/guides/language/analysis-options 30 | -------------------------------------------------------------------------------- /example/android/.gitignore: -------------------------------------------------------------------------------- 1 | gradle-wrapper.jar 2 | /.gradle 3 | /captures/ 4 | /gradlew 5 | /gradlew.bat 6 | /local.properties 7 | GeneratedPluginRegistrant.java 8 | 9 | # Remember to never publicly share your keystore. 10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app 11 | key.properties 12 | **/*.keystore 13 | **/*.jks 14 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | def localProperties = new Properties() 2 | def localPropertiesFile = rootProject.file('local.properties') 3 | if (localPropertiesFile.exists()) { 4 | localPropertiesFile.withReader('UTF-8') { reader -> 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 15 | if (flutterVersionCode == null) { 16 | flutterVersionCode = '1' 17 | } 18 | 19 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 20 | if (flutterVersionName == null) { 21 | flutterVersionName = '1.0' 22 | } 23 | 24 | apply plugin: 'com.android.application' 25 | apply plugin: 'kotlin-android' 26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 27 | 28 | android { 29 | compileSdkVersion flutter.compileSdkVersion 30 | ndkVersion flutter.ndkVersion 31 | 32 | compileOptions { 33 | sourceCompatibility JavaVersion.VERSION_1_8 34 | targetCompatibility JavaVersion.VERSION_1_8 35 | } 36 | 37 | kotlinOptions { 38 | jvmTarget = '1.8' 39 | } 40 | 41 | sourceSets { 42 | main.java.srcDirs += 'src/main/kotlin' 43 | } 44 | 45 | defaultConfig { 46 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 47 | applicationId "com.example.example" 48 | // You can update the following values to match your application needs. 49 | // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. 50 | minSdkVersion flutter.minSdkVersion 51 | targetSdkVersion flutter.targetSdkVersion 52 | versionCode flutterVersionCode.toInteger() 53 | versionName flutterVersionName 54 | } 55 | 56 | buildTypes { 57 | release { 58 | // TODO: Add your own signing config for the release build. 59 | // Signing with the debug keys for now, so `flutter run --release` works. 60 | signingConfig signingConfigs.debug 61 | } 62 | } 63 | } 64 | 65 | flutter { 66 | source '../..' 67 | } 68 | 69 | dependencies { 70 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 71 | } 72 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 15 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 30 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /example/android/app/src/main/kotlin/com/example/example/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.example 2 | 3 | import io.flutter.embedding.android.FlutterActivity 4 | 5 | class MainActivity: FlutterActivity() { 6 | } 7 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable-v21/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values-night/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /example/android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.6.10' 3 | repositories { 4 | google() 5 | mavenCentral() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:7.1.2' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | mavenCentral() 18 | } 19 | } 20 | 21 | rootProject.buildDir = '../build' 22 | subprojects { 23 | project.buildDir = "${rootProject.buildDir}/${project.name}" 24 | } 25 | subprojects { 26 | project.evaluationDependsOn(':app') 27 | } 28 | 29 | task clean(type: Delete) { 30 | delete rootProject.buildDir 31 | } 32 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | android.useAndroidX=true 3 | android.enableJetifier=true 4 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip 6 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | 3 | def localPropertiesFile = new File(rootProject.projectDir, "local.properties") 4 | def properties = new Properties() 5 | 6 | assert localPropertiesFile.exists() 7 | localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } 8 | 9 | def flutterSdkPath = properties.getProperty("flutter.sdk") 10 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties" 11 | apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" 12 | -------------------------------------------------------------------------------- /example/images/Screenshot1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/images/Screenshot1.jpg -------------------------------------------------------------------------------- /example/images/Screenshot2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/images/Screenshot2.jpg -------------------------------------------------------------------------------- /example/images/Screenshot3.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/images/Screenshot3.jpeg -------------------------------------------------------------------------------- /example/images/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/images/demo.gif -------------------------------------------------------------------------------- /example/images/demo2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/images/demo2.gif -------------------------------------------------------------------------------- /example/ios/.gitignore: -------------------------------------------------------------------------------- 1 | **/dgph 2 | *.mode1v3 3 | *.mode2v3 4 | *.moved-aside 5 | *.pbxuser 6 | *.perspectivev3 7 | **/*sync/ 8 | .sconsign.dblite 9 | .tags* 10 | **/.vagrant/ 11 | **/DerivedData/ 12 | Icon? 13 | **/Pods/ 14 | **/.symlinks/ 15 | profile 16 | xcuserdata 17 | **/.generated/ 18 | Flutter/App.framework 19 | Flutter/Flutter.framework 20 | Flutter/Flutter.podspec 21 | Flutter/Generated.xcconfig 22 | Flutter/ephemeral/ 23 | Flutter/app.flx 24 | Flutter/app.zip 25 | Flutter/flutter_assets/ 26 | Flutter/flutter_export_environment.sh 27 | ServiceDefinitions.json 28 | Runner/GeneratedPluginRegistrant.* 29 | 30 | # Exceptions to above rules. 31 | !default.mode1v3 32 | !default.mode2v3 33 | !default.pbxuser 34 | !default.perspectivev3 35 | -------------------------------------------------------------------------------- /example/ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | App 9 | CFBundleIdentifier 10 | io.flutter.flutter.app 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | App 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | MinimumOSVersion 24 | 11.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 69 | 71 | 77 | 78 | 79 | 80 | 82 | 83 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import Flutter 3 | 4 | @UIApplicationMain 5 | @objc class AppDelegate: FlutterAppDelegate { 6 | override func application( 7 | _ application: UIApplication, 8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? 9 | ) -> Bool { 10 | GeneratedPluginRegistrant.register(with: self) 11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "Icon-App-20x20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "Icon-App-20x20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "Icon-App-29x29@1x.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "Icon-App-29x29@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "29x29", 29 | "idiom" : "iphone", 30 | "filename" : "Icon-App-29x29@3x.png", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "Icon-App-40x40@2x.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "40x40", 41 | "idiom" : "iphone", 42 | "filename" : "Icon-App-40x40@3x.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "Icon-App-60x60@2x.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "60x60", 53 | "idiom" : "iphone", 54 | "filename" : "Icon-App-60x60@3x.png", 55 | "scale" : "3x" 56 | }, 57 | { 58 | "size" : "20x20", 59 | "idiom" : "ipad", 60 | "filename" : "Icon-App-20x20@1x.png", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "size" : "20x20", 65 | "idiom" : "ipad", 66 | "filename" : "Icon-App-20x20@2x.png", 67 | "scale" : "2x" 68 | }, 69 | { 70 | "size" : "29x29", 71 | "idiom" : "ipad", 72 | "filename" : "Icon-App-29x29@1x.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "29x29", 77 | "idiom" : "ipad", 78 | "filename" : "Icon-App-29x29@2x.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "40x40", 83 | "idiom" : "ipad", 84 | "filename" : "Icon-App-40x40@1x.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "40x40", 89 | "idiom" : "ipad", 90 | "filename" : "Icon-App-40x40@2x.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "76x76", 95 | "idiom" : "ipad", 96 | "filename" : "Icon-App-76x76@1x.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "76x76", 101 | "idiom" : "ipad", 102 | "filename" : "Icon-App-76x76@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "size" : "83.5x83.5", 107 | "idiom" : "ipad", 108 | "filename" : "Icon-App-83.5x83.5@2x.png", 109 | "scale" : "2x" 110 | }, 111 | { 112 | "size" : "1024x1024", 113 | "idiom" : "ios-marketing", 114 | "filename" : "Icon-App-1024x1024@1x.png", 115 | "scale" : "1x" 116 | } 117 | ], 118 | "info" : { 119 | "version" : 1, 120 | "author" : "xcode" 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "LaunchImage.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "LaunchImage@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "LaunchImage@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md: -------------------------------------------------------------------------------- 1 | # Launch Screen Assets 2 | 3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory. 4 | 5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDisplayName 8 | Example 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | example 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | $(FLUTTER_BUILD_NUMBER) 25 | LSRequiresIPhoneOS 26 | 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | UIViewControllerBasedStatusBarAppearance 45 | 46 | CADisableMinimumFrameDurationOnPhone 47 | 48 | UIApplicationSupportsIndirectInputEvents 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /example/ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /example/lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter/services.dart'; 5 | import 'package:http/http.dart' as http; 6 | import 'package:k_chart/chart_translations.dart'; 7 | import 'package:k_chart/flutter_k_chart.dart'; 8 | 9 | void main() => runApp(MyApp()); 10 | 11 | class MyApp extends StatelessWidget { 12 | @override 13 | Widget build(BuildContext context) { 14 | return MaterialApp( 15 | title: 'Flutter Demo', 16 | theme: ThemeData( 17 | primarySwatch: Colors.green, 18 | ), 19 | home: MyHomePage(title: 'Flutter Demo Home Page'), 20 | ); 21 | } 22 | } 23 | 24 | class MyHomePage extends StatefulWidget { 25 | MyHomePage({Key? key, this.title}) : super(key: key); 26 | 27 | final String? title; 28 | 29 | @override 30 | _MyHomePageState createState() => _MyHomePageState(); 31 | } 32 | 33 | class _MyHomePageState extends State { 34 | List? datas; 35 | bool showLoading = true; 36 | MainState _mainState = MainState.MA; 37 | bool _volHidden = false; 38 | SecondaryState _secondaryState = SecondaryState.MACD; 39 | bool isLine = true; 40 | bool isChinese = true; 41 | bool _hideGrid = false; 42 | bool _showNowPrice = true; 43 | List? _bids, _asks; 44 | bool isChangeUI = false; 45 | bool _isTrendLine = false; 46 | bool _priceLeft = true; 47 | VerticalTextAlignment _verticalTextAlignment = VerticalTextAlignment.left; 48 | 49 | ChartStyle chartStyle = ChartStyle(); 50 | ChartColors chartColors = ChartColors(); 51 | 52 | @override 53 | void initState() { 54 | super.initState(); 55 | getData('1day'); 56 | rootBundle.loadString('assets/depth.json').then((result) { 57 | final parseJson = json.decode(result); 58 | final tick = parseJson['tick'] as Map; 59 | final List bids = (tick['bids'] as List) 60 | .map( 61 | (item) => DepthEntity(item[0] as double, item[1] as double)) 62 | .toList(); 63 | final List asks = (tick['asks'] as List) 64 | .map( 65 | (item) => DepthEntity(item[0] as double, item[1] as double)) 66 | .toList(); 67 | initDepth(bids, asks); 68 | }); 69 | } 70 | 71 | void initDepth(List? bids, List? asks) { 72 | if (bids == null || asks == null || bids.isEmpty || asks.isEmpty) return; 73 | _bids = []; 74 | _asks = []; 75 | double amount = 0.0; 76 | bids.sort((left, right) => left.price.compareTo(right.price)); 77 | //累加买入委托量 78 | bids.reversed.forEach((item) { 79 | amount += item.vol; 80 | item.vol = amount; 81 | _bids!.insert(0, item); 82 | }); 83 | 84 | amount = 0.0; 85 | asks.sort((left, right) => left.price.compareTo(right.price)); 86 | //累加卖出委托量 87 | asks.forEach((item) { 88 | amount += item.vol; 89 | item.vol = amount; 90 | _asks!.add(item); 91 | }); 92 | setState(() {}); 93 | } 94 | 95 | @override 96 | Widget build(BuildContext context) { 97 | return ListView( 98 | shrinkWrap: true, 99 | children: [ 100 | Stack(children: [ 101 | Container( 102 | height: 450, 103 | width: double.infinity, 104 | child: KChartWidget( 105 | datas, 106 | chartStyle, 107 | chartColors, 108 | isLine: isLine, 109 | onSecondaryTap: () { 110 | print('Secondary Tap'); 111 | }, 112 | isTrendLine: _isTrendLine, 113 | mainState: _mainState, 114 | volHidden: _volHidden, 115 | secondaryState: _secondaryState, 116 | fixedLength: 2, 117 | timeFormat: TimeFormat.YEAR_MONTH_DAY, 118 | translations: kChartTranslations, 119 | showNowPrice: _showNowPrice, 120 | //`isChinese` is Deprecated, Use `translations` instead. 121 | isChinese: isChinese, 122 | hideGrid: _hideGrid, 123 | isTapShowInfoDialog: false, 124 | verticalTextAlignment: _verticalTextAlignment, 125 | maDayList: [1, 100, 1000], 126 | ), 127 | ), 128 | if (showLoading) 129 | Container( 130 | width: double.infinity, 131 | height: 450, 132 | alignment: Alignment.center, 133 | child: const CircularProgressIndicator()), 134 | ]), 135 | buildButtons(), 136 | if (_bids != null && _asks != null) 137 | Container( 138 | height: 230, 139 | width: double.infinity, 140 | child: DepthChart(_bids!, _asks!, chartColors), 141 | ) 142 | ], 143 | ); 144 | } 145 | 146 | Widget buildButtons() { 147 | return Wrap( 148 | alignment: WrapAlignment.spaceEvenly, 149 | children: [ 150 | button("Time Mode", onPressed: () => isLine = true), 151 | button("K Line Mode", onPressed: () => isLine = false), 152 | button("TrendLine", onPressed: () => _isTrendLine = !_isTrendLine), 153 | button("Line:MA", onPressed: () => _mainState = MainState.MA), 154 | button("Line:BOLL", onPressed: () => _mainState = MainState.BOLL), 155 | button("Hide Line", onPressed: () => _mainState = MainState.NONE), 156 | button("Secondary Chart:MACD", 157 | onPressed: () => _secondaryState = SecondaryState.MACD), 158 | button("Secondary Chart:KDJ", 159 | onPressed: () => _secondaryState = SecondaryState.KDJ), 160 | button("Secondary Chart:RSI", 161 | onPressed: () => _secondaryState = SecondaryState.RSI), 162 | button("Secondary Chart:WR", 163 | onPressed: () => _secondaryState = SecondaryState.WR), 164 | button("Secondary Chart:CCI", 165 | onPressed: () => _secondaryState = SecondaryState.CCI), 166 | button("Secondary Chart:Hide", 167 | onPressed: () => _secondaryState = SecondaryState.NONE), 168 | button(_volHidden ? "Show Vol" : "Hide Vol", 169 | onPressed: () => _volHidden = !_volHidden), 170 | button("Change Language", onPressed: () => isChinese = !isChinese), 171 | button(_hideGrid ? "Show Grid" : "Hide Grid", 172 | onPressed: () => _hideGrid = !_hideGrid), 173 | button(_showNowPrice ? "Hide Now Price" : "Show Now Price", 174 | onPressed: () => _showNowPrice = !_showNowPrice), 175 | button("Customize UI", onPressed: () { 176 | setState(() { 177 | this.isChangeUI = !this.isChangeUI; 178 | if (this.isChangeUI) { 179 | chartColors.selectBorderColor = Colors.red; 180 | chartColors.selectFillColor = Colors.red; 181 | chartColors.lineFillColor = Colors.red; 182 | chartColors.kLineColor = Colors.yellow; 183 | } else { 184 | chartColors.selectBorderColor = Color(0xff6C7A86); 185 | chartColors.selectFillColor = Color(0xff0D1722); 186 | chartColors.lineFillColor = Color(0x554C86CD); 187 | chartColors.kLineColor = Color(0xff4C86CD); 188 | } 189 | }); 190 | }), 191 | button("Change PriceTextPaint", 192 | onPressed: () => setState(() { 193 | _priceLeft = !_priceLeft; 194 | if (_priceLeft) { 195 | _verticalTextAlignment = VerticalTextAlignment.left; 196 | } else { 197 | _verticalTextAlignment = VerticalTextAlignment.right; 198 | } 199 | })), 200 | ], 201 | ); 202 | } 203 | 204 | Widget button(String text, {VoidCallback? onPressed}) { 205 | return TextButton( 206 | onPressed: () { 207 | if (onPressed != null) { 208 | onPressed(); 209 | setState(() {}); 210 | } 211 | }, 212 | child: Text(text), 213 | style: TextButton.styleFrom( 214 | primary: Colors.white, 215 | minimumSize: const Size(88, 44), 216 | padding: const EdgeInsets.symmetric(horizontal: 16.0), 217 | shape: const RoundedRectangleBorder( 218 | borderRadius: BorderRadius.all(Radius.circular(2.0)), 219 | ), 220 | backgroundColor: Colors.blue, 221 | ), 222 | ); 223 | } 224 | 225 | void getData(String period) { 226 | /* 227 | * 可以翻墙使用方法1加载数据,不可以翻墙使用方法2加载数据,默认使用方法1加载最新数据 228 | */ 229 | final Future future = getChatDataFromInternet(period); 230 | //final Future future = getChatDataFromJson(); 231 | future.then((String result) { 232 | solveChatData(result); 233 | }).catchError((_) { 234 | showLoading = false; 235 | setState(() {}); 236 | print('### datas error $_'); 237 | }); 238 | } 239 | 240 | //获取火币数据,需要翻墙 241 | Future getChatDataFromInternet(String? period) async { 242 | var url = 243 | 'https://api.huobi.br.com/market/history/kline?period=${period ?? '1day'}&size=300&symbol=btcusdt'; 244 | late String result; 245 | final response = await http.get(Uri.parse(url)); 246 | if (response.statusCode == 200) { 247 | result = response.body; 248 | } else { 249 | print('Failed getting IP address'); 250 | } 251 | return result; 252 | } 253 | 254 | // 如果你不能翻墙,可以使用这个方法加载数据 255 | Future getChatDataFromJson() async { 256 | return rootBundle.loadString('assets/chatData.json'); 257 | } 258 | 259 | void solveChatData(String result) { 260 | final Map parseJson = json.decode(result) as Map; 261 | final list = parseJson['data'] as List; 262 | datas = list 263 | .map((item) => KLineEntity.fromJson(item as Map)) 264 | .toList() 265 | .reversed 266 | .toList() 267 | .cast(); 268 | DataUtil.calculate(datas!); 269 | showLoading = false; 270 | setState(() {}); 271 | } 272 | } 273 | -------------------------------------------------------------------------------- /example/linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /example/linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project-level configuration. 2 | cmake_minimum_required(VERSION 3.10) 3 | project(runner LANGUAGES CXX) 4 | 5 | # The name of the executable created for the application. Change this to change 6 | # the on-disk name of your application. 7 | set(BINARY_NAME "example") 8 | # The unique GTK application identifier for this application. See: 9 | # https://wiki.gnome.org/HowDoI/ChooseApplicationID 10 | set(APPLICATION_ID "com.example.example") 11 | 12 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 13 | # versions of CMake. 14 | cmake_policy(SET CMP0063 NEW) 15 | 16 | # Load bundled libraries from the lib/ directory relative to the binary. 17 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") 18 | 19 | # Root filesystem for cross-building. 20 | if(FLUTTER_TARGET_PLATFORM_SYSROOT) 21 | set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) 22 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) 23 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 24 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 25 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 26 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 27 | endif() 28 | 29 | # Define build configuration options. 30 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 31 | set(CMAKE_BUILD_TYPE "Debug" CACHE 32 | STRING "Flutter build mode" FORCE) 33 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 34 | "Debug" "Profile" "Release") 35 | endif() 36 | 37 | # Compilation settings that should be applied to most targets. 38 | # 39 | # Be cautious about adding new options here, as plugins use this function by 40 | # default. In most cases, you should add new options to specific targets instead 41 | # of modifying this function. 42 | function(APPLY_STANDARD_SETTINGS TARGET) 43 | target_compile_features(${TARGET} PUBLIC cxx_std_14) 44 | target_compile_options(${TARGET} PRIVATE -Wall -Werror) 45 | target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") 46 | target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") 47 | endfunction() 48 | 49 | # Flutter library and tool build rules. 50 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 51 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 52 | 53 | # System-level dependencies. 54 | find_package(PkgConfig REQUIRED) 55 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 56 | 57 | add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") 58 | 59 | # Define the application target. To change its name, change BINARY_NAME above, 60 | # not the value here, or `flutter run` will no longer work. 61 | # 62 | # Any new source files that you add to the application should be added here. 63 | add_executable(${BINARY_NAME} 64 | "main.cc" 65 | "my_application.cc" 66 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 67 | ) 68 | 69 | # Apply the standard set of build settings. This can be removed for applications 70 | # that need different build settings. 71 | apply_standard_settings(${BINARY_NAME}) 72 | 73 | # Add dependency libraries. Add any application-specific dependencies here. 74 | target_link_libraries(${BINARY_NAME} PRIVATE flutter) 75 | target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) 76 | 77 | # Run the Flutter tool portions of the build. This must not be removed. 78 | add_dependencies(${BINARY_NAME} flutter_assemble) 79 | 80 | # Only the install-generated bundle's copy of the executable will launch 81 | # correctly, since the resources must in the right relative locations. To avoid 82 | # people trying to run the unbundled copy, put it in a subdirectory instead of 83 | # the default top-level location. 84 | set_target_properties(${BINARY_NAME} 85 | PROPERTIES 86 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" 87 | ) 88 | 89 | # Generated plugin build rules, which manage building the plugins and adding 90 | # them to the application. 91 | include(flutter/generated_plugins.cmake) 92 | 93 | 94 | # === Installation === 95 | # By default, "installing" just makes a relocatable bundle in the build 96 | # directory. 97 | set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") 98 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 99 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 100 | endif() 101 | 102 | # Start with a clean build bundle directory every time. 103 | install(CODE " 104 | file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") 105 | " COMPONENT Runtime) 106 | 107 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 108 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") 109 | 110 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 111 | COMPONENT Runtime) 112 | 113 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 114 | COMPONENT Runtime) 115 | 116 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 117 | COMPONENT Runtime) 118 | 119 | foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) 120 | install(FILES "${bundled_library}" 121 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 122 | COMPONENT Runtime) 123 | endforeach(bundled_library) 124 | 125 | # Fully re-copy the assets directory on each build to avoid having stale files 126 | # from a previous install. 127 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 128 | install(CODE " 129 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 130 | " COMPONENT Runtime) 131 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 132 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 133 | 134 | # Install the AOT library on non-Debug builds only. 135 | if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") 136 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 137 | COMPONENT Runtime) 138 | endif() 139 | -------------------------------------------------------------------------------- /example/linux/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.10) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | 12 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...), 13 | # which isn't available in 3.10. 14 | function(list_prepend LIST_NAME PREFIX) 15 | set(NEW_LIST "") 16 | foreach(element ${${LIST_NAME}}) 17 | list(APPEND NEW_LIST "${PREFIX}${element}") 18 | endforeach(element) 19 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) 20 | endfunction() 21 | 22 | # === Flutter Library === 23 | # System-level dependencies. 24 | find_package(PkgConfig REQUIRED) 25 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 26 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) 27 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) 28 | 29 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") 30 | 31 | # Published to parent scope for install step. 32 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 33 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 34 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 35 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) 36 | 37 | list(APPEND FLUTTER_LIBRARY_HEADERS 38 | "fl_basic_message_channel.h" 39 | "fl_binary_codec.h" 40 | "fl_binary_messenger.h" 41 | "fl_dart_project.h" 42 | "fl_engine.h" 43 | "fl_json_message_codec.h" 44 | "fl_json_method_codec.h" 45 | "fl_message_codec.h" 46 | "fl_method_call.h" 47 | "fl_method_channel.h" 48 | "fl_method_codec.h" 49 | "fl_method_response.h" 50 | "fl_plugin_registrar.h" 51 | "fl_plugin_registry.h" 52 | "fl_standard_message_codec.h" 53 | "fl_standard_method_codec.h" 54 | "fl_string_codec.h" 55 | "fl_value.h" 56 | "fl_view.h" 57 | "flutter_linux.h" 58 | ) 59 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") 60 | add_library(flutter INTERFACE) 61 | target_include_directories(flutter INTERFACE 62 | "${EPHEMERAL_DIR}" 63 | ) 64 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") 65 | target_link_libraries(flutter INTERFACE 66 | PkgConfig::GTK 67 | PkgConfig::GLIB 68 | PkgConfig::GIO 69 | ) 70 | add_dependencies(flutter flutter_assemble) 71 | 72 | # === Flutter tool backend === 73 | # _phony_ is a non-existent file to force this command to run every time, 74 | # since currently there's no way to get a full input/output list from the 75 | # flutter tool. 76 | add_custom_command( 77 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 78 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_ 79 | COMMAND ${CMAKE_COMMAND} -E env 80 | ${FLUTTER_TOOL_ENVIRONMENT} 81 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" 82 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} 83 | VERBATIM 84 | ) 85 | add_custom_target(flutter_assemble DEPENDS 86 | "${FLUTTER_LIBRARY}" 87 | ${FLUTTER_LIBRARY_HEADERS} 88 | ) 89 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void fl_register_plugins(FlPluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void fl_register_plugins(FlPluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /example/linux/main.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | int main(int argc, char** argv) { 4 | g_autoptr(MyApplication) app = my_application_new(); 5 | return g_application_run(G_APPLICATION(app), argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /example/linux/my_application.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | #include 4 | #ifdef GDK_WINDOWING_X11 5 | #include 6 | #endif 7 | 8 | #include "flutter/generated_plugin_registrant.h" 9 | 10 | struct _MyApplication { 11 | GtkApplication parent_instance; 12 | char** dart_entrypoint_arguments; 13 | }; 14 | 15 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) 16 | 17 | // Implements GApplication::activate. 18 | static void my_application_activate(GApplication* application) { 19 | MyApplication* self = MY_APPLICATION(application); 20 | GtkWindow* window = 21 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); 22 | 23 | // Use a header bar when running in GNOME as this is the common style used 24 | // by applications and is the setup most users will be using (e.g. Ubuntu 25 | // desktop). 26 | // If running on X and not using GNOME then just use a traditional title bar 27 | // in case the window manager does more exotic layout, e.g. tiling. 28 | // If running on Wayland assume the header bar will work (may need changing 29 | // if future cases occur). 30 | gboolean use_header_bar = TRUE; 31 | #ifdef GDK_WINDOWING_X11 32 | GdkScreen* screen = gtk_window_get_screen(window); 33 | if (GDK_IS_X11_SCREEN(screen)) { 34 | const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); 35 | if (g_strcmp0(wm_name, "GNOME Shell") != 0) { 36 | use_header_bar = FALSE; 37 | } 38 | } 39 | #endif 40 | if (use_header_bar) { 41 | GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); 42 | gtk_widget_show(GTK_WIDGET(header_bar)); 43 | gtk_header_bar_set_title(header_bar, "example"); 44 | gtk_header_bar_set_show_close_button(header_bar, TRUE); 45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); 46 | } else { 47 | gtk_window_set_title(window, "example"); 48 | } 49 | 50 | gtk_window_set_default_size(window, 1280, 720); 51 | gtk_widget_show(GTK_WIDGET(window)); 52 | 53 | g_autoptr(FlDartProject) project = fl_dart_project_new(); 54 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments); 55 | 56 | FlView* view = fl_view_new(project); 57 | gtk_widget_show(GTK_WIDGET(view)); 58 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); 59 | 60 | fl_register_plugins(FL_PLUGIN_REGISTRY(view)); 61 | 62 | gtk_widget_grab_focus(GTK_WIDGET(view)); 63 | } 64 | 65 | // Implements GApplication::local_command_line. 66 | static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) { 67 | MyApplication* self = MY_APPLICATION(application); 68 | // Strip out the first argument as it is the binary name. 69 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); 70 | 71 | g_autoptr(GError) error = nullptr; 72 | if (!g_application_register(application, nullptr, &error)) { 73 | g_warning("Failed to register: %s", error->message); 74 | *exit_status = 1; 75 | return TRUE; 76 | } 77 | 78 | g_application_activate(application); 79 | *exit_status = 0; 80 | 81 | return TRUE; 82 | } 83 | 84 | // Implements GObject::dispose. 85 | static void my_application_dispose(GObject* object) { 86 | MyApplication* self = MY_APPLICATION(object); 87 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); 88 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object); 89 | } 90 | 91 | static void my_application_class_init(MyApplicationClass* klass) { 92 | G_APPLICATION_CLASS(klass)->activate = my_application_activate; 93 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line; 94 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose; 95 | } 96 | 97 | static void my_application_init(MyApplication* self) {} 98 | 99 | MyApplication* my_application_new() { 100 | return MY_APPLICATION(g_object_new(my_application_get_type(), 101 | "application-id", APPLICATION_ID, 102 | "flags", G_APPLICATION_NON_UNIQUE, 103 | nullptr)); 104 | } 105 | -------------------------------------------------------------------------------- /example/linux/my_application.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_MY_APPLICATION_H_ 2 | #define FLUTTER_MY_APPLICATION_H_ 3 | 4 | #include 5 | 6 | G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, 7 | GtkApplication) 8 | 9 | /** 10 | * my_application_new: 11 | * 12 | * Creates a new Flutter-based application. 13 | * 14 | * Returns: a new #MyApplication. 15 | */ 16 | MyApplication* my_application_new(); 17 | 18 | #endif // FLUTTER_MY_APPLICATION_H_ 19 | -------------------------------------------------------------------------------- /example/macos/.gitignore: -------------------------------------------------------------------------------- 1 | # Flutter-related 2 | **/Flutter/ephemeral/ 3 | **/Pods/ 4 | 5 | # Xcode-related 6 | **/dgph 7 | **/xcuserdata/ 8 | -------------------------------------------------------------------------------- /example/macos/Flutter/Flutter-Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "ephemeral/Flutter-Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/macos/Flutter/Flutter-Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "ephemeral/Flutter-Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/macos/Flutter/GeneratedPluginRegistrant.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | import FlutterMacOS 6 | import Foundation 7 | 8 | 9 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { 10 | } 11 | -------------------------------------------------------------------------------- /example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 69 | 71 | 77 | 78 | 79 | 80 | 82 | 83 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /example/macos/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/macos/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | @NSApplicationMain 5 | class AppDelegate: FlutterAppDelegate { 6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { 7 | return true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "16x16", 5 | "idiom" : "mac", 6 | "filename" : "app_icon_16.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "16x16", 11 | "idiom" : "mac", 12 | "filename" : "app_icon_32.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "32x32", 17 | "idiom" : "mac", 18 | "filename" : "app_icon_32.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "32x32", 23 | "idiom" : "mac", 24 | "filename" : "app_icon_64.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "128x128", 29 | "idiom" : "mac", 30 | "filename" : "app_icon_128.png", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "size" : "128x128", 35 | "idiom" : "mac", 36 | "filename" : "app_icon_256.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "256x256", 41 | "idiom" : "mac", 42 | "filename" : "app_icon_256.png", 43 | "scale" : "1x" 44 | }, 45 | { 46 | "size" : "256x256", 47 | "idiom" : "mac", 48 | "filename" : "app_icon_512.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "512x512", 53 | "idiom" : "mac", 54 | "filename" : "app_icon_512.png", 55 | "scale" : "1x" 56 | }, 57 | { 58 | "size" : "512x512", 59 | "idiom" : "mac", 60 | "filename" : "app_icon_1024.png", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png -------------------------------------------------------------------------------- /example/macos/Runner/Configs/AppInfo.xcconfig: -------------------------------------------------------------------------------- 1 | // Application-level settings for the Runner target. 2 | // 3 | // This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the 4 | // future. If not, the values below would default to using the project name when this becomes a 5 | // 'flutter create' template. 6 | 7 | // The application's name. By default this is also the title of the Flutter window. 8 | PRODUCT_NAME = example 9 | 10 | // The application's bundle identifier 11 | PRODUCT_BUNDLE_IDENTIFIER = com.example.example 12 | 13 | // The copyright displayed in application information 14 | PRODUCT_COPYRIGHT = Copyright © 2022 com.example. All rights reserved. 15 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Debug.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Release.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Warnings.xcconfig: -------------------------------------------------------------------------------- 1 | WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings 2 | GCC_WARN_UNDECLARED_SELECTOR = YES 3 | CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES 4 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE 5 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES 6 | CLANG_WARN_PRAGMA_PACK = YES 7 | CLANG_WARN_STRICT_PROTOTYPES = YES 8 | CLANG_WARN_COMMA = YES 9 | GCC_WARN_STRICT_SELECTOR_MATCH = YES 10 | CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES 11 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES 12 | GCC_WARN_SHADOW = YES 13 | CLANG_WARN_UNREACHABLE_CODE = YES 14 | -------------------------------------------------------------------------------- /example/macos/Runner/DebugProfile.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.cs.allow-jit 8 | 9 | com.apple.security.network.server 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example/macos/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSMinimumSystemVersion 24 | $(MACOSX_DEPLOYMENT_TARGET) 25 | NSHumanReadableCopyright 26 | $(PRODUCT_COPYRIGHT) 27 | NSMainNibFile 28 | MainMenu 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /example/macos/Runner/MainFlutterWindow.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | class MainFlutterWindow: NSWindow { 5 | override func awakeFromNib() { 6 | let flutterViewController = FlutterViewController.init() 7 | let windowFrame = self.frame 8 | self.contentViewController = flutterViewController 9 | self.setFrame(windowFrame, display: true) 10 | 11 | RegisterGeneratedPlugins(registry: flutterViewController) 12 | 13 | super.awakeFromNib() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/macos/Runner/Release.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: example 2 | description: A new Flutter project. 3 | 4 | publish_to: 'none' # Remove this line if you wish to publish to pub.dev 5 | 6 | version: 1.0.0+1 7 | 8 | environment: 9 | sdk: '>=2.18.1 <3.0.0' 10 | 11 | dependencies: 12 | flutter: 13 | sdk: flutter 14 | cupertino_icons: ^1.0.2 15 | http: ^0.13.3 16 | k_chart: 17 | path: ../ 18 | 19 | dev_dependencies: 20 | flutter_test: 21 | sdk: flutter 22 | flutter_lints: ^2.0.0 23 | 24 | flutter: 25 | uses-material-design: true 26 | assets: 27 | - assets/depth.json 28 | - assets/chatData.json 29 | -------------------------------------------------------------------------------- /example/test/widget_test.dart: -------------------------------------------------------------------------------- 1 | // This is a basic Flutter widget test. 2 | // 3 | // To perform an interaction with a widget in your test, use the WidgetTester 4 | // utility in the flutter_test package. For example, you can send tap and scroll 5 | // gestures. You can also use WidgetTester to find child widgets in the widget 6 | // tree, read text, and verify that the values of widget properties are correct. 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:flutter_test/flutter_test.dart'; 10 | 11 | import 'package:example/main.dart'; 12 | 13 | void main() { 14 | testWidgets('Counter increments smoke test', (WidgetTester tester) async { 15 | // Build our app and trigger a frame. 16 | await tester.pumpWidget(const MyApp()); 17 | 18 | // Verify that our counter starts at 0. 19 | expect(find.text('0'), findsOneWidget); 20 | expect(find.text('1'), findsNothing); 21 | 22 | // Tap the '+' icon and trigger a frame. 23 | await tester.tap(find.byIcon(Icons.add)); 24 | await tester.pump(); 25 | 26 | // Verify that our counter has incremented. 27 | expect(find.text('0'), findsNothing); 28 | expect(find.text('1'), findsOneWidget); 29 | }); 30 | } 31 | -------------------------------------------------------------------------------- /example/web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/web/favicon.png -------------------------------------------------------------------------------- /example/web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/web/icons/Icon-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/web/icons/Icon-512.png -------------------------------------------------------------------------------- /example/web/icons/Icon-maskable-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/web/icons/Icon-maskable-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-maskable-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/web/icons/Icon-maskable-512.png -------------------------------------------------------------------------------- /example/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | example 33 | 34 | 35 | 39 | 40 | 41 | 42 | 43 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /example/web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "short_name": "example", 4 | "start_url": ".", 5 | "display": "standalone", 6 | "background_color": "#0175C2", 7 | "theme_color": "#0175C2", 8 | "description": "A new Flutter project.", 9 | "orientation": "portrait-primary", 10 | "prefer_related_applications": false, 11 | "icons": [ 12 | { 13 | "src": "icons/Icon-192.png", 14 | "sizes": "192x192", 15 | "type": "image/png" 16 | }, 17 | { 18 | "src": "icons/Icon-512.png", 19 | "sizes": "512x512", 20 | "type": "image/png" 21 | }, 22 | { 23 | "src": "icons/Icon-maskable-192.png", 24 | "sizes": "192x192", 25 | "type": "image/png", 26 | "purpose": "maskable" 27 | }, 28 | { 29 | "src": "icons/Icon-maskable-512.png", 30 | "sizes": "512x512", 31 | "type": "image/png", 32 | "purpose": "maskable" 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /example/windows/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral/ 2 | 3 | # Visual Studio user-specific files. 4 | *.suo 5 | *.user 6 | *.userosscache 7 | *.sln.docstates 8 | 9 | # Visual Studio build-related files. 10 | x64/ 11 | x86/ 12 | 13 | # Visual Studio cache files 14 | # files ending in .cache can be ignored 15 | *.[Cc]ache 16 | # but keep track of directories ending in .cache 17 | !*.[Cc]ache/ 18 | -------------------------------------------------------------------------------- /example/windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project-level configuration. 2 | cmake_minimum_required(VERSION 3.14) 3 | project(example LANGUAGES CXX) 4 | 5 | # The name of the executable created for the application. Change this to change 6 | # the on-disk name of your application. 7 | set(BINARY_NAME "example") 8 | 9 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 10 | # versions of CMake. 11 | cmake_policy(SET CMP0063 NEW) 12 | 13 | # Define build configuration option. 14 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 15 | if(IS_MULTICONFIG) 16 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" 17 | CACHE STRING "" FORCE) 18 | else() 19 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 20 | set(CMAKE_BUILD_TYPE "Debug" CACHE 21 | STRING "Flutter build mode" FORCE) 22 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 23 | "Debug" "Profile" "Release") 24 | endif() 25 | endif() 26 | # Define settings for the Profile build mode. 27 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") 28 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") 29 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") 30 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") 31 | 32 | # Use Unicode for all projects. 33 | add_definitions(-DUNICODE -D_UNICODE) 34 | 35 | # Compilation settings that should be applied to most targets. 36 | # 37 | # Be cautious about adding new options here, as plugins use this function by 38 | # default. In most cases, you should add new options to specific targets instead 39 | # of modifying this function. 40 | function(APPLY_STANDARD_SETTINGS TARGET) 41 | target_compile_features(${TARGET} PUBLIC cxx_std_17) 42 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") 43 | target_compile_options(${TARGET} PRIVATE /EHsc) 44 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") 45 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") 46 | endfunction() 47 | 48 | # Flutter library and tool build rules. 49 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 50 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 51 | 52 | # Application build; see runner/CMakeLists.txt. 53 | add_subdirectory("runner") 54 | 55 | # Generated plugin build rules, which manage building the plugins and adding 56 | # them to the application. 57 | include(flutter/generated_plugins.cmake) 58 | 59 | 60 | # === Installation === 61 | # Support files are copied into place next to the executable, so that it can 62 | # run in place. This is done instead of making a separate bundle (as on Linux) 63 | # so that building and running from within Visual Studio will work. 64 | set(BUILD_BUNDLE_DIR "$") 65 | # Make the "install" step default, as it's required to run. 66 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) 67 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 68 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 69 | endif() 70 | 71 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 72 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") 73 | 74 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 75 | COMPONENT Runtime) 76 | 77 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 78 | COMPONENT Runtime) 79 | 80 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 81 | COMPONENT Runtime) 82 | 83 | if(PLUGIN_BUNDLED_LIBRARIES) 84 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" 85 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 86 | COMPONENT Runtime) 87 | endif() 88 | 89 | # Fully re-copy the assets directory on each build to avoid having stale files 90 | # from a previous install. 91 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 92 | install(CODE " 93 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 94 | " COMPONENT Runtime) 95 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 96 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 97 | 98 | # Install the AOT library on non-Debug builds only. 99 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 100 | CONFIGURATIONS Profile;Release 101 | COMPONENT Runtime) 102 | -------------------------------------------------------------------------------- /example/windows/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.14) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") 12 | 13 | # === Flutter Library === 14 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") 15 | 16 | # Published to parent scope for install step. 17 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 18 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 19 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 20 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) 21 | 22 | list(APPEND FLUTTER_LIBRARY_HEADERS 23 | "flutter_export.h" 24 | "flutter_windows.h" 25 | "flutter_messenger.h" 26 | "flutter_plugin_registrar.h" 27 | "flutter_texture_registrar.h" 28 | ) 29 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") 30 | add_library(flutter INTERFACE) 31 | target_include_directories(flutter INTERFACE 32 | "${EPHEMERAL_DIR}" 33 | ) 34 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") 35 | add_dependencies(flutter flutter_assemble) 36 | 37 | # === Wrapper === 38 | list(APPEND CPP_WRAPPER_SOURCES_CORE 39 | "core_implementations.cc" 40 | "standard_codec.cc" 41 | ) 42 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") 43 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN 44 | "plugin_registrar.cc" 45 | ) 46 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") 47 | list(APPEND CPP_WRAPPER_SOURCES_APP 48 | "flutter_engine.cc" 49 | "flutter_view_controller.cc" 50 | ) 51 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") 52 | 53 | # Wrapper sources needed for a plugin. 54 | add_library(flutter_wrapper_plugin STATIC 55 | ${CPP_WRAPPER_SOURCES_CORE} 56 | ${CPP_WRAPPER_SOURCES_PLUGIN} 57 | ) 58 | apply_standard_settings(flutter_wrapper_plugin) 59 | set_target_properties(flutter_wrapper_plugin PROPERTIES 60 | POSITION_INDEPENDENT_CODE ON) 61 | set_target_properties(flutter_wrapper_plugin PROPERTIES 62 | CXX_VISIBILITY_PRESET hidden) 63 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) 64 | target_include_directories(flutter_wrapper_plugin PUBLIC 65 | "${WRAPPER_ROOT}/include" 66 | ) 67 | add_dependencies(flutter_wrapper_plugin flutter_assemble) 68 | 69 | # Wrapper sources needed for the runner. 70 | add_library(flutter_wrapper_app STATIC 71 | ${CPP_WRAPPER_SOURCES_CORE} 72 | ${CPP_WRAPPER_SOURCES_APP} 73 | ) 74 | apply_standard_settings(flutter_wrapper_app) 75 | target_link_libraries(flutter_wrapper_app PUBLIC flutter) 76 | target_include_directories(flutter_wrapper_app PUBLIC 77 | "${WRAPPER_ROOT}/include" 78 | ) 79 | add_dependencies(flutter_wrapper_app flutter_assemble) 80 | 81 | # === Flutter tool backend === 82 | # _phony_ is a non-existent file to force this command to run every time, 83 | # since currently there's no way to get a full input/output list from the 84 | # flutter tool. 85 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") 86 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) 87 | add_custom_command( 88 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 89 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} 90 | ${CPP_WRAPPER_SOURCES_APP} 91 | ${PHONY_OUTPUT} 92 | COMMAND ${CMAKE_COMMAND} -E env 93 | ${FLUTTER_TOOL_ENVIRONMENT} 94 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" 95 | windows-x64 $ 96 | VERBATIM 97 | ) 98 | add_custom_target(flutter_assemble DEPENDS 99 | "${FLUTTER_LIBRARY}" 100 | ${FLUTTER_LIBRARY_HEADERS} 101 | ${CPP_WRAPPER_SOURCES_CORE} 102 | ${CPP_WRAPPER_SOURCES_PLUGIN} 103 | ${CPP_WRAPPER_SOURCES_APP} 104 | ) 105 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void RegisterPlugins(flutter::PluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void RegisterPlugins(flutter::PluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /example/windows/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | project(runner LANGUAGES CXX) 3 | 4 | # Define the application target. To change its name, change BINARY_NAME in the 5 | # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer 6 | # work. 7 | # 8 | # Any new source files that you add to the application should be added here. 9 | add_executable(${BINARY_NAME} WIN32 10 | "flutter_window.cpp" 11 | "main.cpp" 12 | "utils.cpp" 13 | "win32_window.cpp" 14 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 15 | "Runner.rc" 16 | "runner.exe.manifest" 17 | ) 18 | 19 | # Apply the standard set of build settings. This can be removed for applications 20 | # that need different build settings. 21 | apply_standard_settings(${BINARY_NAME}) 22 | 23 | # Add preprocessor definitions for the build version. 24 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") 25 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") 26 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") 27 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") 28 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") 29 | 30 | # Disable Windows macros that collide with C++ standard library functions. 31 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 32 | 33 | # Add dependency libraries and include directories. Add any application-specific 34 | # dependencies here. 35 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 36 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 37 | 38 | # Run the Flutter tool portions of the build. This must not be removed. 39 | add_dependencies(${BINARY_NAME} flutter_assemble) 40 | -------------------------------------------------------------------------------- /example/windows/runner/Runner.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #pragma code_page(65001) 4 | #include "resource.h" 5 | 6 | #define APSTUDIO_READONLY_SYMBOLS 7 | ///////////////////////////////////////////////////////////////////////////// 8 | // 9 | // Generated from the TEXTINCLUDE 2 resource. 10 | // 11 | #include "winres.h" 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | #undef APSTUDIO_READONLY_SYMBOLS 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // English (United States) resources 18 | 19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Icon 51 | // 52 | 53 | // Icon with lowest ID value placed first to ensure application icon 54 | // remains consistent on all systems. 55 | IDI_APP_ICON ICON "resources\\app_icon.ico" 56 | 57 | 58 | ///////////////////////////////////////////////////////////////////////////// 59 | // 60 | // Version 61 | // 62 | 63 | #if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD) 64 | #define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD 65 | #else 66 | #define VERSION_AS_NUMBER 1,0,0,0 67 | #endif 68 | 69 | #if defined(FLUTTER_VERSION) 70 | #define VERSION_AS_STRING FLUTTER_VERSION 71 | #else 72 | #define VERSION_AS_STRING "1.0.0" 73 | #endif 74 | 75 | VS_VERSION_INFO VERSIONINFO 76 | FILEVERSION VERSION_AS_NUMBER 77 | PRODUCTVERSION VERSION_AS_NUMBER 78 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 79 | #ifdef _DEBUG 80 | FILEFLAGS VS_FF_DEBUG 81 | #else 82 | FILEFLAGS 0x0L 83 | #endif 84 | FILEOS VOS__WINDOWS32 85 | FILETYPE VFT_APP 86 | FILESUBTYPE 0x0L 87 | BEGIN 88 | BLOCK "StringFileInfo" 89 | BEGIN 90 | BLOCK "040904e4" 91 | BEGIN 92 | VALUE "CompanyName", "com.example" "\0" 93 | VALUE "FileDescription", "example" "\0" 94 | VALUE "FileVersion", VERSION_AS_STRING "\0" 95 | VALUE "InternalName", "example" "\0" 96 | VALUE "LegalCopyright", "Copyright (C) 2022 com.example. All rights reserved." "\0" 97 | VALUE "OriginalFilename", "example.exe" "\0" 98 | VALUE "ProductName", "example" "\0" 99 | VALUE "ProductVersion", VERSION_AS_STRING "\0" 100 | END 101 | END 102 | BLOCK "VarFileInfo" 103 | BEGIN 104 | VALUE "Translation", 0x409, 1252 105 | END 106 | END 107 | 108 | #endif // English (United States) resources 109 | ///////////////////////////////////////////////////////////////////////////// 110 | 111 | 112 | 113 | #ifndef APSTUDIO_INVOKED 114 | ///////////////////////////////////////////////////////////////////////////// 115 | // 116 | // Generated from the TEXTINCLUDE 3 resource. 117 | // 118 | 119 | 120 | ///////////////////////////////////////////////////////////////////////////// 121 | #endif // not APSTUDIO_INVOKED 122 | -------------------------------------------------------------------------------- /example/windows/runner/flutter_window.cpp: -------------------------------------------------------------------------------- 1 | #include "flutter_window.h" 2 | 3 | #include 4 | 5 | #include "flutter/generated_plugin_registrant.h" 6 | 7 | FlutterWindow::FlutterWindow(const flutter::DartProject& project) 8 | : project_(project) {} 9 | 10 | FlutterWindow::~FlutterWindow() {} 11 | 12 | bool FlutterWindow::OnCreate() { 13 | if (!Win32Window::OnCreate()) { 14 | return false; 15 | } 16 | 17 | RECT frame = GetClientArea(); 18 | 19 | // The size here must match the window dimensions to avoid unnecessary surface 20 | // creation / destruction in the startup path. 21 | flutter_controller_ = std::make_unique( 22 | frame.right - frame.left, frame.bottom - frame.top, project_); 23 | // Ensure that basic setup of the controller was successful. 24 | if (!flutter_controller_->engine() || !flutter_controller_->view()) { 25 | return false; 26 | } 27 | RegisterPlugins(flutter_controller_->engine()); 28 | SetChildContent(flutter_controller_->view()->GetNativeWindow()); 29 | return true; 30 | } 31 | 32 | void FlutterWindow::OnDestroy() { 33 | if (flutter_controller_) { 34 | flutter_controller_ = nullptr; 35 | } 36 | 37 | Win32Window::OnDestroy(); 38 | } 39 | 40 | LRESULT 41 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message, 42 | WPARAM const wparam, 43 | LPARAM const lparam) noexcept { 44 | // Give Flutter, including plugins, an opportunity to handle window messages. 45 | if (flutter_controller_) { 46 | std::optional result = 47 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, 48 | lparam); 49 | if (result) { 50 | return *result; 51 | } 52 | } 53 | 54 | switch (message) { 55 | case WM_FONTCHANGE: 56 | flutter_controller_->engine()->ReloadSystemFonts(); 57 | break; 58 | } 59 | 60 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam); 61 | } 62 | -------------------------------------------------------------------------------- /example/windows/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_FLUTTER_WINDOW_H_ 2 | #define RUNNER_FLUTTER_WINDOW_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "win32_window.h" 10 | 11 | // A window that does nothing but host a Flutter view. 12 | class FlutterWindow : public Win32Window { 13 | public: 14 | // Creates a new FlutterWindow hosting a Flutter view running |project|. 15 | explicit FlutterWindow(const flutter::DartProject& project); 16 | virtual ~FlutterWindow(); 17 | 18 | protected: 19 | // Win32Window: 20 | bool OnCreate() override; 21 | void OnDestroy() override; 22 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, 23 | LPARAM const lparam) noexcept override; 24 | 25 | private: 26 | // The project to run. 27 | flutter::DartProject project_; 28 | 29 | // The Flutter instance hosted by this window. 30 | std::unique_ptr flutter_controller_; 31 | }; 32 | 33 | #endif // RUNNER_FLUTTER_WINDOW_H_ 34 | -------------------------------------------------------------------------------- /example/windows/runner/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "flutter_window.h" 6 | #include "utils.h" 7 | 8 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, 9 | _In_ wchar_t *command_line, _In_ int show_command) { 10 | // Attach to console when present (e.g., 'flutter run') or create a 11 | // new console when running with a debugger. 12 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { 13 | CreateAndAttachConsole(); 14 | } 15 | 16 | // Initialize COM, so that it is available for use in the library and/or 17 | // plugins. 18 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); 19 | 20 | flutter::DartProject project(L"data"); 21 | 22 | std::vector command_line_arguments = 23 | GetCommandLineArguments(); 24 | 25 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 26 | 27 | FlutterWindow window(project); 28 | Win32Window::Point origin(10, 10); 29 | Win32Window::Size size(1280, 720); 30 | if (!window.CreateAndShow(L"example", origin, size)) { 31 | return EXIT_FAILURE; 32 | } 33 | window.SetQuitOnClose(true); 34 | 35 | ::MSG msg; 36 | while (::GetMessage(&msg, nullptr, 0, 0)) { 37 | ::TranslateMessage(&msg); 38 | ::DispatchMessage(&msg); 39 | } 40 | 41 | ::CoUninitialize(); 42 | return EXIT_SUCCESS; 43 | } 44 | -------------------------------------------------------------------------------- /example/windows/runner/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Runner.rc 4 | // 5 | #define IDI_APP_ICON 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /example/windows/runner/resources/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFlutter/k_chart/ad6d1937c35f4b78fb86f0f288f241ee2af8014b/example/windows/runner/resources/app_icon.ico -------------------------------------------------------------------------------- /example/windows/runner/runner.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PerMonitorV2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /example/windows/runner/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | void CreateAndAttachConsole() { 11 | if (::AllocConsole()) { 12 | FILE *unused; 13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) { 14 | _dup2(_fileno(stdout), 1); 15 | } 16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) { 17 | _dup2(_fileno(stdout), 2); 18 | } 19 | std::ios::sync_with_stdio(); 20 | FlutterDesktopResyncOutputStreams(); 21 | } 22 | } 23 | 24 | std::vector GetCommandLineArguments() { 25 | // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. 26 | int argc; 27 | wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); 28 | if (argv == nullptr) { 29 | return std::vector(); 30 | } 31 | 32 | std::vector command_line_arguments; 33 | 34 | // Skip the first argument as it's the binary name. 35 | for (int i = 1; i < argc; i++) { 36 | command_line_arguments.push_back(Utf8FromUtf16(argv[i])); 37 | } 38 | 39 | ::LocalFree(argv); 40 | 41 | return command_line_arguments; 42 | } 43 | 44 | std::string Utf8FromUtf16(const wchar_t* utf16_string) { 45 | if (utf16_string == nullptr) { 46 | return std::string(); 47 | } 48 | int target_length = ::WideCharToMultiByte( 49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 50 | -1, nullptr, 0, nullptr, nullptr); 51 | std::string utf8_string; 52 | if (target_length == 0 || target_length > utf8_string.max_size()) { 53 | return utf8_string; 54 | } 55 | utf8_string.resize(target_length); 56 | int converted_length = ::WideCharToMultiByte( 57 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 58 | -1, utf8_string.data(), 59 | target_length, nullptr, nullptr); 60 | if (converted_length == 0) { 61 | return std::string(); 62 | } 63 | return utf8_string; 64 | } 65 | -------------------------------------------------------------------------------- /example/windows/runner/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_UTILS_H_ 2 | #define RUNNER_UTILS_H_ 3 | 4 | #include 5 | #include 6 | 7 | // Creates a console for the process, and redirects stdout and stderr to 8 | // it for both the runner and the Flutter library. 9 | void CreateAndAttachConsole(); 10 | 11 | // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string 12 | // encoded in UTF-8. Returns an empty std::string on failure. 13 | std::string Utf8FromUtf16(const wchar_t* utf16_string); 14 | 15 | // Gets the command line arguments passed in as a std::vector, 16 | // encoded in UTF-8. Returns an empty std::vector on failure. 17 | std::vector GetCommandLineArguments(); 18 | 19 | #endif // RUNNER_UTILS_H_ 20 | -------------------------------------------------------------------------------- /example/windows/runner/win32_window.cpp: -------------------------------------------------------------------------------- 1 | #include "win32_window.h" 2 | 3 | #include 4 | 5 | #include "resource.h" 6 | 7 | namespace { 8 | 9 | constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW"; 10 | 11 | // The number of Win32Window objects that currently exist. 12 | static int g_active_window_count = 0; 13 | 14 | using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd); 15 | 16 | // Scale helper to convert logical scaler values to physical using passed in 17 | // scale factor 18 | int Scale(int source, double scale_factor) { 19 | return static_cast(source * scale_factor); 20 | } 21 | 22 | // Dynamically loads the |EnableNonClientDpiScaling| from the User32 module. 23 | // This API is only needed for PerMonitor V1 awareness mode. 24 | void EnableFullDpiSupportIfAvailable(HWND hwnd) { 25 | HMODULE user32_module = LoadLibraryA("User32.dll"); 26 | if (!user32_module) { 27 | return; 28 | } 29 | auto enable_non_client_dpi_scaling = 30 | reinterpret_cast( 31 | GetProcAddress(user32_module, "EnableNonClientDpiScaling")); 32 | if (enable_non_client_dpi_scaling != nullptr) { 33 | enable_non_client_dpi_scaling(hwnd); 34 | FreeLibrary(user32_module); 35 | } 36 | } 37 | 38 | } // namespace 39 | 40 | // Manages the Win32Window's window class registration. 41 | class WindowClassRegistrar { 42 | public: 43 | ~WindowClassRegistrar() = default; 44 | 45 | // Returns the singleton registar instance. 46 | static WindowClassRegistrar* GetInstance() { 47 | if (!instance_) { 48 | instance_ = new WindowClassRegistrar(); 49 | } 50 | return instance_; 51 | } 52 | 53 | // Returns the name of the window class, registering the class if it hasn't 54 | // previously been registered. 55 | const wchar_t* GetWindowClass(); 56 | 57 | // Unregisters the window class. Should only be called if there are no 58 | // instances of the window. 59 | void UnregisterWindowClass(); 60 | 61 | private: 62 | WindowClassRegistrar() = default; 63 | 64 | static WindowClassRegistrar* instance_; 65 | 66 | bool class_registered_ = false; 67 | }; 68 | 69 | WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; 70 | 71 | const wchar_t* WindowClassRegistrar::GetWindowClass() { 72 | if (!class_registered_) { 73 | WNDCLASS window_class{}; 74 | window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); 75 | window_class.lpszClassName = kWindowClassName; 76 | window_class.style = CS_HREDRAW | CS_VREDRAW; 77 | window_class.cbClsExtra = 0; 78 | window_class.cbWndExtra = 0; 79 | window_class.hInstance = GetModuleHandle(nullptr); 80 | window_class.hIcon = 81 | LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); 82 | window_class.hbrBackground = 0; 83 | window_class.lpszMenuName = nullptr; 84 | window_class.lpfnWndProc = Win32Window::WndProc; 85 | RegisterClass(&window_class); 86 | class_registered_ = true; 87 | } 88 | return kWindowClassName; 89 | } 90 | 91 | void WindowClassRegistrar::UnregisterWindowClass() { 92 | UnregisterClass(kWindowClassName, nullptr); 93 | class_registered_ = false; 94 | } 95 | 96 | Win32Window::Win32Window() { 97 | ++g_active_window_count; 98 | } 99 | 100 | Win32Window::~Win32Window() { 101 | --g_active_window_count; 102 | Destroy(); 103 | } 104 | 105 | bool Win32Window::CreateAndShow(const std::wstring& title, 106 | const Point& origin, 107 | const Size& size) { 108 | Destroy(); 109 | 110 | const wchar_t* window_class = 111 | WindowClassRegistrar::GetInstance()->GetWindowClass(); 112 | 113 | const POINT target_point = {static_cast(origin.x), 114 | static_cast(origin.y)}; 115 | HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST); 116 | UINT dpi = FlutterDesktopGetDpiForMonitor(monitor); 117 | double scale_factor = dpi / 96.0; 118 | 119 | HWND window = CreateWindow( 120 | window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, 121 | Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), 122 | Scale(size.width, scale_factor), Scale(size.height, scale_factor), 123 | nullptr, nullptr, GetModuleHandle(nullptr), this); 124 | 125 | if (!window) { 126 | return false; 127 | } 128 | 129 | return OnCreate(); 130 | } 131 | 132 | // static 133 | LRESULT CALLBACK Win32Window::WndProc(HWND const window, 134 | UINT const message, 135 | WPARAM const wparam, 136 | LPARAM const lparam) noexcept { 137 | if (message == WM_NCCREATE) { 138 | auto window_struct = reinterpret_cast(lparam); 139 | SetWindowLongPtr(window, GWLP_USERDATA, 140 | reinterpret_cast(window_struct->lpCreateParams)); 141 | 142 | auto that = static_cast(window_struct->lpCreateParams); 143 | EnableFullDpiSupportIfAvailable(window); 144 | that->window_handle_ = window; 145 | } else if (Win32Window* that = GetThisFromHandle(window)) { 146 | return that->MessageHandler(window, message, wparam, lparam); 147 | } 148 | 149 | return DefWindowProc(window, message, wparam, lparam); 150 | } 151 | 152 | LRESULT 153 | Win32Window::MessageHandler(HWND hwnd, 154 | UINT const message, 155 | WPARAM const wparam, 156 | LPARAM const lparam) noexcept { 157 | switch (message) { 158 | case WM_DESTROY: 159 | window_handle_ = nullptr; 160 | Destroy(); 161 | if (quit_on_close_) { 162 | PostQuitMessage(0); 163 | } 164 | return 0; 165 | 166 | case WM_DPICHANGED: { 167 | auto newRectSize = reinterpret_cast(lparam); 168 | LONG newWidth = newRectSize->right - newRectSize->left; 169 | LONG newHeight = newRectSize->bottom - newRectSize->top; 170 | 171 | SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, 172 | newHeight, SWP_NOZORDER | SWP_NOACTIVATE); 173 | 174 | return 0; 175 | } 176 | case WM_SIZE: { 177 | RECT rect = GetClientArea(); 178 | if (child_content_ != nullptr) { 179 | // Size and position the child window. 180 | MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, 181 | rect.bottom - rect.top, TRUE); 182 | } 183 | return 0; 184 | } 185 | 186 | case WM_ACTIVATE: 187 | if (child_content_ != nullptr) { 188 | SetFocus(child_content_); 189 | } 190 | return 0; 191 | } 192 | 193 | return DefWindowProc(window_handle_, message, wparam, lparam); 194 | } 195 | 196 | void Win32Window::Destroy() { 197 | OnDestroy(); 198 | 199 | if (window_handle_) { 200 | DestroyWindow(window_handle_); 201 | window_handle_ = nullptr; 202 | } 203 | if (g_active_window_count == 0) { 204 | WindowClassRegistrar::GetInstance()->UnregisterWindowClass(); 205 | } 206 | } 207 | 208 | Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { 209 | return reinterpret_cast( 210 | GetWindowLongPtr(window, GWLP_USERDATA)); 211 | } 212 | 213 | void Win32Window::SetChildContent(HWND content) { 214 | child_content_ = content; 215 | SetParent(content, window_handle_); 216 | RECT frame = GetClientArea(); 217 | 218 | MoveWindow(content, frame.left, frame.top, frame.right - frame.left, 219 | frame.bottom - frame.top, true); 220 | 221 | SetFocus(child_content_); 222 | } 223 | 224 | RECT Win32Window::GetClientArea() { 225 | RECT frame; 226 | GetClientRect(window_handle_, &frame); 227 | return frame; 228 | } 229 | 230 | HWND Win32Window::GetHandle() { 231 | return window_handle_; 232 | } 233 | 234 | void Win32Window::SetQuitOnClose(bool quit_on_close) { 235 | quit_on_close_ = quit_on_close; 236 | } 237 | 238 | bool Win32Window::OnCreate() { 239 | // No-op; provided for subclasses. 240 | return true; 241 | } 242 | 243 | void Win32Window::OnDestroy() { 244 | // No-op; provided for subclasses. 245 | } 246 | -------------------------------------------------------------------------------- /example/windows/runner/win32_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_WIN32_WINDOW_H_ 2 | #define RUNNER_WIN32_WINDOW_H_ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | // A class abstraction for a high DPI-aware Win32 Window. Intended to be 11 | // inherited from by classes that wish to specialize with custom 12 | // rendering and input handling 13 | class Win32Window { 14 | public: 15 | struct Point { 16 | unsigned int x; 17 | unsigned int y; 18 | Point(unsigned int x, unsigned int y) : x(x), y(y) {} 19 | }; 20 | 21 | struct Size { 22 | unsigned int width; 23 | unsigned int height; 24 | Size(unsigned int width, unsigned int height) 25 | : width(width), height(height) {} 26 | }; 27 | 28 | Win32Window(); 29 | virtual ~Win32Window(); 30 | 31 | // Creates and shows a win32 window with |title| and position and size using 32 | // |origin| and |size|. New windows are created on the default monitor. Window 33 | // sizes are specified to the OS in physical pixels, hence to ensure a 34 | // consistent size to will treat the width height passed in to this function 35 | // as logical pixels and scale to appropriate for the default monitor. Returns 36 | // true if the window was created successfully. 37 | bool CreateAndShow(const std::wstring& title, 38 | const Point& origin, 39 | const Size& size); 40 | 41 | // Release OS resources associated with window. 42 | void Destroy(); 43 | 44 | // Inserts |content| into the window tree. 45 | void SetChildContent(HWND content); 46 | 47 | // Returns the backing Window handle to enable clients to set icon and other 48 | // window properties. Returns nullptr if the window has been destroyed. 49 | HWND GetHandle(); 50 | 51 | // If true, closing this window will quit the application. 52 | void SetQuitOnClose(bool quit_on_close); 53 | 54 | // Return a RECT representing the bounds of the current client area. 55 | RECT GetClientArea(); 56 | 57 | protected: 58 | // Processes and route salient window messages for mouse handling, 59 | // size change and DPI. Delegates handling of these to member overloads that 60 | // inheriting classes can handle. 61 | virtual LRESULT MessageHandler(HWND window, 62 | UINT const message, 63 | WPARAM const wparam, 64 | LPARAM const lparam) noexcept; 65 | 66 | // Called when CreateAndShow is called, allowing subclass window-related 67 | // setup. Subclasses should return false if setup fails. 68 | virtual bool OnCreate(); 69 | 70 | // Called when Destroy is called. 71 | virtual void OnDestroy(); 72 | 73 | private: 74 | friend class WindowClassRegistrar; 75 | 76 | // OS callback called by message pump. Handles the WM_NCCREATE message which 77 | // is passed when the non-client area is being created and enables automatic 78 | // non-client DPI scaling so that the non-client area automatically 79 | // responsponds to changes in DPI. All other messages are handled by 80 | // MessageHandler. 81 | static LRESULT CALLBACK WndProc(HWND const window, 82 | UINT const message, 83 | WPARAM const wparam, 84 | LPARAM const lparam) noexcept; 85 | 86 | // Retrieves a class instance pointer for |window| 87 | static Win32Window* GetThisFromHandle(HWND const window) noexcept; 88 | 89 | bool quit_on_close_ = false; 90 | 91 | // window handle for top level window. 92 | HWND window_handle_ = nullptr; 93 | 94 | // window handle for hosted content. 95 | HWND child_content_ = nullptr; 96 | }; 97 | 98 | #endif // RUNNER_WIN32_WINDOW_H_ 99 | -------------------------------------------------------------------------------- /lib/chart_style.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart' show Color; 2 | 3 | class ChartColors { 4 | List bgColor = [Color(0xff18191d), Color(0xff18191d)]; 5 | 6 | Color kLineColor = Color(0xff4C86CD); 7 | Color lineFillColor = Color(0x554C86CD); 8 | Color lineFillInsideColor = Color(0x00000000); 9 | Color ma5Color = Color(0xffC9B885); 10 | Color ma10Color = Color(0xff6CB0A6); 11 | Color ma30Color = Color(0xff9979C6); 12 | Color upColor = Color(0xff4DAA90); 13 | Color dnColor = Color(0xffC15466); 14 | Color volColor = Color(0xff4729AE); 15 | 16 | Color macdColor = Color(0xff4729AE); 17 | Color difColor = Color(0xffC9B885); 18 | Color deaColor = Color(0xff6CB0A6); 19 | 20 | Color kColor = Color(0xffC9B885); 21 | Color dColor = Color(0xff6CB0A6); 22 | Color jColor = Color(0xff9979C6); 23 | Color rsiColor = Color(0xffC9B885); 24 | 25 | Color defaultTextColor = Color(0xff60738E); 26 | 27 | Color nowPriceUpColor = Color(0xff4DAA90); 28 | Color nowPriceDnColor = Color(0xffC15466); 29 | Color nowPriceTextColor = Color(0xffffffff); 30 | 31 | //深度颜色 32 | Color depthBuyColor = Color(0xff60A893); 33 | Color depthSellColor = Color(0xffC15866); 34 | 35 | //选中后显示值边框颜色 36 | Color selectBorderColor = Color(0xff6C7A86); 37 | 38 | //选中后显示值背景的填充颜色 39 | Color selectFillColor = Color(0xff0D1722); 40 | 41 | //分割线颜色 42 | Color gridColor = Color(0xff4c5c74); 43 | 44 | Color infoWindowNormalColor = Color(0xffffffff); 45 | Color infoWindowTitleColor = Color(0xffffffff); 46 | Color infoWindowUpColor = Color(0xff00ff00); 47 | Color infoWindowDnColor = Color(0xffff0000); 48 | 49 | Color hCrossColor = Color(0xffffffff); 50 | Color vCrossColor = Color(0x1Effffff); 51 | Color crossTextColor = Color(0xffffffff); 52 | 53 | //当前显示内最大和最小值的颜色 54 | Color maxColor = Color(0xffffffff); 55 | Color minColor = Color(0xffffffff); 56 | 57 | Color getMAColor(int index) { 58 | switch (index % 3) { 59 | case 1: 60 | return ma10Color; 61 | case 2: 62 | return ma30Color; 63 | default: 64 | return ma5Color; 65 | } 66 | } 67 | } 68 | 69 | class ChartStyle { 70 | double topPadding = 30.0; 71 | 72 | double bottomPadding = 20.0; 73 | 74 | double childPadding = 12.0; 75 | 76 | //点与点的距离 77 | double pointWidth = 11.0; 78 | 79 | //蜡烛宽度 80 | double candleWidth = 8.5; 81 | 82 | //蜡烛中间线的宽度 83 | double candleLineWidth = 1.5; 84 | 85 | //vol柱子宽度 86 | double volWidth = 8.5; 87 | 88 | //macd柱子宽度 89 | double macdWidth = 3.0; 90 | 91 | //垂直交叉线宽度 92 | double vCrossWidth = 8.5; 93 | 94 | //水平交叉线宽度 95 | double hCrossWidth = 0.5; 96 | 97 | //现在价格的线条长度 98 | double nowPriceLineLength = 1; 99 | 100 | //现在价格的线条间隔 101 | double nowPriceLineSpan = 1; 102 | 103 | //现在价格的线条粗细 104 | double nowPriceLineWidth = 1; 105 | 106 | int gridRows = 4; 107 | 108 | int gridColumns = 4; 109 | 110 | //下方時間客製化 111 | List? dateTimeFormat; 112 | } 113 | -------------------------------------------------------------------------------- /lib/chart_translations.dart: -------------------------------------------------------------------------------- 1 | class ChartTranslations { 2 | final String date; 3 | final String open; 4 | final String high; 5 | final String low; 6 | final String close; 7 | final String changeAmount; 8 | final String change; 9 | final String amount; 10 | 11 | const ChartTranslations({ 12 | this.date = 'Date', 13 | this.open = 'Open', 14 | this.high = 'High', 15 | this.low = 'Low', 16 | this.close = 'Close', 17 | this.changeAmount = 'Change', 18 | this.change = 'Change%', 19 | this.amount = 'Amount', 20 | }); 21 | 22 | String byIndex(int index) { 23 | switch (index) { 24 | case 0: 25 | return date; 26 | case 1: 27 | return open; 28 | case 2: 29 | return high; 30 | case 3: 31 | return low; 32 | case 4: 33 | return close; 34 | case 5: 35 | return changeAmount; 36 | case 6: 37 | return change; 38 | case 7: 39 | return amount; 40 | } 41 | 42 | throw UnimplementedError(); 43 | } 44 | } 45 | 46 | const kChartTranslations = { 47 | 'zh_CN': ChartTranslations( 48 | date: '时间', 49 | open: '开', 50 | high: '高', 51 | low: '低', 52 | close: '收', 53 | changeAmount: '涨跌额', 54 | change: '涨跌幅', 55 | amount: '成交额', 56 | ), 57 | }; 58 | -------------------------------------------------------------------------------- /lib/depth_chart.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart'; 4 | 5 | import 'package:k_chart/flutter_k_chart.dart'; 6 | 7 | class DepthChart extends StatefulWidget { 8 | final List bids, asks; 9 | final int fixedLength; 10 | final Color? buyPathColor; 11 | final Color? sellPathColor; 12 | final ChartColors chartColors; 13 | 14 | DepthChart( 15 | this.bids, 16 | this.asks, 17 | this.chartColors, { 18 | this.fixedLength = 2, 19 | this.buyPathColor, 20 | this.sellPathColor, 21 | }); 22 | 23 | @override 24 | _DepthChartState createState() => _DepthChartState(); 25 | } 26 | 27 | class _DepthChartState extends State { 28 | Offset? pressOffset; 29 | bool isLongPress = false; 30 | 31 | @override 32 | Widget build(BuildContext context) { 33 | return GestureDetector( 34 | onLongPressStart: (details) { 35 | pressOffset = details.localPosition; 36 | isLongPress = true; 37 | setState(() {}); 38 | }, 39 | onLongPressMoveUpdate: (details) { 40 | pressOffset = details.localPosition; 41 | isLongPress = true; 42 | setState(() {}); 43 | }, 44 | onTap: () { 45 | if (isLongPress) { 46 | isLongPress = false; 47 | setState(() {}); 48 | } 49 | }, 50 | child: CustomPaint( 51 | size: Size(double.infinity, double.infinity), 52 | painter: DepthChartPainter( 53 | widget.bids, 54 | widget.asks, 55 | pressOffset, 56 | isLongPress, 57 | widget.fixedLength, 58 | widget.buyPathColor, 59 | widget.sellPathColor, 60 | widget.chartColors), 61 | ), 62 | ); 63 | } 64 | } 65 | 66 | class DepthChartPainter extends CustomPainter { 67 | //买入//卖出 68 | List? mBuyData, mSellData; 69 | Offset? pressOffset; 70 | bool isLongPress; 71 | int? fixedLength; 72 | Color? mBuyPathColor, mSellPathColor; 73 | ChartColors chartColors; 74 | 75 | double mPaddingBottom = 18.0; 76 | double mWidth = 0.0, mDrawHeight = 0.0, mDrawWidth = 0.0; 77 | double? mBuyPointWidth, mSellPointWidth; 78 | 79 | //最大的委托量 80 | double? mMaxVolume, mMultiple; 81 | 82 | //右侧绘制个数 83 | int mLineCount = 4; 84 | 85 | Path? mBuyPath, mSellPath; 86 | 87 | //买卖出区域边线绘制画笔 //买卖出取悦绘制画笔 88 | Paint? mBuyLinePaint, 89 | mSellLinePaint, 90 | mBuyPathPaint, 91 | mSellPathPaint, 92 | selectPaint, 93 | selectBorderPaint; 94 | 95 | DepthChartPainter( 96 | this.mBuyData, 97 | this.mSellData, 98 | this.pressOffset, 99 | this.isLongPress, 100 | this.fixedLength, 101 | this.mBuyPathColor, 102 | this.mSellPathColor, 103 | this.chartColors) { 104 | mBuyLinePaint ??= Paint() 105 | ..isAntiAlias = true 106 | ..color = this.chartColors.depthBuyColor 107 | ..style = PaintingStyle.stroke 108 | ..strokeWidth = 1.0; 109 | mSellLinePaint ??= Paint() 110 | ..isAntiAlias = true 111 | ..color = this.chartColors.depthSellColor 112 | ..style = PaintingStyle.stroke 113 | ..strokeWidth = 1.0; 114 | 115 | mBuyPathPaint ??= Paint() 116 | ..isAntiAlias = true 117 | ..color = (mBuyPathColor == null 118 | ? this.chartColors.depthBuyColor.withOpacity(0.2) 119 | : mBuyPathColor)!; 120 | mSellPathPaint ??= Paint() 121 | ..isAntiAlias = true 122 | ..color = (mSellPathColor == null 123 | ? this.chartColors.depthSellColor.withOpacity(0.2) 124 | : mSellPathColor)!; 125 | mBuyPath ??= Path(); 126 | mSellPath ??= Path(); 127 | init(); 128 | } 129 | 130 | void init() { 131 | if (mBuyData == null || 132 | mBuyData!.isEmpty || 133 | mSellData == null || 134 | mSellData!.isEmpty) return; 135 | mMaxVolume = mBuyData![0].vol; 136 | mMaxVolume = max(mMaxVolume!, mSellData!.last.vol); 137 | mMaxVolume = mMaxVolume! * 1.05; 138 | mMultiple = mMaxVolume! / mLineCount; 139 | fixedLength ??= 2; 140 | 141 | selectPaint = Paint() 142 | ..isAntiAlias = true 143 | ..color = chartColors.selectFillColor; 144 | selectBorderPaint = Paint() 145 | ..isAntiAlias = true 146 | ..color = chartColors.selectBorderColor 147 | ..style = PaintingStyle.stroke 148 | ..strokeWidth = 0.5; 149 | } 150 | 151 | @override 152 | void paint(Canvas canvas, Size size) { 153 | if (mBuyData == null || 154 | mSellData == null || 155 | mBuyData!.isEmpty || 156 | mSellData!.isEmpty) return; 157 | mWidth = size.width; 158 | mDrawWidth = mWidth / 2; 159 | mDrawHeight = size.height - mPaddingBottom; 160 | // canvas.drawColor(Colors.green, BlendMode.srcATop); 161 | canvas.save(); 162 | //绘制买入区域 163 | drawBuy(canvas); 164 | //绘制卖出区域 165 | drawSell(canvas); 166 | 167 | //绘制界面相关文案 168 | drawText(canvas); 169 | canvas.restore(); 170 | } 171 | 172 | void drawBuy(Canvas canvas) { 173 | mBuyPointWidth = 174 | (mDrawWidth / (mBuyData!.length - 1 == 0 ? 1 : mBuyData!.length - 1)); 175 | mBuyPath!.reset(); 176 | double x; 177 | double y; 178 | for (int i = 0; i < mBuyData!.length; i++) { 179 | if (i == 0) { 180 | mBuyPath!.moveTo(0, getY(mBuyData![0].vol)); 181 | } 182 | x = mBuyPointWidth! * i; 183 | y = getY(mBuyData![i].vol); 184 | if (i >= 1) { 185 | canvas.drawLine( 186 | Offset(mBuyPointWidth! * (i - 1), getY(mBuyData![i - 1].vol)), 187 | Offset(x, y), 188 | mBuyLinePaint!); 189 | } 190 | if (i != mBuyData!.length - 1) { 191 | mBuyPath!.quadraticBezierTo( 192 | x, y, mBuyPointWidth! * (i + 1), getY(mBuyData![i + 1].vol)); 193 | } else { 194 | if (i == 0) { 195 | mBuyPath!.lineTo(mDrawWidth, y); 196 | mBuyPath!.lineTo(mDrawWidth, mDrawHeight); 197 | mBuyPath!.lineTo(0, mDrawHeight); 198 | } else { 199 | mBuyPath!.quadraticBezierTo(x, y, x, mDrawHeight); 200 | mBuyPath!.quadraticBezierTo(x, mDrawHeight, 0, mDrawHeight); 201 | } 202 | mBuyPath!.close(); 203 | } 204 | } 205 | canvas.drawPath(mBuyPath!, mBuyPathPaint!); 206 | } 207 | 208 | void drawSell(Canvas canvas) { 209 | mSellPointWidth = 210 | (mDrawWidth / (mSellData!.length - 1 == 0 ? 1 : mSellData!.length - 1)); 211 | mSellPath!.reset(); 212 | double x; 213 | double y; 214 | for (int i = 0; i < mSellData!.length; i++) { 215 | if (i == 0) { 216 | mSellPath!.moveTo(mDrawWidth, getY(mSellData![0].vol)); 217 | } 218 | x = (mSellPointWidth! * i) + mDrawWidth; 219 | y = getY(mSellData![i].vol); 220 | if (i >= 1) { 221 | canvas.drawLine( 222 | Offset((mSellPointWidth! * (i - 1)) + mDrawWidth, 223 | getY(mSellData![i - 1].vol)), 224 | Offset(x, y), 225 | mSellLinePaint!); 226 | } 227 | if (i != mSellData!.length - 1) { 228 | mSellPath!.quadraticBezierTo( 229 | x, 230 | y, 231 | (mSellPointWidth! * (i + 1)) + mDrawWidth, 232 | getY(mSellData![i + 1].vol)); 233 | } else { 234 | if (i == 0) { 235 | mSellPath!.lineTo(mWidth, y); 236 | mSellPath!.lineTo(mWidth, mDrawHeight); 237 | mSellPath!.lineTo(mDrawWidth, mDrawHeight); 238 | } else { 239 | mSellPath!.quadraticBezierTo(mWidth, y, x, mDrawHeight); 240 | mSellPath!.quadraticBezierTo(x, mDrawHeight, mDrawWidth, mDrawHeight); 241 | } 242 | mSellPath!.close(); 243 | } 244 | } 245 | canvas.drawPath(mSellPath!, mSellPathPaint!); 246 | } 247 | 248 | // int? mLastPosition; 249 | 250 | void drawText(Canvas canvas) { 251 | double value; 252 | String str; 253 | for (int j = 0; j < mLineCount; j++) { 254 | value = mMaxVolume! - mMultiple! * j; 255 | str = value.toStringAsFixed(fixedLength!); 256 | var tp = getTextPainter(str); 257 | tp.layout(); 258 | tp.paint( 259 | canvas, 260 | Offset( 261 | mWidth - tp.width, mDrawHeight / mLineCount * j + tp.height / 2)); 262 | } 263 | 264 | var startText = mBuyData!.first.price.toStringAsFixed(fixedLength!); 265 | TextPainter startTP = getTextPainter(startText); 266 | startTP.layout(); 267 | startTP.paint(canvas, Offset(0, getBottomTextY(startTP.height))); 268 | 269 | double centerPrice = (mBuyData!.last.price + mSellData!.first.price) / 2; 270 | 271 | var center = centerPrice.toStringAsFixed(fixedLength!); 272 | TextPainter centerTP = getTextPainter(center); 273 | centerTP.layout(); 274 | centerTP.paint( 275 | canvas, 276 | Offset( 277 | mDrawWidth - centerTP.width / 2, getBottomTextY(centerTP.height))); 278 | 279 | var endText = mSellData!.last.price.toStringAsFixed(fixedLength!); 280 | TextPainter endTP = getTextPainter(endText); 281 | endTP.layout(); 282 | endTP.paint( 283 | canvas, Offset(mWidth - endTP.width, getBottomTextY(endTP.height))); 284 | 285 | var leftHalfText = ((mBuyData!.first.price + centerPrice) / 2) 286 | .toStringAsFixed(fixedLength!); 287 | TextPainter leftHalfTP = getTextPainter(leftHalfText); 288 | leftHalfTP.layout(); 289 | leftHalfTP.paint( 290 | canvas, 291 | Offset((mDrawWidth - leftHalfTP.width) / 2, 292 | getBottomTextY(leftHalfTP.height))); 293 | 294 | var rightHalfText = ((mSellData!.last.price + centerPrice) / 2) 295 | .toStringAsFixed(fixedLength!); 296 | TextPainter rightHalfTP = getTextPainter(rightHalfText); 297 | rightHalfTP.layout(); 298 | rightHalfTP.paint( 299 | canvas, 300 | Offset((mDrawWidth + mWidth - rightHalfTP.width) / 2, 301 | getBottomTextY(rightHalfTP.height))); 302 | 303 | if (isLongPress == true) { 304 | if (pressOffset!.dx <= mDrawWidth) { 305 | int index = _indexOfTranslateX( 306 | pressOffset!.dx, 0, mBuyData!.length - 1, getBuyX); 307 | drawSelectView(canvas, index, true); 308 | } else { 309 | int index = _indexOfTranslateX( 310 | pressOffset!.dx, 0, mSellData!.length - 1, getSellX); 311 | drawSelectView(canvas, index, false); 312 | } 313 | } 314 | } 315 | 316 | void drawSelectView(Canvas canvas, int index, bool isLeft) { 317 | DepthEntity entity = isLeft ? mBuyData![index] : mSellData![index]; 318 | double dx = isLeft ? getBuyX(index) : getSellX(index); 319 | 320 | double radius = 8.0; 321 | if (dx < mDrawWidth) { 322 | canvas.drawCircle(Offset(dx, getY(entity.vol)), radius / 3, 323 | mBuyLinePaint!..style = PaintingStyle.fill); 324 | canvas.drawCircle(Offset(dx, getY(entity.vol)), radius, 325 | mBuyLinePaint!..style = PaintingStyle.stroke); 326 | } else { 327 | canvas.drawCircle(Offset(dx, getY(entity.vol)), radius / 3, 328 | mSellLinePaint!..style = PaintingStyle.fill); 329 | canvas.drawCircle(Offset(dx, getY(entity.vol)), radius, 330 | mSellLinePaint!..style = PaintingStyle.stroke); 331 | } 332 | 333 | //画底部 334 | TextPainter priceTP = 335 | getTextPainter(entity.price.toStringAsFixed(fixedLength!)); 336 | priceTP.layout(); 337 | double left; 338 | if (dx <= priceTP.width / 2) { 339 | left = 0; 340 | } else if (dx >= mWidth - priceTP.width / 2) { 341 | left = mWidth - priceTP.width; 342 | } else { 343 | left = dx - priceTP.width / 2; 344 | } 345 | Rect bottomRect = Rect.fromLTRB(left - 3, mDrawHeight + 3, 346 | left + priceTP.width + 3, mDrawHeight + mPaddingBottom); 347 | canvas.drawRect(bottomRect, selectPaint!); 348 | canvas.drawRect(bottomRect, selectBorderPaint!); 349 | priceTP.paint( 350 | canvas, 351 | Offset(bottomRect.left + (bottomRect.width - priceTP.width) / 2, 352 | bottomRect.top + (bottomRect.height - priceTP.height) / 2)); 353 | //画左边 354 | TextPainter amountTP = 355 | getTextPainter(entity.vol.toStringAsFixed(fixedLength!)); 356 | amountTP.layout(); 357 | double y = getY(entity.vol); 358 | double rightRectTop; 359 | if (y <= amountTP.height / 2) { 360 | rightRectTop = 0; 361 | } else if (y >= mDrawHeight - amountTP.height / 2) { 362 | rightRectTop = mDrawHeight - amountTP.height; 363 | } else { 364 | rightRectTop = y - amountTP.height / 2; 365 | } 366 | Rect rightRect = Rect.fromLTRB(mWidth - amountTP.width - 6, 367 | rightRectTop - 3, mWidth, rightRectTop + amountTP.height + 3); 368 | canvas.drawRect(rightRect, selectPaint!); 369 | canvas.drawRect(rightRect, selectBorderPaint!); 370 | amountTP.paint( 371 | canvas, 372 | Offset(rightRect.left + (rightRect.width - amountTP.width) / 2, 373 | rightRect.top + (rightRect.height - amountTP.height) / 2)); 374 | } 375 | 376 | ///二分查找当前值的index 377 | int _indexOfTranslateX(double translateX, int start, int end, Function getX) { 378 | if (end == start || end == -1) { 379 | return start; 380 | } 381 | if (end - start == 1) { 382 | double startValue = getX(start); 383 | double endValue = getX(end); 384 | return (translateX - startValue).abs() < (translateX - endValue).abs() 385 | ? start 386 | : end; 387 | } 388 | int mid = start + (end - start) ~/ 2; 389 | double midValue = getX(mid); 390 | if (translateX < midValue) { 391 | return _indexOfTranslateX(translateX, start, mid, getX); 392 | } else if (translateX > midValue) { 393 | return _indexOfTranslateX(translateX, mid, end, getX); 394 | } else { 395 | return mid; 396 | } 397 | } 398 | 399 | double getBuyX(int position) => position * mBuyPointWidth!; 400 | 401 | double getSellX(int position) => position * mSellPointWidth! + mDrawWidth; 402 | 403 | getTextPainter(String text, [Color color = Colors.white]) => TextPainter( 404 | text: 405 | TextSpan(text: "$text", style: TextStyle(color: color, fontSize: 10)), 406 | textDirection: TextDirection.ltr); 407 | 408 | double getBottomTextY(double textHeight) => 409 | (mPaddingBottom - textHeight) / 2 + mDrawHeight; 410 | 411 | double getY(double volume) => 412 | mDrawHeight - (mDrawHeight) * volume / mMaxVolume!; 413 | 414 | @override 415 | bool shouldRepaint(DepthChartPainter oldDelegate) { 416 | // return oldDelegate.mBuyData != mBuyData || 417 | // oldDelegate.mSellData != mSellData || 418 | // oldDelegate.isLongPress != isLongPress || 419 | // oldDelegate.pressOffset != pressOffset; 420 | return true; 421 | } 422 | } 423 | -------------------------------------------------------------------------------- /lib/entity/candle_entity.dart: -------------------------------------------------------------------------------- 1 | // ignore_for_file: non_constant_identifier_names,library_prefixes,unused_import,camel_case_types 2 | mixin CandleEntity { 3 | late double open; 4 | late double high; 5 | late double low; 6 | late double close; 7 | 8 | List? maValueList; 9 | 10 | // 上轨线 11 | double? up; 12 | 13 | // 中轨线 14 | double? mb; 15 | 16 | // 下轨线 17 | double? dn; 18 | 19 | double? BOLLMA; 20 | } 21 | -------------------------------------------------------------------------------- /lib/entity/cci_entity.dart: -------------------------------------------------------------------------------- 1 | mixin CCIEntity { 2 | double? cci; 3 | } -------------------------------------------------------------------------------- /lib/entity/depth_entity.dart: -------------------------------------------------------------------------------- 1 | class DepthEntity { 2 | double price; 3 | double vol; 4 | 5 | DepthEntity(this.price, this.vol); 6 | 7 | @override 8 | String toString() { 9 | return 'Data{price: $price, vol: $vol}'; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lib/entity/index.dart: -------------------------------------------------------------------------------- 1 | export 'candle_entity.dart'; 2 | export 'cci_entity.dart'; 3 | export 'depth_entity.dart'; 4 | export 'info_window_entity.dart'; 5 | export 'kdj_entity.dart'; 6 | export 'k_entity.dart'; 7 | export 'k_line_entity.dart'; 8 | export 'macd_entity.dart'; 9 | export 'rsi_entity.dart'; 10 | export 'rw_entity.dart'; 11 | export 'volume_entity.dart'; -------------------------------------------------------------------------------- /lib/entity/info_window_entity.dart: -------------------------------------------------------------------------------- 1 | import '../entity/k_line_entity.dart'; 2 | 3 | class InfoWindowEntity { 4 | KLineEntity kLineEntity; 5 | bool isLeft; 6 | 7 | InfoWindowEntity( 8 | this.kLineEntity, { 9 | this.isLeft = false, 10 | }); 11 | } 12 | -------------------------------------------------------------------------------- /lib/entity/k_entity.dart: -------------------------------------------------------------------------------- 1 | import 'candle_entity.dart'; 2 | import 'kdj_entity.dart'; 3 | import 'macd_entity.dart'; 4 | import 'rsi_entity.dart'; 5 | import 'rw_entity.dart'; 6 | import 'volume_entity.dart'; 7 | import 'cci_entity.dart'; 8 | 9 | class KEntity 10 | with 11 | CandleEntity, 12 | VolumeEntity, 13 | KDJEntity, 14 | RSIEntity, 15 | WREntity, 16 | CCIEntity, 17 | MACDEntity {} 18 | -------------------------------------------------------------------------------- /lib/entity/k_line_entity.dart: -------------------------------------------------------------------------------- 1 | import '../entity/k_entity.dart'; 2 | 3 | class KLineEntity extends KEntity { 4 | late double open; 5 | late double high; 6 | late double low; 7 | late double close; 8 | late double vol; 9 | late double? amount; 10 | double? change; 11 | double? ratio; 12 | int? time; 13 | 14 | KLineEntity.fromCustom({ 15 | this.amount, 16 | required this.open, 17 | required this.close, 18 | this.change, 19 | this.ratio, 20 | required this.time, 21 | required this.high, 22 | required this.low, 23 | required this.vol, 24 | }); 25 | 26 | KLineEntity.fromJson(Map json) { 27 | open = json['open']?.toDouble() ?? 0; 28 | high = json['high']?.toDouble() ?? 0; 29 | low = json['low']?.toDouble() ?? 0; 30 | close = json['close']?.toDouble() ?? 0; 31 | vol = json['vol']?.toDouble() ?? 0; 32 | amount = json['amount']?.toDouble(); 33 | int? tempTime = json['time']?.toInt(); 34 | //兼容火币数据 35 | if (tempTime == null) { 36 | tempTime = json['id']?.toInt() ?? 0; 37 | tempTime = tempTime! * 1000; 38 | } 39 | time = tempTime; 40 | ratio = json['ratio']?.toDouble(); 41 | change = json['change']?.toDouble(); 42 | } 43 | 44 | Map toJson() { 45 | final Map data = new Map(); 46 | data['time'] = this.time; 47 | data['open'] = this.open; 48 | data['close'] = this.close; 49 | data['high'] = this.high; 50 | data['low'] = this.low; 51 | data['vol'] = this.vol; 52 | data['amount'] = this.amount; 53 | data['ratio'] = this.ratio; 54 | data['change'] = this.change; 55 | return data; 56 | } 57 | 58 | @override 59 | String toString() { 60 | return 'MarketModel{open: $open, high: $high, low: $low, close: $close, vol: $vol, time: $time, amount: $amount, ratio: $ratio, change: $change}'; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /lib/entity/kdj_entity.dart: -------------------------------------------------------------------------------- 1 | mixin KDJEntity { 2 | double? k; 3 | double? d; 4 | double? j; 5 | } 6 | -------------------------------------------------------------------------------- /lib/entity/macd_entity.dart: -------------------------------------------------------------------------------- 1 | import 'cci_entity.dart'; 2 | import 'kdj_entity.dart'; 3 | import 'rsi_entity.dart'; 4 | import 'rw_entity.dart'; 5 | 6 | mixin MACDEntity on KDJEntity, RSIEntity, WREntity, CCIEntity { 7 | double? dea; 8 | double? dif; 9 | double? macd; 10 | } 11 | -------------------------------------------------------------------------------- /lib/entity/rsi_entity.dart: -------------------------------------------------------------------------------- 1 | mixin RSIEntity { 2 | /// RSI值 3 | double? rsi; 4 | } 5 | -------------------------------------------------------------------------------- /lib/entity/rw_entity.dart: -------------------------------------------------------------------------------- 1 | mixin WREntity { 2 | /// %R值 3 | double? r; 4 | } 5 | -------------------------------------------------------------------------------- /lib/entity/volume_entity.dart: -------------------------------------------------------------------------------- 1 | // ignore_for_file: non_constant_identifier_names,library_prefixes,unused_import,camel_case_types 2 | mixin VolumeEntity { 3 | late double open; 4 | late double close; 5 | late double vol; 6 | double? MA5Volume; 7 | double? MA10Volume; 8 | } 9 | -------------------------------------------------------------------------------- /lib/extension/map_ext.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | import 'package:k_chart/chart_translations.dart'; 3 | 4 | extension ChartTranslationsMap on Map { 5 | ChartTranslations of(BuildContext context) { 6 | final locale = Localizations.localeOf(context); 7 | final languageTag = '${locale.languageCode}_${locale.countryCode}'; 8 | 9 | return this[languageTag] ?? ChartTranslations(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lib/extension/num_ext.dart: -------------------------------------------------------------------------------- 1 | extension NumExt on num? { 2 | bool get notNullOrZero { 3 | if (this == null || this == 0) { 4 | return false; 5 | } 6 | return this!.abs().toStringAsFixed(4) != "0.0000"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /lib/flutter_k_chart.dart: -------------------------------------------------------------------------------- 1 | library flutter_k_chart; 2 | 3 | export 'k_chart_widget.dart'; //布局 4 | export 'chart_style.dart'; 5 | export 'depth_chart.dart'; 6 | 7 | export 'utils/index.dart'; //数据加工 8 | export 'entity/index.dart'; //数据 9 | export 'renderer/index.dart'; 10 | export 'extension/num_ext.dart'; -------------------------------------------------------------------------------- /lib/renderer/base_chart_painter.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart' 4 | show Color, TextStyle, Rect, Canvas, Size, CustomPainter; 5 | import 'package:k_chart/utils/date_format_util.dart'; 6 | 7 | import '../chart_style.dart' show ChartStyle; 8 | import '../entity/k_line_entity.dart'; 9 | import '../k_chart_widget.dart'; 10 | 11 | export 'package:flutter/material.dart' 12 | show Color, required, TextStyle, Rect, Canvas, Size, CustomPainter; 13 | 14 | abstract class BaseChartPainter extends CustomPainter { 15 | static double maxScrollX = 0.0; 16 | List? datas; 17 | MainState mainState; 18 | 19 | SecondaryState secondaryState; 20 | 21 | bool volHidden; 22 | bool isTapShowInfoDialog; 23 | double scaleX = 1.0, scrollX = 0.0, selectX; 24 | bool isLongPress = false; 25 | bool isOnTap; 26 | bool isLine; 27 | 28 | //3块区域大小与位置 29 | late Rect mMainRect; 30 | Rect? mVolRect, mSecondaryRect; 31 | late double mDisplayHeight, mWidth; 32 | double mTopPadding = 30.0, mBottomPadding = 20.0, mChildPadding = 12.0; 33 | int mGridRows = 4, mGridColumns = 4; 34 | int mStartIndex = 0, mStopIndex = 0; 35 | double mMainMaxValue = double.minPositive, mMainMinValue = double.maxFinite; 36 | double mVolMaxValue = double.minPositive, mVolMinValue = double.maxFinite; 37 | double mSecondaryMaxValue = double.minPositive, 38 | mSecondaryMinValue = double.maxFinite; 39 | double mTranslateX = double.minPositive; 40 | int mMainMaxIndex = 0, mMainMinIndex = 0; 41 | double mMainHighMaxValue = double.minPositive, 42 | mMainLowMinValue = double.maxFinite; 43 | int mItemCount = 0; 44 | double mDataLen = 0.0; //数据占屏幕总长度 45 | final ChartStyle chartStyle; 46 | late double mPointWidth; 47 | List mFormats = [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn]; //格式化时间 48 | double xFrontPadding; 49 | 50 | BaseChartPainter( 51 | this.chartStyle, { 52 | this.datas, 53 | required this.scaleX, 54 | required this.scrollX, 55 | required this.isLongPress, 56 | required this.selectX, 57 | required this.xFrontPadding, 58 | this.isOnTap = false, 59 | this.mainState = MainState.MA, 60 | this.volHidden = false, 61 | this.isTapShowInfoDialog = false, 62 | this.secondaryState = SecondaryState.MACD, 63 | this.isLine = false, 64 | }) { 65 | mItemCount = datas?.length ?? 0; 66 | mPointWidth = this.chartStyle.pointWidth; 67 | mTopPadding = this.chartStyle.topPadding; 68 | mBottomPadding = this.chartStyle.bottomPadding; 69 | mChildPadding = this.chartStyle.childPadding; 70 | mGridRows = this.chartStyle.gridRows; 71 | mGridColumns = this.chartStyle.gridColumns; 72 | mDataLen = mItemCount * mPointWidth; 73 | initFormats(); 74 | } 75 | 76 | void initFormats() { 77 | if (this.chartStyle.dateTimeFormat != null) { 78 | mFormats = this.chartStyle.dateTimeFormat!; 79 | return; 80 | } 81 | 82 | if (mItemCount < 2) { 83 | mFormats = [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn]; 84 | return; 85 | } 86 | 87 | int firstTime = datas!.first.time ?? 0; 88 | int secondTime = datas![1].time ?? 0; 89 | int time = secondTime - firstTime; 90 | time ~/= 1000; 91 | //月线 92 | if (time >= 24 * 60 * 60 * 28) 93 | mFormats = [yy, '-', mm]; 94 | //日线等 95 | else if (time >= 24 * 60 * 60) 96 | mFormats = [yy, '-', mm, '-', dd]; 97 | //小时线等 98 | else 99 | mFormats = [mm, '-', dd, ' ', HH, ':', nn]; 100 | } 101 | 102 | @override 103 | void paint(Canvas canvas, Size size) { 104 | canvas.clipRect(Rect.fromLTRB(0, 0, size.width, size.height)); 105 | mDisplayHeight = size.height - mTopPadding - mBottomPadding; 106 | mWidth = size.width; 107 | initRect(size); 108 | calculateValue(); 109 | initChartRenderer(); 110 | 111 | canvas.save(); 112 | canvas.scale(1, 1); 113 | drawBg(canvas, size); 114 | drawGrid(canvas); 115 | if (datas != null && datas!.isNotEmpty) { 116 | drawChart(canvas, size); 117 | drawVerticalText(canvas); 118 | drawDate(canvas, size); 119 | 120 | drawText(canvas, datas!.last, 5); 121 | drawMaxAndMin(canvas); 122 | drawNowPrice(canvas); 123 | 124 | if (isLongPress == true || (isTapShowInfoDialog && isOnTap)) { 125 | drawCrossLineText(canvas, size); 126 | } 127 | } 128 | canvas.restore(); 129 | } 130 | 131 | void initChartRenderer(); 132 | 133 | //画背景 134 | void drawBg(Canvas canvas, Size size); 135 | 136 | //画网格 137 | void drawGrid(canvas); 138 | 139 | //画图表 140 | void drawChart(Canvas canvas, Size size); 141 | 142 | //画右边值 143 | void drawVerticalText(canvas); 144 | 145 | //画时间 146 | void drawDate(Canvas canvas, Size size); 147 | 148 | //画值 149 | void drawText(Canvas canvas, KLineEntity data, double x); 150 | 151 | //画最大最小值 152 | void drawMaxAndMin(Canvas canvas); 153 | 154 | //画当前价格 155 | void drawNowPrice(Canvas canvas); 156 | 157 | //画交叉线 158 | void drawCrossLine(Canvas canvas, Size size); 159 | 160 | //交叉线值 161 | void drawCrossLineText(Canvas canvas, Size size); 162 | 163 | void initRect(Size size) { 164 | double volHeight = volHidden != true ? mDisplayHeight * 0.2 : 0; 165 | double secondaryHeight = 166 | secondaryState != SecondaryState.NONE ? mDisplayHeight * 0.2 : 0; 167 | 168 | double mainHeight = mDisplayHeight; 169 | mainHeight -= volHeight; 170 | mainHeight -= secondaryHeight; 171 | 172 | mMainRect = Rect.fromLTRB(0, mTopPadding, mWidth, mTopPadding + mainHeight); 173 | 174 | if (volHidden != true) { 175 | mVolRect = Rect.fromLTRB(0, mMainRect.bottom + mChildPadding, mWidth, 176 | mMainRect.bottom + volHeight); 177 | } 178 | 179 | //secondaryState == SecondaryState.NONE隐藏副视图 180 | if (secondaryState != SecondaryState.NONE) { 181 | mSecondaryRect = Rect.fromLTRB( 182 | 0, 183 | mMainRect.bottom + volHeight + mChildPadding, 184 | mWidth, 185 | mMainRect.bottom + volHeight + secondaryHeight); 186 | } 187 | } 188 | 189 | calculateValue() { 190 | if (datas == null) return; 191 | if (datas!.isEmpty) return; 192 | maxScrollX = getMinTranslateX().abs(); 193 | setTranslateXFromScrollX(scrollX); 194 | mStartIndex = indexOfTranslateX(xToTranslateX(0)); 195 | mStopIndex = indexOfTranslateX(xToTranslateX(mWidth)); 196 | for (int i = mStartIndex; i <= mStopIndex; i++) { 197 | var item = datas![i]; 198 | getMainMaxMinValue(item, i); 199 | getVolMaxMinValue(item); 200 | getSecondaryMaxMinValue(item); 201 | } 202 | } 203 | 204 | void getMainMaxMinValue(KLineEntity item, int i) { 205 | double maxPrice, minPrice; 206 | if (mainState == MainState.MA) { 207 | maxPrice = max(item.high, _findMaxMA(item.maValueList ?? [0])); 208 | minPrice = min(item.low, _findMinMA(item.maValueList ?? [0])); 209 | } else if (mainState == MainState.BOLL) { 210 | maxPrice = max(item.up ?? 0, item.high); 211 | minPrice = min(item.dn ?? 0, item.low); 212 | } else { 213 | maxPrice = item.high; 214 | minPrice = item.low; 215 | } 216 | mMainMaxValue = max(mMainMaxValue, maxPrice); 217 | mMainMinValue = min(mMainMinValue, minPrice); 218 | 219 | if (mMainHighMaxValue < item.high) { 220 | mMainHighMaxValue = item.high; 221 | mMainMaxIndex = i; 222 | } 223 | if (mMainLowMinValue > item.low) { 224 | mMainLowMinValue = item.low; 225 | mMainMinIndex = i; 226 | } 227 | 228 | if (isLine == true) { 229 | mMainMaxValue = max(mMainMaxValue, item.close); 230 | mMainMinValue = min(mMainMinValue, item.close); 231 | } 232 | } 233 | 234 | double _findMaxMA(List a) { 235 | double result = double.minPositive; 236 | for (double i in a) { 237 | result = max(result, i); 238 | } 239 | return result; 240 | } 241 | 242 | double _findMinMA(List a) { 243 | double result = double.maxFinite; 244 | for (double i in a) { 245 | result = min(result, i == 0 ? double.maxFinite : i); 246 | } 247 | return result; 248 | } 249 | 250 | void getVolMaxMinValue(KLineEntity item) { 251 | mVolMaxValue = max(mVolMaxValue, 252 | max(item.vol, max(item.MA5Volume ?? 0, item.MA10Volume ?? 0))); 253 | mVolMinValue = min(mVolMinValue, 254 | min(item.vol, min(item.MA5Volume ?? 0, item.MA10Volume ?? 0))); 255 | } 256 | 257 | void getSecondaryMaxMinValue(KLineEntity item) { 258 | if (secondaryState == SecondaryState.MACD) { 259 | if (item.macd != null) { 260 | mSecondaryMaxValue = 261 | max(mSecondaryMaxValue, max(item.macd!, max(item.dif!, item.dea!))); 262 | mSecondaryMinValue = 263 | min(mSecondaryMinValue, min(item.macd!, min(item.dif!, item.dea!))); 264 | } 265 | } else if (secondaryState == SecondaryState.KDJ) { 266 | if (item.d != null) { 267 | mSecondaryMaxValue = 268 | max(mSecondaryMaxValue, max(item.k!, max(item.d!, item.j!))); 269 | mSecondaryMinValue = 270 | min(mSecondaryMinValue, min(item.k!, min(item.d!, item.j!))); 271 | } 272 | } else if (secondaryState == SecondaryState.RSI) { 273 | if (item.rsi != null) { 274 | mSecondaryMaxValue = max(mSecondaryMaxValue, item.rsi!); 275 | mSecondaryMinValue = min(mSecondaryMinValue, item.rsi!); 276 | } 277 | } else if (secondaryState == SecondaryState.WR) { 278 | mSecondaryMaxValue = 0; 279 | mSecondaryMinValue = -100; 280 | } else if (secondaryState == SecondaryState.CCI) { 281 | if (item.cci != null) { 282 | mSecondaryMaxValue = max(mSecondaryMaxValue, item.cci!); 283 | mSecondaryMinValue = min(mSecondaryMinValue, item.cci!); 284 | } 285 | } else { 286 | mSecondaryMaxValue = 0; 287 | mSecondaryMinValue = 0; 288 | } 289 | } 290 | 291 | double xToTranslateX(double x) => -mTranslateX + x / scaleX; 292 | 293 | int indexOfTranslateX(double translateX) => 294 | _indexOfTranslateX(translateX, 0, mItemCount - 1); 295 | 296 | ///二分查找当前值的index 297 | int _indexOfTranslateX(double translateX, int start, int end) { 298 | if (end == start || end == -1) { 299 | return start; 300 | } 301 | if (end - start == 1) { 302 | double startValue = getX(start); 303 | double endValue = getX(end); 304 | return (translateX - startValue).abs() < (translateX - endValue).abs() 305 | ? start 306 | : end; 307 | } 308 | int mid = start + (end - start) ~/ 2; 309 | double midValue = getX(mid); 310 | if (translateX < midValue) { 311 | return _indexOfTranslateX(translateX, start, mid); 312 | } else if (translateX > midValue) { 313 | return _indexOfTranslateX(translateX, mid, end); 314 | } else { 315 | return mid; 316 | } 317 | } 318 | 319 | ///根据索引索取x坐标 320 | ///+ mPointWidth / 2防止第一根和最后一根k线显示不��� 321 | ///@param position 索引值 322 | double getX(int position) => position * mPointWidth + mPointWidth / 2; 323 | 324 | KLineEntity getItem(int position) { 325 | return datas![position]; 326 | // if (datas != null) { 327 | // return datas[position]; 328 | // } else { 329 | // return null; 330 | // } 331 | } 332 | 333 | ///scrollX 转换为 TranslateX 334 | void setTranslateXFromScrollX(double scrollX) => 335 | mTranslateX = scrollX + getMinTranslateX(); 336 | 337 | ///获取平移的最小值 338 | double getMinTranslateX() { 339 | var x = -mDataLen + mWidth / scaleX - mPointWidth / 2 - xFrontPadding; 340 | return x >= 0 ? 0.0 : x; 341 | } 342 | 343 | ///计算长按后x的值,转换为index 344 | int calculateSelectedX(double selectX) { 345 | int mSelectedIndex = indexOfTranslateX(xToTranslateX(selectX)); 346 | if (mSelectedIndex < mStartIndex) { 347 | mSelectedIndex = mStartIndex; 348 | } 349 | if (mSelectedIndex > mStopIndex) { 350 | mSelectedIndex = mStopIndex; 351 | } 352 | return mSelectedIndex; 353 | } 354 | 355 | ///translateX转化为view中的x 356 | double translateXtoX(double translateX) => 357 | (translateX + mTranslateX) * scaleX; 358 | 359 | TextStyle getTextStyle(Color color) { 360 | return TextStyle(fontSize: 10.0, color: color); 361 | } 362 | 363 | @override 364 | bool shouldRepaint(BaseChartPainter oldDelegate) { 365 | return true; 366 | // return oldDelegate.datas != datas || 367 | // oldDelegate.datas?.length != datas?.length || 368 | // oldDelegate.scaleX != scaleX || 369 | // oldDelegate.scrollX != scrollX || 370 | // oldDelegate.isLongPress != isLongPress || 371 | // oldDelegate.selectX != selectX || 372 | // oldDelegate.isLine != isLine || 373 | // oldDelegate.mainState != mainState || 374 | // oldDelegate.secondaryState != secondaryState; 375 | } 376 | } 377 | -------------------------------------------------------------------------------- /lib/renderer/base_chart_renderer.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | export '../chart_style.dart'; 4 | 5 | abstract class BaseChartRenderer { 6 | double maxValue, minValue; 7 | late double scaleY; 8 | double topPadding; 9 | Rect chartRect; 10 | int fixedLength; 11 | Paint chartPaint = Paint() 12 | ..isAntiAlias = true 13 | ..filterQuality = FilterQuality.high 14 | ..strokeWidth = 1.0 15 | ..color = Colors.red; 16 | Paint gridPaint = Paint() 17 | ..isAntiAlias = true 18 | ..filterQuality = FilterQuality.high 19 | ..strokeWidth = 0.5 20 | ..color = Color(0xff4c5c74); 21 | 22 | BaseChartRenderer({ 23 | required this.chartRect, 24 | required this.maxValue, 25 | required this.minValue, 26 | required this.topPadding, 27 | required this.fixedLength, 28 | required Color gridColor, 29 | }) { 30 | if (maxValue == minValue) { 31 | maxValue *= 1.5; 32 | minValue /= 2; 33 | } 34 | scaleY = chartRect.height / (maxValue - minValue); 35 | gridPaint.color = gridColor; 36 | // print("maxValue=====" + maxValue.toString() + "====minValue===" + minValue.toString() + "==scaleY==" + scaleY.toString()); 37 | } 38 | 39 | double getY(double y) => (maxValue - y) * scaleY + chartRect.top; 40 | 41 | String format(double? n) { 42 | if (n == null || n.isNaN) { 43 | return "0.00"; 44 | } else { 45 | return n.toStringAsFixed(fixedLength); 46 | } 47 | } 48 | 49 | void drawGrid(Canvas canvas, int gridRows, int gridColumns); 50 | 51 | void drawText(Canvas canvas, T data, double x); 52 | 53 | void drawVerticalText(canvas, textStyle, int gridRows); 54 | 55 | void drawChart(T lastPoint, T curPoint, double lastX, double curX, Size size, 56 | Canvas canvas); 57 | 58 | void drawLine(double? lastPrice, double? curPrice, Canvas canvas, 59 | double lastX, double curX, Color color) { 60 | if (lastPrice == null || curPrice == null) { 61 | return; 62 | } 63 | //("lasePrice==" + lastPrice.toString() + "==curPrice==" + curPrice.toString()); 64 | double lastY = getY(lastPrice); 65 | double curY = getY(curPrice); 66 | //print("lastX-----==" + lastX.toString() + "==lastY==" + lastY.toString() + "==curX==" + curX.toString() + "==curY==" + curY.toString()); 67 | canvas.drawLine( 68 | Offset(lastX, lastY), Offset(curX, curY), chartPaint..color = color); 69 | } 70 | 71 | TextStyle getTextStyle(Color color) { 72 | return TextStyle(fontSize: 10.0, color: color); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /lib/renderer/index.dart: -------------------------------------------------------------------------------- 1 | export 'base_chart_painter.dart'; 2 | export 'base_chart_renderer.dart'; 3 | export 'chart_painter.dart'; 4 | export 'main_renderer.dart'; 5 | export 'secondary_renderer.dart'; 6 | export 'vol_renderer.dart'; 7 | -------------------------------------------------------------------------------- /lib/renderer/main_renderer.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | import '../entity/candle_entity.dart'; 4 | import '../k_chart_widget.dart' show MainState; 5 | import 'base_chart_renderer.dart'; 6 | 7 | enum VerticalTextAlignment { left, right } 8 | //For TrendLine 9 | double? trendLineMax; 10 | double? trendLineScale; 11 | double? trendLineContentRec; 12 | 13 | class MainRenderer extends BaseChartRenderer { 14 | late double mCandleWidth; 15 | late double mCandleLineWidth; 16 | MainState state; 17 | bool isLine; 18 | 19 | //绘制的内容区域 20 | late Rect _contentRect; 21 | double _contentPadding = 5.0; 22 | List maDayList; 23 | final ChartStyle chartStyle; 24 | final ChartColors chartColors; 25 | final double mLineStrokeWidth = 1.0; 26 | double scaleX; 27 | late Paint mLinePaint; 28 | final VerticalTextAlignment verticalTextAlignment; 29 | 30 | MainRenderer( 31 | Rect mainRect, 32 | double maxValue, 33 | double minValue, 34 | double topPadding, 35 | this.state, 36 | this.isLine, 37 | int fixedLength, 38 | this.chartStyle, 39 | this.chartColors, 40 | this.scaleX, 41 | this.verticalTextAlignment, 42 | [this.maDayList = const [5, 10, 20]]) 43 | : super( 44 | chartRect: mainRect, 45 | maxValue: maxValue, 46 | minValue: minValue, 47 | topPadding: topPadding, 48 | fixedLength: fixedLength, 49 | gridColor: chartColors.gridColor) { 50 | mCandleWidth = this.chartStyle.candleWidth; 51 | mCandleLineWidth = this.chartStyle.candleLineWidth; 52 | mLinePaint = Paint() 53 | ..isAntiAlias = true 54 | ..style = PaintingStyle.stroke 55 | ..strokeWidth = mLineStrokeWidth 56 | ..color = this.chartColors.kLineColor; 57 | _contentRect = Rect.fromLTRB( 58 | chartRect.left, 59 | chartRect.top + _contentPadding, 60 | chartRect.right, 61 | chartRect.bottom - _contentPadding); 62 | if (maxValue == minValue) { 63 | maxValue *= 1.5; 64 | minValue /= 2; 65 | } 66 | scaleY = _contentRect.height / (maxValue - minValue); 67 | } 68 | 69 | @override 70 | void drawText(Canvas canvas, CandleEntity data, double x) { 71 | if (isLine == true) return; 72 | TextSpan? span; 73 | if (state == MainState.MA) { 74 | span = TextSpan( 75 | children: _createMATextSpan(data), 76 | ); 77 | } else if (state == MainState.BOLL) { 78 | span = TextSpan( 79 | children: [ 80 | if (data.up != 0) 81 | TextSpan( 82 | text: "BOLL:${format(data.mb)} ", 83 | style: getTextStyle(this.chartColors.ma5Color)), 84 | if (data.mb != 0) 85 | TextSpan( 86 | text: "UB:${format(data.up)} ", 87 | style: getTextStyle(this.chartColors.ma10Color)), 88 | if (data.dn != 0) 89 | TextSpan( 90 | text: "LB:${format(data.dn)} ", 91 | style: getTextStyle(this.chartColors.ma30Color)), 92 | ], 93 | ); 94 | } 95 | if (span == null) return; 96 | TextPainter tp = TextPainter(text: span, textDirection: TextDirection.ltr); 97 | tp.layout(); 98 | tp.paint(canvas, Offset(x, chartRect.top - topPadding)); 99 | } 100 | 101 | List _createMATextSpan(CandleEntity data) { 102 | List result = []; 103 | for (int i = 0; i < (data.maValueList?.length ?? 0); i++) { 104 | if (data.maValueList?[i] != 0) { 105 | var item = TextSpan( 106 | text: "MA${maDayList[i]}:${format(data.maValueList![i])} ", 107 | style: getTextStyle(this.chartColors.getMAColor(i))); 108 | result.add(item); 109 | } 110 | } 111 | return result; 112 | } 113 | 114 | @override 115 | void drawChart(CandleEntity lastPoint, CandleEntity curPoint, double lastX, 116 | double curX, Size size, Canvas canvas) { 117 | if (isLine) { 118 | drawPolyline(lastPoint.close, curPoint.close, canvas, lastX, curX); 119 | } else { 120 | drawCandle(curPoint, canvas, curX); 121 | if (state == MainState.MA) { 122 | drawMaLine(lastPoint, curPoint, canvas, lastX, curX); 123 | } else if (state == MainState.BOLL) { 124 | drawBollLine(lastPoint, curPoint, canvas, lastX, curX); 125 | } 126 | } 127 | } 128 | 129 | Shader? mLineFillShader; 130 | Path? mLinePath, mLineFillPath; 131 | Paint mLineFillPaint = Paint() 132 | ..style = PaintingStyle.fill 133 | ..isAntiAlias = true; 134 | 135 | //画折线图 136 | drawPolyline(double lastPrice, double curPrice, Canvas canvas, double lastX, 137 | double curX) { 138 | // drawLine(lastPrice + 100, curPrice + 100, canvas, lastX, curX, ChartColors.kLineColor); 139 | mLinePath ??= Path(); 140 | 141 | // if (lastX == curX) { 142 | // mLinePath.moveTo(lastX, getY(lastPrice)); 143 | // } else { 144 | //// mLinePath.lineTo(curX, getY(curPrice)); 145 | // mLinePath.cubicTo( 146 | // (lastX + curX) / 2, getY(lastPrice), (lastX + curX) / 2, getY(curPrice), curX, getY(curPrice)); 147 | // } 148 | if (lastX == curX) lastX = 0; //起点位置填充 149 | mLinePath!.moveTo(lastX, getY(lastPrice)); 150 | mLinePath!.cubicTo((lastX + curX) / 2, getY(lastPrice), (lastX + curX) / 2, 151 | getY(curPrice), curX, getY(curPrice)); 152 | 153 | //画阴影 154 | mLineFillShader ??= LinearGradient( 155 | begin: Alignment.topCenter, 156 | end: Alignment.bottomCenter, 157 | tileMode: TileMode.clamp, 158 | colors: [this.chartColors.lineFillColor, this.chartColors.lineFillInsideColor], 159 | ).createShader(Rect.fromLTRB( 160 | chartRect.left, chartRect.top, chartRect.right, chartRect.bottom)); 161 | mLineFillPaint..shader = mLineFillShader; 162 | 163 | mLineFillPath ??= Path(); 164 | 165 | mLineFillPath!.moveTo(lastX, chartRect.height + chartRect.top); 166 | mLineFillPath!.lineTo(lastX, getY(lastPrice)); 167 | mLineFillPath!.cubicTo((lastX + curX) / 2, getY(lastPrice), 168 | (lastX + curX) / 2, getY(curPrice), curX, getY(curPrice)); 169 | mLineFillPath!.lineTo(curX, chartRect.height + chartRect.top); 170 | mLineFillPath!.close(); 171 | 172 | canvas.drawPath(mLineFillPath!, mLineFillPaint); 173 | mLineFillPath!.reset(); 174 | 175 | canvas.drawPath(mLinePath!, 176 | mLinePaint..strokeWidth = (mLineStrokeWidth / scaleX).clamp(0.1, 1.0)); 177 | mLinePath!.reset(); 178 | } 179 | 180 | void drawMaLine(CandleEntity lastPoint, CandleEntity curPoint, Canvas canvas, 181 | double lastX, double curX) { 182 | for (int i = 0; i < (curPoint.maValueList?.length ?? 0); i++) { 183 | if (i == 3) { 184 | break; 185 | } 186 | if (lastPoint.maValueList?[i] != 0) { 187 | drawLine(lastPoint.maValueList?[i], curPoint.maValueList?[i], canvas, 188 | lastX, curX, this.chartColors.getMAColor(i)); 189 | } 190 | } 191 | } 192 | 193 | void drawBollLine(CandleEntity lastPoint, CandleEntity curPoint, 194 | Canvas canvas, double lastX, double curX) { 195 | if (lastPoint.up != 0) { 196 | drawLine(lastPoint.up, curPoint.up, canvas, lastX, curX, 197 | this.chartColors.ma10Color); 198 | } 199 | if (lastPoint.mb != 0) { 200 | drawLine(lastPoint.mb, curPoint.mb, canvas, lastX, curX, 201 | this.chartColors.ma5Color); 202 | } 203 | if (lastPoint.dn != 0) { 204 | drawLine(lastPoint.dn, curPoint.dn, canvas, lastX, curX, 205 | this.chartColors.ma30Color); 206 | } 207 | } 208 | 209 | void drawCandle(CandleEntity curPoint, Canvas canvas, double curX) { 210 | var high = getY(curPoint.high); 211 | var low = getY(curPoint.low); 212 | var open = getY(curPoint.open); 213 | var close = getY(curPoint.close); 214 | double r = mCandleWidth / 2; 215 | double lineR = mCandleLineWidth / 2; 216 | if (open >= close) { 217 | // 实体高度>= CandleLineWidth 218 | if (open - close < mCandleLineWidth) { 219 | open = close + mCandleLineWidth; 220 | } 221 | chartPaint.color = this.chartColors.upColor; 222 | canvas.drawRect( 223 | Rect.fromLTRB(curX - r, close, curX + r, open), chartPaint); 224 | canvas.drawRect( 225 | Rect.fromLTRB(curX - lineR, high, curX + lineR, low), chartPaint); 226 | } else if (close > open) { 227 | // 实体高度>= CandleLineWidth 228 | if (close - open < mCandleLineWidth) { 229 | open = close - mCandleLineWidth; 230 | } 231 | chartPaint.color = this.chartColors.dnColor; 232 | canvas.drawRect( 233 | Rect.fromLTRB(curX - r, open, curX + r, close), chartPaint); 234 | canvas.drawRect( 235 | Rect.fromLTRB(curX - lineR, high, curX + lineR, low), chartPaint); 236 | } 237 | } 238 | 239 | @override 240 | void drawVerticalText(canvas, textStyle, int gridRows) { 241 | double rowSpace = chartRect.height / gridRows; 242 | for (var i = 0; i <= gridRows; ++i) { 243 | double value = (gridRows - i) * rowSpace / scaleY + minValue; 244 | TextSpan span = TextSpan(text: "${format(value)}", style: textStyle); 245 | TextPainter tp = 246 | TextPainter(text: span, textDirection: TextDirection.ltr); 247 | tp.layout(); 248 | 249 | double offsetX; 250 | switch (verticalTextAlignment) { 251 | case VerticalTextAlignment.left: 252 | offsetX = 0; 253 | break; 254 | case VerticalTextAlignment.right: 255 | offsetX = chartRect.width - tp.width; 256 | break; 257 | } 258 | 259 | if (i == 0) { 260 | tp.paint(canvas, Offset(offsetX, topPadding)); 261 | } else { 262 | tp.paint( 263 | canvas, Offset(offsetX, rowSpace * i - tp.height + topPadding)); 264 | } 265 | } 266 | } 267 | 268 | @override 269 | void drawGrid(Canvas canvas, int gridRows, int gridColumns) { 270 | // final int gridRows = 4, gridColumns = 4; 271 | double rowSpace = chartRect.height / gridRows; 272 | for (int i = 0; i <= gridRows; i++) { 273 | canvas.drawLine(Offset(0, rowSpace * i + topPadding), 274 | Offset(chartRect.width, rowSpace * i + topPadding), gridPaint); 275 | } 276 | double columnSpace = chartRect.width / gridColumns; 277 | for (int i = 0; i <= columnSpace; i++) { 278 | canvas.drawLine(Offset(columnSpace * i, topPadding / 3), 279 | Offset(columnSpace * i, chartRect.bottom), gridPaint); 280 | } 281 | } 282 | 283 | @override 284 | double getY(double y) { 285 | //For TrendLine 286 | updateTrendLineData(); 287 | return (maxValue - y) * scaleY + _contentRect.top; 288 | } 289 | 290 | void updateTrendLineData() { 291 | trendLineMax = maxValue; 292 | trendLineScale = scaleY; 293 | trendLineContentRec = _contentRect.top; 294 | } 295 | } 296 | -------------------------------------------------------------------------------- /lib/renderer/secondary_renderer.dart: -------------------------------------------------------------------------------- 1 | import 'dart:ui'; 2 | 3 | import 'package:flutter/material.dart'; 4 | 5 | import '../entity/macd_entity.dart'; 6 | import '../k_chart_widget.dart' show SecondaryState; 7 | import 'base_chart_renderer.dart'; 8 | 9 | class SecondaryRenderer extends BaseChartRenderer { 10 | late double mMACDWidth; 11 | SecondaryState state; 12 | final ChartStyle chartStyle; 13 | final ChartColors chartColors; 14 | 15 | SecondaryRenderer( 16 | Rect mainRect, 17 | double maxValue, 18 | double minValue, 19 | double topPadding, 20 | this.state, 21 | int fixedLength, 22 | this.chartStyle, 23 | this.chartColors) 24 | : super( 25 | chartRect: mainRect, 26 | maxValue: maxValue, 27 | minValue: minValue, 28 | topPadding: topPadding, 29 | fixedLength: fixedLength, 30 | gridColor: chartColors.gridColor,) { 31 | mMACDWidth = this.chartStyle.macdWidth; 32 | } 33 | 34 | @override 35 | void drawChart(MACDEntity lastPoint, MACDEntity curPoint, double lastX, 36 | double curX, Size size, Canvas canvas) { 37 | switch (state) { 38 | case SecondaryState.MACD: 39 | drawMACD(curPoint, canvas, curX, lastPoint, lastX); 40 | break; 41 | case SecondaryState.KDJ: 42 | drawLine(lastPoint.k, curPoint.k, canvas, lastX, curX, 43 | this.chartColors.kColor); 44 | drawLine(lastPoint.d, curPoint.d, canvas, lastX, curX, 45 | this.chartColors.dColor); 46 | drawLine(lastPoint.j, curPoint.j, canvas, lastX, curX, 47 | this.chartColors.jColor); 48 | break; 49 | case SecondaryState.RSI: 50 | drawLine(lastPoint.rsi, curPoint.rsi, canvas, lastX, curX, 51 | this.chartColors.rsiColor); 52 | break; 53 | case SecondaryState.WR: 54 | drawLine(lastPoint.r, curPoint.r, canvas, lastX, curX, 55 | this.chartColors.rsiColor); 56 | break; 57 | case SecondaryState.CCI: 58 | drawLine(lastPoint.cci, curPoint.cci, canvas, lastX, curX, 59 | this.chartColors.rsiColor); 60 | break; 61 | default: 62 | break; 63 | } 64 | } 65 | 66 | void drawMACD(MACDEntity curPoint, Canvas canvas, double curX, 67 | MACDEntity lastPoint, double lastX) { 68 | final macd = curPoint.macd ?? 0; 69 | double macdY = getY(macd); 70 | double r = mMACDWidth / 2; 71 | double zeroy = getY(0); 72 | if (macd > 0) { 73 | canvas.drawRect(Rect.fromLTRB(curX - r, macdY, curX + r, zeroy), 74 | chartPaint..color = this.chartColors.upColor); 75 | } else { 76 | canvas.drawRect(Rect.fromLTRB(curX - r, zeroy, curX + r, macdY), 77 | chartPaint..color = this.chartColors.dnColor); 78 | } 79 | if (lastPoint.dif != 0) { 80 | drawLine(lastPoint.dif, curPoint.dif, canvas, lastX, curX, 81 | this.chartColors.difColor); 82 | } 83 | if (lastPoint.dea != 0) { 84 | drawLine(lastPoint.dea, curPoint.dea, canvas, lastX, curX, 85 | this.chartColors.deaColor); 86 | } 87 | } 88 | 89 | @override 90 | void drawText(Canvas canvas, MACDEntity data, double x) { 91 | List? children; 92 | switch (state) { 93 | case SecondaryState.MACD: 94 | children = [ 95 | TextSpan( 96 | text: "MACD(12,26,9) ", 97 | style: getTextStyle(this.chartColors.defaultTextColor)), 98 | if (data.macd != 0) 99 | TextSpan( 100 | text: "MACD:${format(data.macd)} ", 101 | style: getTextStyle(this.chartColors.macdColor)), 102 | if (data.dif != 0) 103 | TextSpan( 104 | text: "DIF:${format(data.dif)} ", 105 | style: getTextStyle(this.chartColors.difColor)), 106 | if (data.dea != 0) 107 | TextSpan( 108 | text: "DEA:${format(data.dea)} ", 109 | style: getTextStyle(this.chartColors.deaColor)), 110 | ]; 111 | break; 112 | case SecondaryState.KDJ: 113 | children = [ 114 | TextSpan( 115 | text: "KDJ(9,1,3) ", 116 | style: getTextStyle(this.chartColors.defaultTextColor)), 117 | if (data.macd != 0) 118 | TextSpan( 119 | text: "K:${format(data.k)} ", 120 | style: getTextStyle(this.chartColors.kColor)), 121 | if (data.dif != 0) 122 | TextSpan( 123 | text: "D:${format(data.d)} ", 124 | style: getTextStyle(this.chartColors.dColor)), 125 | if (data.dea != 0) 126 | TextSpan( 127 | text: "J:${format(data.j)} ", 128 | style: getTextStyle(this.chartColors.jColor)), 129 | ]; 130 | break; 131 | case SecondaryState.RSI: 132 | children = [ 133 | TextSpan( 134 | text: "RSI(14):${format(data.rsi)} ", 135 | style: getTextStyle(this.chartColors.rsiColor)), 136 | ]; 137 | break; 138 | case SecondaryState.WR: 139 | children = [ 140 | TextSpan( 141 | text: "WR(14):${format(data.r)} ", 142 | style: getTextStyle(this.chartColors.rsiColor)), 143 | ]; 144 | break; 145 | case SecondaryState.CCI: 146 | children = [ 147 | TextSpan( 148 | text: "CCI(14):${format(data.cci)} ", 149 | style: getTextStyle(this.chartColors.rsiColor)), 150 | ]; 151 | break; 152 | default: 153 | break; 154 | } 155 | TextPainter tp = TextPainter( 156 | text: TextSpan(children: children ?? []), 157 | textDirection: TextDirection.ltr); 158 | tp.layout(); 159 | tp.paint(canvas, Offset(x, chartRect.top - topPadding)); 160 | } 161 | 162 | @override 163 | void drawVerticalText(canvas, textStyle, int gridRows) { 164 | TextPainter maxTp = TextPainter( 165 | text: TextSpan(text: "${format(maxValue)}", style: textStyle), 166 | textDirection: TextDirection.ltr); 167 | maxTp.layout(); 168 | TextPainter minTp = TextPainter( 169 | text: TextSpan(text: "${format(minValue)}", style: textStyle), 170 | textDirection: TextDirection.ltr); 171 | minTp.layout(); 172 | 173 | maxTp.paint(canvas, 174 | Offset(chartRect.width - maxTp.width, chartRect.top - topPadding)); 175 | minTp.paint(canvas, 176 | Offset(chartRect.width - minTp.width, chartRect.bottom - minTp.height)); 177 | } 178 | 179 | @override 180 | void drawGrid(Canvas canvas, int gridRows, int gridColumns) { 181 | canvas.drawLine(Offset(0, chartRect.top), 182 | Offset(chartRect.width, chartRect.top), gridPaint); 183 | canvas.drawLine(Offset(0, chartRect.bottom), 184 | Offset(chartRect.width, chartRect.bottom), gridPaint); 185 | double columnSpace = chartRect.width / gridColumns; 186 | for (int i = 0; i <= columnSpace; i++) { 187 | //mSecondaryRect垂直线 188 | canvas.drawLine(Offset(columnSpace * i, chartRect.top - topPadding), 189 | Offset(columnSpace * i, chartRect.bottom), gridPaint); 190 | } 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /lib/renderer/vol_renderer.dart: -------------------------------------------------------------------------------- 1 | import 'dart:ui'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:k_chart/flutter_k_chart.dart'; 5 | 6 | class VolRenderer extends BaseChartRenderer { 7 | late double mVolWidth; 8 | final ChartStyle chartStyle; 9 | final ChartColors chartColors; 10 | 11 | VolRenderer(Rect mainRect, double maxValue, double minValue, 12 | double topPadding, int fixedLength, this.chartStyle, this.chartColors) 13 | : super( 14 | chartRect: mainRect, 15 | maxValue: maxValue, 16 | minValue: minValue, 17 | topPadding: topPadding, 18 | fixedLength: fixedLength, 19 | gridColor: chartColors.gridColor,) { 20 | mVolWidth = this.chartStyle.volWidth; 21 | } 22 | 23 | @override 24 | void drawChart(VolumeEntity lastPoint, VolumeEntity curPoint, double lastX, 25 | double curX, Size size, Canvas canvas) { 26 | double r = mVolWidth / 2; 27 | double top = getVolY(curPoint.vol); 28 | double bottom = chartRect.bottom; 29 | if (curPoint.vol != 0) { 30 | canvas.drawRect( 31 | Rect.fromLTRB(curX - r, top, curX + r, bottom), 32 | chartPaint 33 | ..color = curPoint.close > curPoint.open 34 | ? this.chartColors.upColor 35 | : this.chartColors.dnColor); 36 | } 37 | 38 | if (lastPoint.MA5Volume != 0) { 39 | drawLine(lastPoint.MA5Volume, curPoint.MA5Volume, canvas, lastX, curX, 40 | this.chartColors.ma5Color); 41 | } 42 | 43 | if (lastPoint.MA10Volume != 0) { 44 | drawLine(lastPoint.MA10Volume, curPoint.MA10Volume, canvas, lastX, curX, 45 | this.chartColors.ma10Color); 46 | } 47 | } 48 | 49 | double getVolY(double value) => 50 | (maxValue - value) * (chartRect.height / maxValue) + chartRect.top; 51 | 52 | @override 53 | void drawText(Canvas canvas, VolumeEntity data, double x) { 54 | TextSpan span = TextSpan( 55 | children: [ 56 | TextSpan( 57 | text: "VOL:${NumberUtil.format(data.vol)} ", 58 | style: getTextStyle(this.chartColors.volColor)), 59 | if (data.MA5Volume.notNullOrZero) 60 | TextSpan( 61 | text: "MA5:${NumberUtil.format(data.MA5Volume!)} ", 62 | style: getTextStyle(this.chartColors.ma5Color)), 63 | if (data.MA10Volume.notNullOrZero) 64 | TextSpan( 65 | text: "MA10:${NumberUtil.format(data.MA10Volume!)} ", 66 | style: getTextStyle(this.chartColors.ma10Color)), 67 | ], 68 | ); 69 | TextPainter tp = TextPainter(text: span, textDirection: TextDirection.ltr); 70 | tp.layout(); 71 | tp.paint(canvas, Offset(x, chartRect.top - topPadding)); 72 | } 73 | 74 | @override 75 | void drawVerticalText(canvas, textStyle, int gridRows) { 76 | TextSpan span = 77 | TextSpan(text: "${NumberUtil.format(maxValue)}", style: textStyle); 78 | TextPainter tp = TextPainter(text: span, textDirection: TextDirection.ltr); 79 | tp.layout(); 80 | tp.paint( 81 | canvas, Offset(chartRect.width - tp.width, chartRect.top - topPadding)); 82 | } 83 | 84 | @override 85 | void drawGrid(Canvas canvas, int gridRows, int gridColumns) { 86 | canvas.drawLine(Offset(0, chartRect.bottom), 87 | Offset(chartRect.width, chartRect.bottom), gridPaint); 88 | double columnSpace = chartRect.width / gridColumns; 89 | for (int i = 0; i <= columnSpace; i++) { 90 | //vol垂直线 91 | canvas.drawLine(Offset(columnSpace * i, chartRect.top - topPadding), 92 | Offset(columnSpace * i, chartRect.bottom), gridPaint); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /lib/utils/data_util.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import '../entity/index.dart'; 4 | 5 | class DataUtil { 6 | static calculate(List dataList, 7 | [List maDayList = const [5, 10, 20], int n = 20, k = 2]) { 8 | calcMA(dataList, maDayList); 9 | calcBOLL(dataList, n, k); 10 | calcVolumeMA(dataList); 11 | calcKDJ(dataList); 12 | calcMACD(dataList); 13 | calcRSI(dataList); 14 | calcWR(dataList); 15 | calcCCI(dataList); 16 | } 17 | 18 | static calcMA(List dataList, List maDayList) { 19 | List ma = List.filled(maDayList.length, 0); 20 | 21 | if (dataList.isNotEmpty) { 22 | for (int i = 0; i < dataList.length; i++) { 23 | KLineEntity entity = dataList[i]; 24 | final closePrice = entity.close; 25 | entity.maValueList = List.filled(maDayList.length, 0); 26 | 27 | for (int j = 0; j < maDayList.length; j++) { 28 | ma[j] += closePrice; 29 | if (i == maDayList[j] - 1) { 30 | entity.maValueList?[j] = ma[j] / maDayList[j]; 31 | } else if (i >= maDayList[j]) { 32 | ma[j] -= dataList[i - maDayList[j]].close; 33 | entity.maValueList?[j] = ma[j] / maDayList[j]; 34 | } else { 35 | entity.maValueList?[j] = 0; 36 | } 37 | } 38 | } 39 | } 40 | } 41 | 42 | static void calcBOLL(List dataList, int n, int k) { 43 | _calcBOLLMA(n, dataList); 44 | for (int i = 0; i < dataList.length; i++) { 45 | KLineEntity entity = dataList[i]; 46 | if (i >= n) { 47 | double md = 0; 48 | for (int j = i - n + 1; j <= i; j++) { 49 | double c = dataList[j].close; 50 | double m = entity.BOLLMA!; 51 | double value = c - m; 52 | md += value * value; 53 | } 54 | md = md / (n - 1); 55 | md = sqrt(md); 56 | entity.mb = entity.BOLLMA!; 57 | entity.up = entity.mb! + k * md; 58 | entity.dn = entity.mb! - k * md; 59 | } 60 | } 61 | } 62 | 63 | static void _calcBOLLMA(int day, List dataList) { 64 | double ma = 0; 65 | for (int i = 0; i < dataList.length; i++) { 66 | KLineEntity entity = dataList[i]; 67 | ma += entity.close; 68 | if (i == day - 1) { 69 | entity.BOLLMA = ma / day; 70 | } else if (i >= day) { 71 | ma -= dataList[i - day].close; 72 | entity.BOLLMA = ma / day; 73 | } else { 74 | entity.BOLLMA = null; 75 | } 76 | } 77 | } 78 | 79 | static void calcMACD(List dataList) { 80 | double ema12 = 0; 81 | double ema26 = 0; 82 | double dif = 0; 83 | double dea = 0; 84 | double macd = 0; 85 | 86 | for (int i = 0; i < dataList.length; i++) { 87 | KLineEntity entity = dataList[i]; 88 | final closePrice = entity.close; 89 | if (i == 0) { 90 | ema12 = closePrice; 91 | ema26 = closePrice; 92 | } else { 93 | // EMA(12) = 前一日EMA(12) X 11/13 + 今日收盘价 X 2/13 94 | ema12 = ema12 * 11 / 13 + closePrice * 2 / 13; 95 | // EMA(26) = 前一日EMA(26) X 25/27 + 今日收盘价 X 2/27 96 | ema26 = ema26 * 25 / 27 + closePrice * 2 / 27; 97 | } 98 | // DIF = EMA(12) - EMA(26) 。 99 | // 今日DEA = (前一日DEA X 8/10 + 今日DIF X 2/10) 100 | // 用(DIF-DEA)*2即为MACD柱状图。 101 | dif = ema12 - ema26; 102 | dea = dea * 8 / 10 + dif * 2 / 10; 103 | macd = (dif - dea) * 2; 104 | entity.dif = dif; 105 | entity.dea = dea; 106 | entity.macd = macd; 107 | } 108 | } 109 | 110 | static void calcVolumeMA(List dataList) { 111 | double volumeMa5 = 0; 112 | double volumeMa10 = 0; 113 | 114 | for (int i = 0; i < dataList.length; i++) { 115 | KLineEntity entry = dataList[i]; 116 | 117 | volumeMa5 += entry.vol; 118 | volumeMa10 += entry.vol; 119 | 120 | if (i == 4) { 121 | entry.MA5Volume = (volumeMa5 / 5); 122 | } else if (i > 4) { 123 | volumeMa5 -= dataList[i - 5].vol; 124 | entry.MA5Volume = volumeMa5 / 5; 125 | } else { 126 | entry.MA5Volume = 0; 127 | } 128 | 129 | if (i == 9) { 130 | entry.MA10Volume = volumeMa10 / 10; 131 | } else if (i > 9) { 132 | volumeMa10 -= dataList[i - 10].vol; 133 | entry.MA10Volume = volumeMa10 / 10; 134 | } else { 135 | entry.MA10Volume = 0; 136 | } 137 | } 138 | } 139 | 140 | static void calcRSI(List dataList) { 141 | double? rsi; 142 | double rsiABSEma = 0; 143 | double rsiMaxEma = 0; 144 | for (int i = 0; i < dataList.length; i++) { 145 | KLineEntity entity = dataList[i]; 146 | final double closePrice = entity.close; 147 | if (i == 0) { 148 | rsi = 0; 149 | rsiABSEma = 0; 150 | rsiMaxEma = 0; 151 | } else { 152 | double rMax = max(0, closePrice - dataList[i - 1].close.toDouble()); 153 | double rAbs = (closePrice - dataList[i - 1].close.toDouble()).abs(); 154 | 155 | rsiMaxEma = (rMax + (14 - 1) * rsiMaxEma) / 14; 156 | rsiABSEma = (rAbs + (14 - 1) * rsiABSEma) / 14; 157 | rsi = (rsiMaxEma / rsiABSEma) * 100; 158 | } 159 | if (i < 13) rsi = null; 160 | if (rsi != null && rsi.isNaN) rsi = null; 161 | entity.rsi = rsi; 162 | } 163 | } 164 | 165 | static void calcKDJ(List dataList) { 166 | var preK = 50.0; 167 | var preD = 50.0; 168 | final tmp = dataList.first; 169 | tmp.k = preK; 170 | tmp.d = preD; 171 | tmp.j = 50.0; 172 | for (int i = 1; i < dataList.length; i++) { 173 | final entity = dataList[i]; 174 | final n = max(0, i - 8); 175 | var low = entity.low; 176 | var high = entity.high; 177 | for (int j = n; j < i; j++) { 178 | final t = dataList[j]; 179 | if (t.low < low) { 180 | low = t.low; 181 | } 182 | if (t.high > high) { 183 | high = t.high; 184 | } 185 | } 186 | final cur = entity.close; 187 | var rsv = (cur - low) * 100.0 / (high - low); 188 | rsv = rsv.isNaN ? 0 : rsv; 189 | final k = (2 * preK + rsv) / 3.0; 190 | final d = (2 * preD + k) / 3.0; 191 | final j = 3 * k - 2 * d; 192 | preK = k; 193 | preD = d; 194 | entity.k = k; 195 | entity.d = d; 196 | entity.j = j; 197 | } 198 | } 199 | 200 | static void calcWR(List dataList) { 201 | double r; 202 | for (int i = 0; i < dataList.length; i++) { 203 | KLineEntity entity = dataList[i]; 204 | int startIndex = i - 14; 205 | if (startIndex < 0) { 206 | startIndex = 0; 207 | } 208 | double max14 = double.minPositive; 209 | double min14 = double.maxFinite; 210 | for (int index = startIndex; index <= i; index++) { 211 | max14 = max(max14, dataList[index].high); 212 | min14 = min(min14, dataList[index].low); 213 | } 214 | if (i < 13) { 215 | entity.r = -10; 216 | } else { 217 | r = -100 * (max14 - dataList[i].close) / (max14 - min14); 218 | if (r.isNaN) { 219 | entity.r = null; 220 | } else { 221 | entity.r = r; 222 | } 223 | } 224 | } 225 | } 226 | 227 | static void calcCCI(List dataList) { 228 | final size = dataList.length; 229 | final count = 14; 230 | for (int i = 0; i < size; i++) { 231 | final kline = dataList[i]; 232 | final tp = (kline.high + kline.low + kline.close) / 3; 233 | final start = max(0, i - count + 1); 234 | var amount = 0.0; 235 | var len = 0; 236 | for (int n = start; n <= i; n++) { 237 | amount += (dataList[n].high + dataList[n].low + dataList[n].close) / 3; 238 | len++; 239 | } 240 | final ma = amount / len; 241 | amount = 0.0; 242 | for (int n = start; n <= i; n++) { 243 | amount += 244 | (ma - (dataList[n].high + dataList[n].low + dataList[n].close) / 3) 245 | .abs(); 246 | } 247 | final md = amount / len; 248 | kline.cci = ((tp - ma) / 0.015 / md); 249 | if (kline.cci!.isNaN) { 250 | kline.cci = 0.0; 251 | } 252 | } 253 | } 254 | } 255 | -------------------------------------------------------------------------------- /lib/utils/date_format_util.dart: -------------------------------------------------------------------------------- 1 | /// Outputs year as four digits 2 | /// 3 | /// Example: 4 | /// formatDate(DateTime(1989), [yyyy]); 5 | /// // => 1989 6 | const String yyyy = 'yyyy'; 7 | 8 | /// Outputs year as two digits 9 | /// 10 | /// Example: 11 | /// formatDate(DateTime(1989), [yy]); 12 | /// // => 89 13 | const String yy = 'yy'; 14 | 15 | /// Outputs month as two digits 16 | /// 17 | /// Example: 18 | /// formatDate(DateTime(1989, 11), [mm]); 19 | /// // => 11 20 | /// formatDate(DateTime(1989, 5), [mm]); 21 | /// // => 05 22 | const String mm = 'mm'; 23 | 24 | /// Outputs month compactly 25 | /// 26 | /// Example: 27 | /// formatDate(DateTime(1989, 11), [mm]); 28 | /// // => 11 29 | /// formatDate(DateTime(1989, 5), [m]); 30 | /// // => 5 31 | const String m = 'm'; 32 | 33 | /// Outputs month as long name 34 | /// 35 | /// Example: 36 | /// formatDate(DateTime(1989, 2), [MM]); 37 | /// // => february 38 | const String MM = 'MM'; 39 | 40 | /// Outputs month as short name 41 | /// 42 | /// Example: 43 | /// formatDate(DateTime(1989, 2), [M]); 44 | /// // => feb 45 | const String M = 'M'; 46 | 47 | /// Outputs day as two digits 48 | /// 49 | /// Example: 50 | /// formatDate(DateTime(1989, 2, 21), [dd]); 51 | /// // => 21 52 | /// formatDate(DateTime(1989, 2, 5), [dd]); 53 | /// // => 05 54 | const String dd = 'dd'; 55 | 56 | /// Outputs day compactly 57 | /// 58 | /// Example: 59 | /// formatDate(DateTime(1989, 2, 21), [d]); 60 | /// // => 21 61 | /// formatDate(DateTime(1989, 2, 5), [d]); 62 | /// // => 5 63 | const String d = 'd'; 64 | 65 | /// Outputs week in month 66 | /// 67 | /// Example: 68 | /// formatDate(DateTime(1989, 2, 21), [w]); 69 | /// // => 4 70 | const String w = 'w'; 71 | 72 | /// Outputs week in year as two digits 73 | /// 74 | /// Example: 75 | /// formatDate(DateTime(1989, 12, 31), [W]); 76 | /// // => 53 77 | /// formatDate(DateTime(1989, 2, 21), [W]); 78 | /// // => 08 79 | const String WW = 'WW'; 80 | 81 | /// Outputs week in year compactly 82 | /// 83 | /// Example: 84 | /// formatDate(DateTime(1989, 2, 21), [W]); 85 | /// // => 8 86 | const String W = 'W'; 87 | 88 | /// Outputs week day as long name 89 | /// 90 | /// Example: 91 | /// formatDate(DateTime(2018, 1, 14), [DD]); 92 | /// // => sunday 93 | const String DD = 'DD'; 94 | 95 | /// Outputs week day as long name 96 | /// 97 | /// Example: 98 | /// formatDate(DateTime(2018, 1, 14), [D]); 99 | /// // => sun 100 | const String D = 'D'; 101 | 102 | /// Outputs hour (0 - 11) as two digits 103 | /// 104 | /// Example: 105 | /// formatDate(DateTime(1989, 02, 1, 15), [hh]); 106 | /// // => 03 107 | const String hh = 'hh'; 108 | 109 | /// Outputs hour (0 - 11) compactly 110 | /// 111 | /// Example: 112 | /// formatDate(DateTime(1989, 02, 1, 15), [h]); 113 | /// // => 3 114 | const String h = 'h'; 115 | 116 | /// Outputs hour (0 to 23) as two digits 117 | /// 118 | /// Example: 119 | /// formatDate(DateTime(1989, 02, 1, 15), [HH]); 120 | /// // => 15 121 | const String HH = 'HH'; 122 | 123 | /// Outputs hour (0 to 23) compactly 124 | /// 125 | /// Example: 126 | /// formatDate(DateTime(1989, 02, 1, 5), [H]); 127 | /// // => 5 128 | const String H = 'H'; 129 | 130 | /// Outputs minute as two digits 131 | /// 132 | /// Example: 133 | /// formatDate(DateTime(1989, 02, 1, 15, 40), [nn]); 134 | /// // => 40 135 | /// formatDate(DateTime(1989, 02, 1, 15, 4), [nn]); 136 | /// // => 04 137 | const String nn = 'nn'; 138 | 139 | /// Outputs minute compactly 140 | /// 141 | /// Example: 142 | /// formatDate(DateTime(1989, 02, 1, 15, 4), [n]); 143 | /// // => 4 144 | const String n = 'n'; 145 | 146 | /// Outputs second as two digits 147 | /// 148 | /// Example: 149 | /// formatDate(DateTime(1989, 02, 1, 15, 40, 10), [ss]); 150 | /// // => 10 151 | /// formatDate(DateTime(1989, 02, 1, 15, 40, 5), [ss]); 152 | /// // => 05 153 | const String ss = 'ss'; 154 | 155 | /// Outputs second compactly 156 | /// 157 | /// Example: 158 | /// formatDate(DateTime(1989, 02, 1, 15, 40, 5), [s]); 159 | /// // => 5 160 | const String s = 's'; 161 | 162 | /// Outputs millisecond as three digits 163 | /// 164 | /// Example: 165 | /// formatDate(DateTime(1989, 02, 1, 15, 40, 10, 999), [SSS]); 166 | /// // => 999 167 | /// formatDate(DateTime(1989, 02, 1, 15, 40, 10, 99), [SS]); 168 | /// // => 099 169 | /// formatDate(DateTime(1989, 02, 1, 15, 40, 10, 0), [SS]); 170 | /// // => 009 171 | const String SSS = 'SSS'; 172 | 173 | /// Outputs millisecond compactly 174 | /// 175 | /// Example: 176 | /// formatDate(DateTime(1989, 02, 1, 15, 40, 10, 999), [SSS]); 177 | /// // => 999 178 | /// formatDate(DateTime(1989, 02, 1, 15, 40, 10, 99), [SS]); 179 | /// // => 99 180 | /// formatDate(DateTime(1989, 02, 1, 15, 40, 10, 9), [SS]); 181 | /// // => 9 182 | const String S = 'S'; 183 | 184 | /// Outputs microsecond as three digits 185 | /// 186 | /// Example: 187 | /// formatDate(DateTime(1989, 02, 1, 15, 40, 10, 0, 999), [uuu]); 188 | /// // => 999 189 | /// formatDate(DateTime(1989, 02, 1, 15, 40, 10, 0, 99), [uuu]); 190 | /// // => 099 191 | /// formatDate(DateTime(1989, 02, 1, 15, 40, 10, 0, 9), [uuu]); 192 | /// // => 009 193 | const String uuu = 'uuu'; 194 | 195 | /// Outputs millisecond compactly 196 | /// 197 | /// Example: 198 | /// formatDate(DateTime(1989, 02, 1, 15, 40, 10, 0, 999), [u]); 199 | /// // => 999 200 | /// formatDate(DateTime(1989, 02, 1, 15, 40, 10, 0, 99), [u]); 201 | /// // => 99 202 | /// formatDate(DateTime(1989, 02, 1, 15, 40, 10, 0, 9), [u]); 203 | /// // => 9 204 | const String u = 'u'; 205 | 206 | /// Outputs if hour is AM or PM 207 | /// 208 | /// Example: 209 | /// print(formatDate(DateTime(1989, 02, 1, 5), [am])); 210 | /// // => AM 211 | /// print(formatDate(DateTime(1989, 02, 1, 15), [am])); 212 | /// // => PM 213 | const String am = 'am'; 214 | 215 | /// Outputs timezone as time offset 216 | /// 217 | /// Example: 218 | /// 219 | const String z = 'z'; 220 | const String Z = 'Z'; 221 | 222 | String dateFormat(DateTime date, List formats) { 223 | final sb = StringBuffer(); 224 | 225 | for (String format in formats) { 226 | if (format == yyyy) { 227 | sb.write(_digits(date.year, 4)); 228 | } else if (format == yy) { 229 | sb.write(_digits(date.year % 100, 2)); 230 | } else if (format == mm) { 231 | sb.write(_digits(date.month, 2)); 232 | } else if (format == m) { 233 | sb.write(date.month); 234 | } else if (format == MM) { 235 | sb.write(monthLong[date.month - 1]); 236 | } else if (format == M) { 237 | sb.write(monthShort[date.month - 1]); 238 | } else if (format == dd) { 239 | sb.write(_digits(date.day, 2)); 240 | } else if (format == d) { 241 | sb.write(date.day); 242 | } else if (format == w) { 243 | sb.write((date.day + 7) ~/ 7); 244 | } else if (format == W) { 245 | sb.write((dayInYear(date) + 7) ~/ 7); 246 | } else if (format == WW) { 247 | sb.write(_digits((dayInYear(date) + 7) ~/ 7, 2)); 248 | } else if (format == DD) { 249 | sb.write(dayLong[date.weekday - 1]); 250 | } else if (format == D) { 251 | sb.write(dayShort[date.weekday - 1]); 252 | } else if (format == HH) { 253 | sb.write(_digits(date.hour, 2)); 254 | } else if (format == H) { 255 | sb.write(date.hour); 256 | } else if (format == hh) { 257 | int hour = date.hour % 12; 258 | if (hour == 0) hour = 12; 259 | sb.write(_digits(hour, 2)); 260 | } else if (format == h) { 261 | int hour = date.hour % 12; 262 | if (hour == 0) hour = 12; 263 | sb.write(hour); 264 | } else if (format == am) { 265 | sb.write(date.hour < 12 ? 'AM' : 'PM'); 266 | } else if (format == nn) { 267 | sb.write(_digits(date.minute, 2)); 268 | } else if (format == n) { 269 | sb.write(date.minute); 270 | } else if (format == ss) { 271 | sb.write(_digits(date.second, 2)); 272 | } else if (format == s) { 273 | sb.write(date.second); 274 | } else if (format == SSS) { 275 | sb.write(_digits(date.millisecond, 3)); 276 | } else if (format == S) { 277 | sb.write(date.second); 278 | } else if (format == uuu) { 279 | sb.write(_digits(date.microsecond, 2)); 280 | } else if (format == u) { 281 | sb.write(date.microsecond); 282 | } else if (format == z) { 283 | if (date.timeZoneOffset.inMinutes == 0) { 284 | sb.write('Z'); 285 | } else { 286 | if (date.timeZoneOffset.isNegative) { 287 | sb.write('-'); 288 | sb.write(_digits((-date.timeZoneOffset.inHours) % 24, 2)); 289 | sb.write(_digits((-date.timeZoneOffset.inMinutes) % 60, 2)); 290 | } else { 291 | sb.write('+'); 292 | sb.write(_digits(date.timeZoneOffset.inHours % 24, 2)); 293 | sb.write(_digits(date.timeZoneOffset.inMinutes % 60, 2)); 294 | } 295 | } 296 | } else if (format == Z) { 297 | sb.write(date.timeZoneName); 298 | } else { 299 | sb.write(format); 300 | } 301 | } 302 | 303 | return sb.toString(); 304 | } 305 | 306 | String _digits(int value, int length) { 307 | String ret = '$value'; 308 | if (ret.length < length) { 309 | ret = '0' * (length - ret.length) + ret; 310 | } 311 | return ret; 312 | } 313 | 314 | const List monthShort = const [ 315 | 'Jan', 316 | 'Feb', 317 | 'Mar', 318 | 'Apr', 319 | 'May', 320 | 'Jun', 321 | 'Jul', 322 | 'Aug', 323 | 'Sep', 324 | 'Oct', 325 | 'Nov', 326 | 'Dec' 327 | ]; 328 | 329 | const List monthLong = const [ 330 | 'January', 331 | 'February', 332 | 'March', 333 | 'April', 334 | 'May', 335 | 'June', 336 | 'July', 337 | 'August', 338 | 'September', 339 | 'October', 340 | 'November', 341 | 'December' 342 | ]; 343 | 344 | const List dayShort = const [ 345 | 'Mon', 346 | 'Tue', 347 | 'Wed', 348 | 'Thur', 349 | 'Fri', 350 | 'Sat', 351 | 'Sun' 352 | ]; 353 | 354 | const List dayLong = const [ 355 | 'Monday', 356 | 'Tuesday', 357 | 'Wednesday', 358 | 'Thursday', 359 | 'Friday', 360 | 'Saturday', 361 | 'Sunday' 362 | ]; 363 | 364 | int dayInYear(DateTime date) => 365 | date.difference(DateTime(date.year, 1, 1)).inDays; -------------------------------------------------------------------------------- /lib/utils/index.dart: -------------------------------------------------------------------------------- 1 | export 'data_util.dart'; 2 | export 'date_format_util.dart'; 3 | export 'number_util.dart'; -------------------------------------------------------------------------------- /lib/utils/number_util.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | class NumberUtil { 4 | static String format(double n) { 5 | if (n >= 1000000000) { 6 | n /= 1000000000; 7 | return "${n.toStringAsFixed(2)}B"; 8 | } else if (n >= 1000000) { 9 | n /= 1000000; 10 | return "${n.toStringAsFixed(2)}M"; 11 | } else if (n >= 10000) { 12 | n /= 1000; 13 | return "${n.toStringAsFixed(2)}K"; 14 | } else { 15 | return n.toStringAsFixed(4); 16 | } 17 | } 18 | 19 | static int getDecimalLength(double b) { 20 | String s = b.toString(); 21 | int dotIndex = s.indexOf("."); 22 | if (dotIndex < 0) { 23 | return 0; 24 | } else { 25 | return s.length - dotIndex - 1; 26 | } 27 | } 28 | 29 | static int getMaxDecimalLength(double a, double b, double c, double d) { 30 | int result = max(getDecimalLength(a), getDecimalLength(b)); 31 | result = max(result, getDecimalLength(c)); 32 | result = max(result, getDecimalLength(d)); 33 | return result; 34 | } 35 | 36 | static bool checkNotNullOrZero(double? a) { 37 | if (a == null || a == 0) { 38 | return false; 39 | } else if (a.abs().toStringAsFixed(4) == "0.0000") { 40 | return false; 41 | } else { 42 | return true; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: k_chart 2 | description: A Flutter K Chart. 3 | version: 0.7.1 4 | homepage: https://github.com/mafanwei/k_chart 5 | 6 | environment: 7 | sdk: ">=2.12.0 <3.0.0" 8 | 9 | dependencies: 10 | flutter: 11 | sdk: flutter 12 | 13 | dev_dependencies: 14 | flutter_test: 15 | sdk: flutter 16 | 17 | flutter: 18 | --------------------------------------------------------------------------------