├── .gitignore ├── .idea ├── encodings.xml ├── flutter_chart.iml ├── inspectionProfiles │ └── Project_Default.xml ├── libraries │ ├── Dart_Packages.xml │ ├── Dart_SDK.xml │ └── Flutter_Plugins.xml ├── misc.xml ├── modules.xml ├── vcs.xml └── workspace.xml ├── .metadata ├── CHANGELOG.md ├── LICENSE ├── README.md ├── draggable_fixed_bar_chart.gif ├── draggable_fixed_line_chart.gif ├── draggable_line_chart.gif ├── example ├── .gitignore ├── .metadata ├── README.md ├── 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 ├── flutter_android.sksl.json ├── 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 │ ├── draggable_bar_chart.dart │ ├── draggable_chart_page.dart │ ├── draggable_line_chart.dart │ ├── example_page.dart │ ├── fixed_draggable_bar_chart.dart │ ├── fixed_draggable_line_chart.dart │ ├── main.dart │ └── style.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.lock ├── 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 ├── flutter_chart.iml ├── lib ├── chart │ ├── canvas │ │ ├── axis_canvas_impl.dart │ │ ├── base_canvas.dart │ │ ├── base_chart_canvas.dart │ │ ├── chart_canvas_impl.dart │ │ ├── line_painter.dart │ │ └── point_painter.dart │ ├── chart │ │ ├── bar_chart.dart │ │ ├── bar_popup_canvas.dart │ │ ├── base_chart.dart │ │ ├── line_chart.dart │ │ └── line_popup_canvas.dart │ ├── chart_bean.dart │ ├── chart_pie_bean.dart │ ├── common │ │ ├── axis_delegate.dart │ │ ├── base_layout_config.dart │ │ ├── base_text_element.dart │ │ ├── chart_gesture_view.dart │ │ ├── find.dart │ │ ├── gesture_delegate.dart │ │ ├── popup_spec.dart │ │ ├── style.dart │ │ └── text_element.dart │ ├── impl │ │ ├── bar │ │ │ ├── bar_canvas_impl.dart │ │ │ ├── bar_layout_impl.dart │ │ │ ├── fixed_bar_canvas_impl.dart │ │ │ └── fixed_bar_layout_impl.dart │ │ └── line │ │ │ ├── fixed_line_canvas_impl.dart │ │ │ ├── fixed_line_layout_impl.dart │ │ │ ├── line_canvas_impl.dart │ │ │ └── line_layout_impl.dart │ ├── model │ │ ├── chart_data_bar.dart │ │ └── chart_data_model.dart │ ├── painter │ │ ├── base_painter.dart │ │ ├── chart_bar_painter.dart │ │ ├── chart_line_painter.dart │ │ └── chart_pie_painter.dart │ └── view │ │ ├── chart_bar.dart │ │ ├── chart_line.dart │ │ └── chart_pie.dart └── flutter_chart.dart ├── pubspec.lock ├── pubspec.yaml ├── test └── flutter_chart_test.dart ├── ui_chart_all.gif ├── ui_chart_bar.gif ├── ui_chart_curve.gif └── ui_chart_line.gif /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .dart_tool/ 3 | 4 | .packages 5 | .pub/ 6 | 7 | build/ 8 | ios/.generated/ 9 | ios/Flutter/Generated.xcconfig 10 | ios/Runner/GeneratedPluginRegistrant.* 11 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/flutter_chart.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | -------------------------------------------------------------------------------- /.idea/libraries/Dart_SDK.xml: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /.idea/libraries/Flutter_Plugins.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.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: 8661d8aecd626f7f57ccbcb735553edc05a2e713 8 | channel: stable 9 | 10 | project_type: package 11 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.2.0 - 2022/06/26 2 | 3 | * Line、Bar 支持拖拽模式,绘制触摸悬浮框. 4 | 5 | ## 0.1.6 - 2022/05/19 6 | 7 | * 迁移至 Sound Null Safety And Support Flutter 3 . 8 | 9 | ## 0.1.5 - 2019/7/11 10 | 11 | * 添加了对图表的触摸手势的支持,另外,柱状图现在支持绘制圆角 12 | 13 | ## 0.1.4 - 2019/7/9 14 | 15 | * 曲线,折线 添加阴影绘制 16 | 17 | ## 0.1.3 - 2019/5/16 18 | 19 | * 优化动画 20 | 21 | ## 0.1.2 - 2019/4/24 22 | 23 | * 添加示例代码 24 | 25 | ## 0.1.0 - 2019/4/22 26 | 27 | * 修改版本 28 | 29 | ## 0.0.1 - 2019/4/22 30 | 31 | * 贝塞尔曲线,柱状图 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2019, 吃点儿啥 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Flutter绘制图表,支持 android 、ios、web、macos、windows、linux . 2 | 3 | 绘制曲线 ,折线,柱状,饼图,包含动画效果,支持触摸、拖拽。 4 | 5 | # 怎么使用? 6 | 7 | - 添加依赖 flutter_chart: ^0.2.0 8 | 9 | ## 我的博客 10 | 11 | - [CSDN](https://blog.csdn.net/sxt_zls) 12 | - [GitHub](https://github.com/good-good-study/flutter_chart) 13 | 14 | # UI示例 15 | 16 | # 曲线图,悬浮框 17 | 18 | ![image](https://github.com/good-good-study/flutter_chart/blob/master/draggable_line_chart.gif) 19 | 20 | # 曲线图,拖拽、悬浮框 21 | 22 | ![image](https://github.com/good-good-study/flutter_chart/blob/master/draggable_fixed_line_chart.gif) 23 | 24 | # 睡眠图谱,拖拽、悬浮框 25 | 26 | ![image](https://github.com/good-good-study/flutter_chart/blob/master/draggable_fixed_bar_chart.gif) 27 | 28 | # 曲线图 29 | 30 | ![image](https://github.com/good-good-study/flutter_chart/blob/master/ui_chart_curve.gif) 31 | 32 | # 柱状图 33 | 34 | ![image](https://github.com/good-good-study/flutter_chart/blob/master/ui_chart_bar.gif) 35 | 36 | # 折线图 37 | 38 | ![image](https://github.com/good-good-study/flutter_chart/blob/master/ui_chart_line.gif) 39 | -------------------------------------------------------------------------------- /draggable_fixed_bar_chart.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/draggable_fixed_bar_chart.gif -------------------------------------------------------------------------------- /draggable_fixed_line_chart.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/draggable_fixed_line_chart.gif -------------------------------------------------------------------------------- /draggable_line_chart.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/draggable_line_chart.gif -------------------------------------------------------------------------------- /example/.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/.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: ee4e09cce01d6f2d7f4baebd247fde02e5008851 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: ee4e09cce01d6f2d7f4baebd247fde02e5008851 17 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 18 | - platform: android 19 | create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 20 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 21 | - platform: ios 22 | create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 23 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 24 | - platform: linux 25 | create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 26 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 27 | - platform: macos 28 | create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 29 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 30 | - platform: web 31 | create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 32 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 33 | - platform: windows 34 | create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 35 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 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 | # Flutter绘制图表 2 | 3 | 绘制曲线和柱状图,包含动画效果 4 | 5 | # 怎么使用? 6 | 7 | - 添加依赖 8 | flutter_chart: ^0.1.5 9 | 10 | ## 我的博客 11 | 12 | - [CSDN](https://blog.csdn.net/sxt_zls) 13 | -------------------------------------------------------------------------------- /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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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 | #Fri Jun 23 08:50:38 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip 7 | -------------------------------------------------------------------------------- /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/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 | 9.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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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 | 49 | 50 | -------------------------------------------------------------------------------- /example/ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /example/lib/draggable_chart_page.dart: -------------------------------------------------------------------------------- 1 | import 'package:example/draggable_line_chart.dart'; 2 | import 'package:flutter/cupertino.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | import 'draggable_bar_chart.dart'; 6 | import 'fixed_draggable_bar_chart.dart'; 7 | import 'fixed_draggable_line_chart.dart'; 8 | 9 | class DraggableChartPage extends StatelessWidget { 10 | const DraggableChartPage({Key? key}) : super(key: key); 11 | 12 | @override 13 | Widget build(BuildContext context) { 14 | return CupertinoPageScaffold( 15 | navigationBar: const CupertinoNavigationBar( 16 | previousPageTitle: '返回', 17 | middle: Text( 18 | 'Charts', 19 | style: TextStyle(fontSize: 17, color: Colors.black), 20 | ), 21 | ), 22 | child: SingleChildScrollView( 23 | padding: const EdgeInsets.symmetric(vertical: 64), 24 | child: Material( 25 | child: Column( 26 | crossAxisAlignment: CrossAxisAlignment.start, 27 | children: [ 28 | SizedBox(height: 24), 29 | 30 | /// Line Chart 31 | _title('Line Chart'), 32 | DraggableLineChart(), 33 | 34 | SizedBox(height: 8), 35 | 36 | /// Fixed Line Chart 37 | _title('Fixed Line Chart'), 38 | FixedDraggableLineChart(), 39 | 40 | SizedBox(height: 8), 41 | 42 | /// bar Chart 43 | _title('Bar Chart'), 44 | DraggableBarChart(), 45 | 46 | /// bar Chart 47 | _title('Fixed Bar Chart'), 48 | FixedDraggableBarChart(), 49 | ], 50 | ), 51 | ), 52 | ), 53 | ); 54 | } 55 | 56 | Padding _title(String label) { 57 | return Padding( 58 | padding: EdgeInsets.all(16), 59 | child: Text( 60 | label, 61 | style: TextStyle(fontSize: 20, fontWeight: FontWeight.w500), 62 | ), 63 | ); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /example/lib/draggable_line_chart.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:example/style.dart'; 4 | import 'package:flutter/material.dart'; 5 | import 'package:flutter_chart/chart/chart/line_chart.dart'; 6 | import 'package:flutter_chart/chart/common/base_layout_config.dart'; 7 | import 'package:flutter_chart/chart/common/chart_gesture_view.dart'; 8 | import 'package:flutter_chart/chart/impl/line/line_canvas_impl.dart'; 9 | import 'package:flutter_chart/chart/impl/line/line_layout_impl.dart'; 10 | import 'package:flutter_chart/chart/model/chart_data_model.dart'; 11 | import 'package:intl/intl.dart'; 12 | 13 | /// 拖拽&长按 的 Charts,横坐标依据数据长度而定。 14 | /// 适合排列场景:07-1 、07-02、07-03、07-04... 15 | /// 即:每个x轴刻度间的距离相同,x轴刻度之间只允许绘制一个点。 16 | class DraggableLineChart extends StatefulWidget { 17 | const DraggableLineChart({Key? key}) : super(key: key); 18 | 19 | @override 20 | State createState() => _DraggableLineChartState(); 21 | } 22 | 23 | class _DraggableLineChartState extends State { 24 | static DateTime hour({int hour = 0}) { 25 | var milliseconds = (1656302400 + 3600 * hour) * 1000; 26 | return DateTime.fromMillisecondsSinceEpoch(milliseconds); 27 | } 28 | 29 | /// 数据源 30 | final data = [ 31 | ChartDataModel( 32 | xAxis: hour(hour: 0), 33 | yAxis: 0, 34 | hasBubble: Random(0).nextBool(), 35 | ), 36 | ChartDataModel( 37 | xAxis: hour(hour: 1), 38 | yAxis: 1, 39 | hasBubble: Random(1).nextBool(), 40 | ), 41 | ChartDataModel( 42 | xAxis: hour(hour: 2), 43 | yAxis: 9, 44 | hasBubble: Random(2).nextBool(), 45 | ), 46 | ChartDataModel( 47 | xAxis: hour(hour: 3), 48 | yAxis: 11, 49 | hasBubble: Random(3).nextBool(), 50 | ), 51 | ChartDataModel( 52 | xAxis: hour(hour: 4), 53 | yAxis: 56, 54 | hasBubble: Random(4).nextBool(), 55 | ), 56 | ChartDataModel( 57 | xAxis: hour(hour: 5), 58 | yAxis: 100, 59 | hasBubble: Random(5).nextBool(), 60 | ), 61 | ChartDataModel( 62 | xAxis: hour(hour: 6), 63 | yAxis: 88, 64 | hasBubble: Random(6).nextBool(), 65 | ), 66 | ChartDataModel( 67 | xAxis: hour(hour: 7), 68 | yAxis: 33, 69 | hasBubble: Random(7).nextBool(), 70 | ), 71 | ChartDataModel(xAxis: hour(hour: 8), yAxis: 55), 72 | ChartDataModel(xAxis: hour(hour: 9), yAxis: 77), 73 | ChartDataModel(xAxis: hour(hour: 10), yAxis: 34), 74 | ChartDataModel(xAxis: hour(hour: 11), yAxis: 2), 75 | ChartDataModel(xAxis: hour(hour: 12), yAxis: 7), 76 | ]; 77 | 78 | Size? size; 79 | final margin = const EdgeInsets.symmetric(horizontal: 10); 80 | 81 | @override 82 | Widget build(BuildContext context) { 83 | var pixel = MediaQuery.of(context).size.width; 84 | size ??= Size(pixel, 264); 85 | return Container( 86 | width: double.infinity, 87 | margin: margin, 88 | decoration: BoxDecoration( 89 | color: Colors.white, 90 | borderRadius: BorderRadius.circular(8), 91 | ), 92 | child: ChartGestureView( 93 | initConfig: LineLayoutConfig( 94 | data: data, 95 | size: Size(pixel - margin.horizontal, 264), 96 | delegate: CommonLineAxisDelegate.copyWith( 97 | xAxisFormatter: _xAxisFormatter, 98 | yAxisFormatter: _yAxisFormatter, 99 | lineStyle: CommonLineAxisDelegate.lineStyle?.copyWith( 100 | color: Colors.green, 101 | ), 102 | ), 103 | popupSpec: CommonPopupSpec.copyWith( 104 | textFormatter: _textFormatter, 105 | // popupShouldDraw: _popupShouldShow, 106 | // bubbleShouldDraw: _popupBubbleShouldShow, 107 | lineStyle: CommonPopupSpec.lineStyle?.copyWith( 108 | color: Colors.lightGreen, 109 | ), 110 | ), 111 | ), 112 | builder: (_, newConfig) => CustomPaint( 113 | size: size!, 114 | painter: LineChart( 115 | data: data, 116 | contentCanvas: LineCanvasImpl(), 117 | layoutConfig: newConfig as BaseLayoutConfig, 118 | ), 119 | ), 120 | ), 121 | ); 122 | } 123 | 124 | /// 悬浮框内容 125 | InlineSpan _textFormatter(ChartDataModel data) { 126 | var xAxis = DateFormat('HH:mm').format(data.xAxis); 127 | 128 | /// 是否为异常数据 129 | var normalValue = 20; 130 | bool isException = data.yAxis > normalValue; 131 | Color color = isException ? Colors.red : Colors.black; 132 | return TextSpan( 133 | text: '$xAxis\n', 134 | style: const TextStyle(fontSize: 12, color: Colors.black), 135 | children: [ 136 | TextSpan( 137 | text: isException ? '气温:大于' : '气温: ', 138 | style: TextStyle(fontSize: 12, color: color), 139 | ), 140 | TextSpan( 141 | text: isException ? normalValue.toString() : '${data.yAxis.toInt()}', 142 | style: const TextStyle( 143 | fontSize: 16, 144 | color: Colors.red, 145 | fontWeight: FontWeight.w500, 146 | ), 147 | ), 148 | TextSpan( 149 | text: '°c', 150 | style: TextStyle(fontSize: 14, color: color), 151 | ), 152 | ], 153 | ); 154 | } 155 | 156 | /// x轴坐标数据格式化 157 | String _xAxisFormatter(int index) { 158 | return DateFormat('HH:mm').format(data[index].xAxis); 159 | } 160 | 161 | /// y轴坐标数据格式化 162 | String _yAxisFormatter(num data, int index) { 163 | return data.toInt().toString(); 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /example/lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | import 'example_page.dart'; 4 | 5 | void main() => runApp(Example()); 6 | -------------------------------------------------------------------------------- /example/lib/style.dart: -------------------------------------------------------------------------------- 1 | // ignore_for_file: constant_identifier_names 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_chart/chart/common/axis_delegate.dart'; 4 | import 'package:flutter_chart/chart/common/popup_spec.dart'; 5 | import 'package:flutter_chart/chart/model/chart_data_bar.dart'; 6 | import 'package:flutter_chart/chart/model/chart_data_model.dart'; 7 | 8 | /// 曲线图 坐标轴基本样式 9 | const CommonLineAxisDelegate = AxisDelegate( 10 | showXAxisLine: true, 11 | showYAxisLine: true, 12 | showVerticalHintAxisLine: true, 13 | showHorizontalHintAxisLine: true, 14 | labelStyle: LabelStyle( 15 | style: TextStyle(fontSize: 12, color: Color(0xFF666666)), 16 | ), 17 | axisLineStyle: LineStyle(color: Color(0xFFE5E5E5), dashPattern: [4]), 18 | hintLineStyle: LineStyle(color: Color(0xFFE5E5E5), dashPattern: [4]), 19 | lineStyle: LineStyle( 20 | strokeWidth: 2, 21 | color: Colors.deepOrangeAccent, 22 | ), 23 | ); 24 | 25 | /// 悬浮框基本样式 26 | const CommonPopupSpec = PopupSpec( 27 | lineStyle: LineStyle( 28 | color: Color(0xFFEE2828), 29 | strokeWidth: 1, 30 | dashPattern: [3], 31 | ), 32 | radius: 8, 33 | fill: Colors.white, 34 | stroke: Color(0x5CD2BFBF), 35 | strokeWidthPx: 2, 36 | bubbleSpec: BubbleSpec( 37 | fill: Color(0xFFEE2828), 38 | strokeWidthPx: 4, 39 | stroke: Color(0xFFFFD4D4), 40 | ), 41 | ); 42 | 43 | /// bar 坐标轴基本样式 44 | const CommonBarAxisDelegate = AxisDelegate( 45 | showXAxisLine: true, 46 | showYAxisLine: true, 47 | showVerticalHintAxisLine: true, 48 | showHorizontalHintAxisLine: true, 49 | labelStyle: LabelStyle( 50 | style: TextStyle(fontSize: 12, color: Color(0xFF666666)), 51 | ), 52 | axisLineStyle: LineStyle(color: Color(0xFFE5E5E5), dashPattern: [4]), 53 | hintLineStyle: LineStyle(color: Color(0xFFE5E5E5), dashPattern: [4]), 54 | domainPointSpacing: 56, 55 | hintLineNum: 5, 56 | lineStyle: LineStyle( 57 | strokeWidth: 2, 58 | color: Colors.deepOrangeAccent, 59 | ), 60 | barStyle: BarStyle(), 61 | ); 62 | 63 | /// 悬浮框基本样式 64 | const CommonBarPopupSpec = PopupSpec( 65 | lineStyle: LineStyle( 66 | color: Color(0xFFEE2828), 67 | strokeWidth: 1, 68 | dashPattern: [3], 69 | ), 70 | radius: 8, 71 | fill: Colors.white, 72 | stroke: Color(0x5CD2BFBF), 73 | strokeWidthPx: 2, 74 | bubbleSpec: BubbleSpec( 75 | fill: Color(0xFFEE2828), 76 | strokeWidthPx: 4, 77 | stroke: Color(0xFFFFD4D4), 78 | ), 79 | ); 80 | -------------------------------------------------------------------------------- /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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | async: 5 | dependency: transitive 6 | description: 7 | name: async 8 | url: "https://pub.flutter-io.cn" 9 | source: hosted 10 | version: "2.8.2" 11 | boolean_selector: 12 | dependency: transitive 13 | description: 14 | name: boolean_selector 15 | url: "https://pub.flutter-io.cn" 16 | source: hosted 17 | version: "2.1.0" 18 | characters: 19 | dependency: transitive 20 | description: 21 | name: characters 22 | url: "https://pub.flutter-io.cn" 23 | source: hosted 24 | version: "1.2.0" 25 | charcode: 26 | dependency: transitive 27 | description: 28 | name: charcode 29 | url: "https://pub.flutter-io.cn" 30 | source: hosted 31 | version: "1.3.1" 32 | clock: 33 | dependency: transitive 34 | description: 35 | name: clock 36 | url: "https://pub.flutter-io.cn" 37 | source: hosted 38 | version: "1.1.0" 39 | collection: 40 | dependency: transitive 41 | description: 42 | name: collection 43 | url: "https://pub.flutter-io.cn" 44 | source: hosted 45 | version: "1.16.0" 46 | fake_async: 47 | dependency: transitive 48 | description: 49 | name: fake_async 50 | url: "https://pub.flutter-io.cn" 51 | source: hosted 52 | version: "1.3.0" 53 | flutter: 54 | dependency: "direct main" 55 | description: flutter 56 | source: sdk 57 | version: "0.0.0" 58 | flutter_chart: 59 | dependency: "direct main" 60 | description: 61 | path: ".." 62 | relative: true 63 | source: path 64 | version: "0.2.0" 65 | flutter_test: 66 | dependency: "direct dev" 67 | description: flutter 68 | source: sdk 69 | version: "0.0.0" 70 | intl: 71 | dependency: transitive 72 | description: 73 | name: intl 74 | url: "https://pub.flutter-io.cn" 75 | source: hosted 76 | version: "0.17.0" 77 | matcher: 78 | dependency: transitive 79 | description: 80 | name: matcher 81 | url: "https://pub.flutter-io.cn" 82 | source: hosted 83 | version: "0.12.11" 84 | material_color_utilities: 85 | dependency: transitive 86 | description: 87 | name: material_color_utilities 88 | url: "https://pub.flutter-io.cn" 89 | source: hosted 90 | version: "0.1.4" 91 | meta: 92 | dependency: transitive 93 | description: 94 | name: meta 95 | url: "https://pub.flutter-io.cn" 96 | source: hosted 97 | version: "1.7.0" 98 | path: 99 | dependency: transitive 100 | description: 101 | name: path 102 | url: "https://pub.flutter-io.cn" 103 | source: hosted 104 | version: "1.8.1" 105 | sky_engine: 106 | dependency: transitive 107 | description: flutter 108 | source: sdk 109 | version: "0.0.99" 110 | source_span: 111 | dependency: transitive 112 | description: 113 | name: source_span 114 | url: "https://pub.flutter-io.cn" 115 | source: hosted 116 | version: "1.8.2" 117 | stack_trace: 118 | dependency: transitive 119 | description: 120 | name: stack_trace 121 | url: "https://pub.flutter-io.cn" 122 | source: hosted 123 | version: "1.10.0" 124 | stream_channel: 125 | dependency: transitive 126 | description: 127 | name: stream_channel 128 | url: "https://pub.flutter-io.cn" 129 | source: hosted 130 | version: "2.1.0" 131 | string_scanner: 132 | dependency: transitive 133 | description: 134 | name: string_scanner 135 | url: "https://pub.flutter-io.cn" 136 | source: hosted 137 | version: "1.1.0" 138 | term_glyph: 139 | dependency: transitive 140 | description: 141 | name: term_glyph 142 | url: "https://pub.flutter-io.cn" 143 | source: hosted 144 | version: "1.2.0" 145 | test_api: 146 | dependency: transitive 147 | description: 148 | name: test_api 149 | url: "https://pub.flutter-io.cn" 150 | source: hosted 151 | version: "0.4.9" 152 | vector_math: 153 | dependency: transitive 154 | description: 155 | name: vector_math 156 | url: "https://pub.flutter-io.cn" 157 | source: hosted 158 | version: "2.1.2" 159 | sdks: 160 | dart: ">=2.17.0 <3.0.0" 161 | -------------------------------------------------------------------------------- /example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: example 2 | description: Demonstrates how to use the flutter_chart plugin. 3 | version: 0.1.5 4 | publish_to: 'none' 5 | 6 | environment: 7 | sdk: ">=2.17.0 <3.0.0" 8 | 9 | dependencies: 10 | flutter: 11 | sdk: flutter 12 | flutter_chart: 13 | path: ../ 14 | 15 | dev_dependencies: 16 | flutter_test: 17 | sdk: flutter 18 | 19 | flutter: 20 | uses-material-design: true -------------------------------------------------------------------------------- /example/test/widget_test.dart: -------------------------------------------------------------------------------- 1 | //import 'package:example/example_page.dart'; 2 | //import 'package:flutter_test/flutter_test.dart'; 3 | 4 | void main() { 5 | // group('Chart Test', () { 6 | // testWidgets("example chart", (WidgetTester tester) async { 7 | // tester.pumpWidget(Example()); 8 | // }); 9 | // }); 10 | } 11 | -------------------------------------------------------------------------------- /example/web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/example/web/favicon.png -------------------------------------------------------------------------------- /example/web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/example/web/icons/Icon-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/example/web/icons/Icon-512.png -------------------------------------------------------------------------------- /example/web/icons/Icon-maskable-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/example/web/icons/Icon-maskable-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-maskable-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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 | # Disable Windows macros that collide with C++ standard library functions. 24 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 25 | 26 | # Add dependency libraries and include directories. Add any application-specific 27 | # dependencies here. 28 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 29 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 30 | 31 | # Run the Flutter tool portions of the build. This must not be removed. 32 | add_dependencies(${BINARY_NAME} flutter_assemble) 33 | -------------------------------------------------------------------------------- /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 | #ifdef FLUTTER_BUILD_NUMBER 64 | #define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER 65 | #else 66 | #define VERSION_AS_NUMBER 1,0,0 67 | #endif 68 | 69 | #ifdef FLUTTER_BUILD_NAME 70 | #define VERSION_AS_STRING #FLUTTER_BUILD_NAME 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/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/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.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 | -------------------------------------------------------------------------------- /flutter_chart.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /lib/chart/canvas/base_canvas.dart: -------------------------------------------------------------------------------- 1 | import 'dart:ui'; 2 | 3 | import '../common/base_layout_config.dart'; 4 | import 'base_chart_canvas.dart'; 5 | 6 | /// Base 绘制内容 7 | abstract class BaseCanvas { 8 | const BaseCanvas(); 9 | 10 | void draw({ 11 | required List data, 12 | required Canvas canvas, 13 | required BaseChartCanvas chartCanvas, 14 | required BaseLayoutConfig config, 15 | }); 16 | } 17 | -------------------------------------------------------------------------------- /lib/chart/canvas/base_chart_canvas.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_chart/chart/common/base_text_element.dart'; 5 | 6 | /// 绘制内容 7 | abstract class BaseChartCanvas { 8 | const BaseChartCanvas(); 9 | 10 | /// 绘制点 11 | void drawPoint({ 12 | required Canvas canvas, 13 | required Offset offset, 14 | required double radius, 15 | Color? fill, 16 | Color? stroke, 17 | double? strokeWidthPx, 18 | BlendMode? blendMode, 19 | Rectangle? clipBounds, 20 | Offset? translate, 21 | }); 22 | 23 | /// 绘制线 24 | void drawLine({ 25 | required Canvas canvas, 26 | required List points, 27 | Rectangle? clipBounds, 28 | Offset? translate, 29 | Color? color, 30 | bool? roundEndCaps, 31 | double? strokeWidthPx, 32 | List? dashPattern, 33 | }); 34 | 35 | /// 绘制曲线 36 | void drawCurvedLine({ 37 | required Canvas canvas, 38 | required List points, 39 | Rectangle? clipBounds, 40 | Offset? translate, 41 | Color? color, 42 | bool? roundEndCaps, 43 | double? strokeWidthPx, 44 | List? dashPattern, 45 | }); 46 | 47 | /// 绘制矩形 48 | void drawRect({ 49 | required Canvas canvas, 50 | required Rectangle bounds, 51 | Rectangle? clipBounds, 52 | Offset? translate, 53 | Color? fill, 54 | Color? stroke, 55 | double? strokeWidthPx, 56 | }); 57 | 58 | /// 绘制圆角矩形 59 | void drawRRect({ 60 | required Canvas canvas, 61 | required Rectangle bounds, 62 | Rectangle? clipBounds, 63 | Offset? translate, 64 | Color? fill, 65 | Color? stroke, 66 | double? strokeWidthPx, 67 | num? radius, 68 | bool roundTopLeft = false, 69 | bool roundTopRight = false, 70 | bool roundBottomLeft = false, 71 | bool roundBottomRight = false, 72 | }); 73 | 74 | /// 绘制文字 75 | void drawText({ 76 | required Canvas canvas, 77 | required BaseTextElement textElement, 78 | required Offset offset, 79 | double rotation = 0.0, 80 | Offset? translate, 81 | }); 82 | } 83 | -------------------------------------------------------------------------------- /lib/chart/canvas/point_painter.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | /// 绘制点 4 | class PointPainter { 5 | static void draw({ 6 | required Canvas canvas, 7 | required Paint paint, 8 | required Offset offset, 9 | required double radius, 10 | Color? fill, 11 | Color? stroke, 12 | double? strokeWidthPx, 13 | }) { 14 | if (fill != null) { 15 | paint.color = fill; 16 | paint.style = PaintingStyle.fill; 17 | canvas.drawCircle(Offset(offset.dx, offset.dy), radius, paint); 18 | } 19 | if (stroke != null && strokeWidthPx != null && strokeWidthPx > 0.0) { 20 | paint.color = stroke; 21 | paint.strokeWidth = strokeWidthPx; 22 | paint.strokeJoin = StrokeJoin.bevel; 23 | paint.style = PaintingStyle.stroke; 24 | canvas.drawCircle( 25 | Offset(offset.dx, offset.dy), 26 | radius, 27 | paint, 28 | ); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/chart/chart/bar_chart.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_chart/chart/canvas/axis_canvas_impl.dart'; 3 | import 'package:flutter_chart/chart/canvas/chart_canvas_impl.dart'; 4 | 5 | import 'bar_popup_canvas.dart'; 6 | import 'base_chart.dart'; 7 | 8 | /// 绘制 bar 段落 9 | class BarChart extends BaseChart { 10 | const BarChart({ 11 | required super.data, 12 | required super.layoutConfig, 13 | super.chartCanvas = const ChartCanvasImpl(), 14 | super.axisCanvas = const AxisCanvasImpl(), 15 | super.contentCanvas, 16 | }); 17 | 18 | /// 绘制悬浮框 19 | @override 20 | void onDrawGesture(Canvas canvas, Rect bounds) { 21 | BarPopupCanvas.draw( 22 | canvas: canvas, 23 | config: layoutConfig, 24 | chartCanvas: chartCanvas, 25 | ); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/chart/chart/bar_popup_canvas.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_chart/chart/canvas/base_chart_canvas.dart'; 5 | import 'package:flutter_chart/chart/common/base_layout_config.dart'; 6 | import 'package:flutter_chart/chart/common/gesture_delegate.dart'; 7 | import 'package:flutter_chart/chart/common/text_element.dart'; 8 | 9 | /// 绘制Bar Popup悬浮框 10 | /// [BaseLayoutConfig.popupSpec] 11 | class BarPopupCanvas { 12 | static void draw({ 13 | required Canvas canvas, 14 | required BaseChartCanvas chartCanvas, 15 | required BaseLayoutConfig config, 16 | }) { 17 | /// 区分事件类型 18 | var popup = config.popupSpec; 19 | var bounds = config.bounds; 20 | var delegate = config.delegate; 21 | 22 | if (config.gestureDelegate == null || popup == null) { 23 | return; 24 | } 25 | final position = config.gestureDelegate!.position; 26 | if (position?.local == null || position?.global == null) { 27 | return; 28 | } 29 | 30 | /// 长按事件:显示悬浮框 31 | switch (config.gestureDelegate!.type) { 32 | case GestureType.onLongPressStart: 33 | case GestureType.onLongPressMoveUpdate: 34 | case GestureType.onLongPressEnd: 35 | case GestureType.onTapDown: 36 | 37 | /// 查找最匹配的坐标点。 38 | var find = config.findTarget(position!.local!); 39 | if (find == null) return; 40 | 41 | /// 待绘制的富文本 42 | var element = TextElement( 43 | config.popupSpec?.textFormatter?.call(find.model) ?? const TextSpan(), 44 | ); 45 | 46 | /// 文本与边框的距离 47 | var padding = popup.padding; 48 | 49 | /// popup宽度 50 | var rectWidth = element.measurement.horizontalSliceWidth + 51 | padding.left + 52 | padding.right; 53 | 54 | /// popup高度 55 | var rectHeight = element.measurement.verticalSliceWidth + 56 | padding.top + 57 | padding.bottom; 58 | 59 | /// 修正绘制区域 60 | double top; 61 | var verticalSpacing = delegate?.labelVerticalSpacing ?? 0; 62 | var barHeight = delegate?.barStyle?.height ?? 0; 63 | var spacing = verticalSpacing + barHeight; 64 | var dis = find.offset.dy - rectHeight - spacing; 65 | 66 | /// popup显示在bubble的上方 67 | if (dis > bounds.top) { 68 | top = dis; 69 | } else { 70 | /// popup显示在bubble的下方。 71 | top = find.offset.dy + spacing; 72 | } 73 | var rectangle = Rectangle( 74 | max( 75 | bounds.left, 76 | min( 77 | bounds.right - rectWidth, 78 | position.local!.dx - rectWidth / 2, 79 | ), 80 | ), 81 | top, 82 | rectWidth, 83 | rectHeight, 84 | ); 85 | 86 | /// 仅绘制可视范围内的popup 87 | if (rectangle.left > find.offset.dx || 88 | rectangle.right < find.offset.dx) { 89 | return; 90 | } 91 | 92 | /// 绘制指示线 93 | /// 这里减去横轴的辅助线高度,是为了防止指示线压线。 94 | var strokeWidth = delegate?.hintLineStyle?.strokeWidth ?? 0; 95 | var points = [ 96 | Offset(find.offset.dx, config.bounds.top + strokeWidth * 2), 97 | Offset(find.offset.dx, config.bounds.bottom - strokeWidth), 98 | ]; 99 | chartCanvas.drawLine( 100 | canvas: canvas, 101 | points: points, 102 | color: config.popupSpec?.lineStyle?.color, 103 | strokeWidthPx: config.popupSpec?.lineStyle?.strokeWidth, 104 | dashPattern: config.popupSpec?.lineStyle?.dashPattern, 105 | ); 106 | 107 | /// 绘制气泡 108 | if (popup.bubbleShouldDraw?.call(find.model) ?? true) { 109 | var yOffset = Offset(0, (delegate?.barStyle?.height ?? 0) / 2); 110 | chartCanvas.drawPoint( 111 | canvas: canvas, 112 | offset: find.offset + yOffset, 113 | radius: popup.bubbleSpec?.radius ?? 4, 114 | fill: popup.bubbleSpec?.fill, 115 | stroke: popup.bubbleSpec?.stroke, 116 | strokeWidthPx: popup.bubbleSpec?.strokeWidthPx, 117 | ); 118 | } 119 | 120 | /// 绘制Popup 121 | if (true == popup.popupShouldDraw?.call(find.model)) { 122 | chartCanvas.drawRRect( 123 | canvas: canvas, 124 | radius: popup.radius, 125 | fill: popup.fill, 126 | stroke: popup.stroke, 127 | strokeWidthPx: popup.strokeWidthPx, 128 | roundTopLeft: popup.roundTopLeft, 129 | roundTopRight: popup.roundTopRight, 130 | roundBottomLeft: popup.roundBottomLeft, 131 | roundBottomRight: popup.roundBottomRight, 132 | bounds: rectangle, 133 | ); 134 | 135 | /// 在popup区域内绘制富文本 136 | chartCanvas.drawText( 137 | canvas: canvas, 138 | offset: Offset( 139 | rectangle.left.toDouble() + padding.left, 140 | rectangle.top.toDouble() + padding.top, 141 | ), 142 | textElement: element, 143 | ); 144 | } 145 | break; 146 | 147 | default: 148 | break; 149 | } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /lib/chart/chart/base_chart.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | import '../canvas/base_canvas.dart'; 4 | import '../canvas/base_chart_canvas.dart'; 5 | import '../common/base_layout_config.dart'; 6 | 7 | /// create by xt.sun 8 | /// at 2022.06.20 9 | /// 画笔 10 | abstract class BaseChart extends CustomPainter { 11 | /// 数据源 12 | final List data; 13 | 14 | /// charts配置信息 15 | final BaseLayoutConfig layoutConfig; 16 | 17 | /// chart基础绘制:点、线、面,一般的绘制用这个足够了,不够的话,可以扩展。 18 | final BaseChartCanvas chartCanvas; 19 | 20 | /// 坐标系绘制 21 | final BaseCanvas? axisCanvas; 22 | 23 | /// charts内容绘制 24 | final BaseCanvas? contentCanvas; 25 | 26 | const BaseChart({ 27 | required this.data, 28 | required this.layoutConfig, 29 | required this.chartCanvas, 30 | this.axisCanvas, 31 | this.contentCanvas, 32 | }); 33 | 34 | @override 35 | bool shouldRepaint(covariant BaseChart oldDelegate) => 36 | oldDelegate.data != data || oldDelegate.layoutConfig != layoutConfig; 37 | 38 | @override 39 | void paint(Canvas canvas, Size size) { 40 | _onDrawAxis(canvas, layoutConfig.bounds); 41 | _onDraw(canvas, layoutConfig.bounds); 42 | if (layoutConfig.gestureDelegate != null) { 43 | onDrawGesture(canvas, layoutConfig.bounds); 44 | } 45 | } 46 | 47 | /// 绘制坐标系 48 | void _onDrawAxis(Canvas canvas, Rect bounds) { 49 | axisCanvas?.draw( 50 | data: data, 51 | canvas: canvas, 52 | config: layoutConfig, 53 | chartCanvas: chartCanvas, 54 | ); 55 | } 56 | 57 | /// 绘制 Charts 58 | void _onDraw(Canvas canvas, Rect bounds) { 59 | contentCanvas?.draw( 60 | data: data, 61 | canvas: canvas, 62 | config: layoutConfig, 63 | chartCanvas: chartCanvas, 64 | ); 65 | } 66 | 67 | /// 绘制手势 68 | void onDrawGesture(Canvas canvas, Rect bounds) { 69 | // 如果子类需要绘制触摸事件,则需要重写此方法。 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /lib/chart/chart/line_chart.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_chart/chart/canvas/axis_canvas_impl.dart'; 3 | import 'package:flutter_chart/chart/canvas/chart_canvas_impl.dart'; 4 | 5 | import 'base_chart.dart'; 6 | import 'line_popup_canvas.dart'; 7 | 8 | /// 绘制 折线、曲线。 9 | class LineChart extends BaseChart { 10 | const LineChart({ 11 | required super.data, 12 | required super.layoutConfig, 13 | super.chartCanvas = const ChartCanvasImpl(), 14 | super.axisCanvas = const AxisCanvasImpl(), 15 | super.contentCanvas, 16 | }); 17 | 18 | /// 绘制悬浮框 19 | @override 20 | void onDrawGesture(Canvas canvas, Rect bounds) { 21 | LinePopupCanvas.draw( 22 | canvas: canvas, 23 | config: layoutConfig, 24 | chartCanvas: chartCanvas, 25 | ); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/chart/chart/line_popup_canvas.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_chart/chart/canvas/base_chart_canvas.dart'; 5 | import 'package:flutter_chart/chart/common/base_layout_config.dart'; 6 | import 'package:flutter_chart/chart/common/gesture_delegate.dart'; 7 | import 'package:flutter_chart/chart/common/text_element.dart'; 8 | 9 | /// 绘制Line Popup悬浮框 10 | /// [BaseLayoutConfig.popupSpec] 11 | class LinePopupCanvas { 12 | static void draw({ 13 | required Canvas canvas, 14 | required BaseChartCanvas chartCanvas, 15 | required BaseLayoutConfig config, 16 | }) { 17 | /// 区分事件类型 18 | var popup = config.popupSpec; 19 | var bounds = config.bounds; 20 | 21 | if (config.gestureDelegate == null || popup == null) { 22 | return; 23 | } 24 | final position = config.gestureDelegate!.position; 25 | if (position?.local == null || position?.global == null) { 26 | return; 27 | } 28 | 29 | /// 长按事件:显示悬浮框 30 | switch (config.gestureDelegate!.type) { 31 | case GestureType.onLongPressStart: 32 | case GestureType.onLongPressMoveUpdate: 33 | case GestureType.onLongPressEnd: 34 | case GestureType.onTapDown: 35 | 36 | /// 查找最匹配的坐标点。 37 | var find = config.findTarget(position!.local!); 38 | if (find == null) return; 39 | 40 | /// 待绘制的富文本 41 | var element = TextElement( 42 | config.popupSpec?.textFormatter?.call(find.model) ?? const TextSpan(), 43 | ); 44 | 45 | /// 文本与边框的距离 46 | var padding = popup.padding; 47 | 48 | /// popup宽度 49 | var rectWidth = element.measurement.horizontalSliceWidth + 50 | padding.left + 51 | padding.right; 52 | 53 | /// popup高度 54 | var rectHeight = element.measurement.verticalSliceWidth + 55 | padding.top + 56 | padding.bottom; 57 | 58 | /// 修正绘制区域 59 | double top; 60 | var verticalSpacing = (config.delegate?.labelVerticalSpacing ?? 0); 61 | var dis = find.offset.dy - rectHeight - verticalSpacing; 62 | 63 | // popup显示在bubble的上方 64 | if (dis > bounds.top) { 65 | top = dis; 66 | } else { 67 | // popup显示在bubble的下方。 68 | top = find.offset.dy + verticalSpacing; 69 | } 70 | var rectangle = Rectangle( 71 | max( 72 | bounds.left, 73 | min( 74 | bounds.right - rectWidth, 75 | position.local!.dx - rectWidth / 2, 76 | ), 77 | ), 78 | top, 79 | rectWidth, 80 | rectHeight, 81 | ); 82 | 83 | /// 仅绘制可视范围内的popup 84 | if (rectangle.left > find.offset.dx || 85 | rectangle.right < find.offset.dx) { 86 | return; 87 | } 88 | 89 | /// 绘制指示线 90 | /// 这里减去横轴的辅助线高度,是为了防止指示线压线。 91 | var strokeWidth = config.delegate?.hintLineStyle?.strokeWidth ?? 0; 92 | var points = [ 93 | Offset(find.offset.dx, config.bounds.top + strokeWidth * 2), 94 | Offset(find.offset.dx, config.bounds.bottom - strokeWidth), 95 | ]; 96 | chartCanvas.drawLine( 97 | canvas: canvas, 98 | points: points, 99 | color: config.popupSpec?.lineStyle?.color, 100 | strokeWidthPx: config.popupSpec?.lineStyle?.strokeWidth, 101 | dashPattern: config.popupSpec?.lineStyle?.dashPattern, 102 | ); 103 | 104 | /// 绘制气泡 105 | if (popup.bubbleShouldDraw?.call(find.model) ?? true) { 106 | chartCanvas.drawPoint( 107 | canvas: canvas, 108 | offset: find.offset, 109 | radius: popup.bubbleSpec?.radius ?? 4, 110 | fill: popup.bubbleSpec?.fill, 111 | stroke: popup.bubbleSpec?.stroke, 112 | strokeWidthPx: popup.bubbleSpec?.strokeWidthPx, 113 | ); 114 | } 115 | 116 | /// 此点位,不需要绘制悬浮框,默认可显示。 117 | if (false == popup.popupShouldDraw?.call(find.model)) return; 118 | 119 | /// 绘制Popup 120 | chartCanvas.drawRRect( 121 | canvas: canvas, 122 | radius: popup.radius, 123 | fill: popup.fill, 124 | stroke: popup.stroke, 125 | strokeWidthPx: popup.strokeWidthPx, 126 | roundTopLeft: popup.roundTopLeft, 127 | roundTopRight: popup.roundTopRight, 128 | roundBottomLeft: popup.roundBottomLeft, 129 | roundBottomRight: popup.roundBottomRight, 130 | bounds: rectangle, 131 | ); 132 | 133 | /// 在popup区域内绘制富文本 134 | chartCanvas.drawText( 135 | canvas: canvas, 136 | offset: Offset( 137 | rectangle.left.toDouble() + padding.left, 138 | rectangle.top.toDouble() + padding.top, 139 | ), 140 | textElement: element, 141 | ); 142 | break; 143 | 144 | default: 145 | break; 146 | } 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /lib/chart/chart_bean.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class ChartBean { 4 | String x; 5 | double y; 6 | int? millisSeconds; 7 | Color? color; 8 | 9 | ChartBean({ 10 | required this.x, 11 | required this.y, 12 | this.millisSeconds, 13 | this.color, 14 | }); 15 | } 16 | -------------------------------------------------------------------------------- /lib/chart/chart_pie_bean.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class ChartPieBean { 4 | double value; 5 | String? type; 6 | double? rate; 7 | Color? color; 8 | double? startAngle; 9 | double? sweepAngle; 10 | 11 | ChartPieBean({ 12 | required this.value, 13 | this.type, 14 | this.rate, 15 | this.color, 16 | this.startAngle, 17 | this.sweepAngle, 18 | }); 19 | } 20 | -------------------------------------------------------------------------------- /lib/chart/common/base_layout_config.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_chart/chart/common/style.dart'; 5 | 6 | import 'axis_delegate.dart'; 7 | import 'find.dart'; 8 | import 'gesture_delegate.dart'; 9 | import 'popup_spec.dart'; 10 | 11 | /// Charts基础配置 12 | abstract class BaseLayoutConfig { 13 | /// 数据源 14 | final List data; 15 | 16 | /// 绘制大小 17 | final Size size; 18 | 19 | /// x轴刻度的数量,默认取[data.length]. 20 | final int? axisCount; 21 | 22 | /// 23 | 24 | /// 坐标原点 25 | final Offset originOffset; 26 | 27 | /// 最右边的坐标 28 | final Offset endOffset; 29 | 30 | /// 绘制区域 31 | final Rect bounds; 32 | 33 | /// 内边距,绘制在[bounds]的内容区域以为 34 | final EdgeInsets padding; 35 | 36 | /// 域轴配置信息 37 | final AxisDelegate? delegate; 38 | 39 | /// 触摸事件 40 | final GestureDelegate? gestureDelegate; 41 | 42 | /// 悬浮框样式 43 | final PopupSpec? popupSpec; 44 | 45 | /// 初始默认滑动到的数据索引 46 | final int? initializePosition; 47 | 48 | /// 一组数据的最大值 49 | num get maxValue => 0.0; 50 | 51 | /// 计算最大值 52 | num getMaxValue(List data) => 0.0; 53 | 54 | /// 获取指定数据的y轴值 55 | num yAxisValue(T data) => 0.0; 56 | 57 | /// 获取x轴指定位置的值 07:00 58 | String? xAxisValue(int index) => null; 59 | 60 | /// x轴刻度数量 61 | int get xAxisCount => axisCount ?? data.length; 62 | 63 | /// 根据触摸坐标,匹配目标点位 64 | ChartTargetFind? findTarget(Offset offset) => null; 65 | 66 | /// 定义手势拖拽的宽度,一般为一屏的宽度。 67 | double? get draggableWidth => size.width - padding.horizontal; 68 | 69 | /// 初始选中点坐标 70 | Offset? getInitializeOffset() { 71 | if (initializePosition == null) { 72 | return null; 73 | } 74 | return _initEndOffset( 75 | length: min(initializePosition!, axisCount ?? data.length), 76 | size: size, 77 | delegate: delegate, 78 | padding: padding, 79 | ); 80 | } 81 | 82 | /// 复用已有字段重新创建一个新的Config. 83 | BaseLayoutConfig copyWith({ 84 | Size? size, 85 | int? axisCount, 86 | int? initializePosition, 87 | AxisDelegate? delegate, 88 | GestureDelegate? gestureDelegate, 89 | PopupSpec? popupSpec, 90 | EdgeInsets? padding, 91 | }); 92 | 93 | BaseLayoutConfig({ 94 | required this.data, 95 | required this.size, 96 | this.axisCount, 97 | this.initializePosition, 98 | this.delegate, 99 | final GestureDelegate? gestureDelegate, 100 | this.popupSpec, 101 | this.padding = const EdgeInsets.only( 102 | left: 40, 103 | top: 32, 104 | right: 16, 105 | bottom: 40, 106 | ), 107 | }) : 108 | // 计算绘制区域 109 | bounds = Rect.fromLTWH( 110 | padding.left, 111 | padding.top, 112 | size.width - padding.left - padding.right, 113 | size.height - padding.top - padding.bottom, 114 | ), 115 | // 坐标系原点 116 | originOffset = _initOriginOffset(size: size, padding: padding), 117 | // 最右边的点,包括不可见的坐标(即:可拖动查看的最右边的点坐标) 118 | endOffset = _initEndOffset( 119 | length: axisCount ?? data.length, 120 | size: size, 121 | delegate: delegate, 122 | padding: padding, 123 | ), 124 | // 初始化手势识别器 125 | gestureDelegate = gestureDelegate?.copyWith( 126 | width: size.width - padding.horizontal, 127 | originOffset: _initOriginOffset(size: size, padding: padding), 128 | endOffset: _initEndOffset( 129 | length: axisCount ?? data.length, 130 | size: size, 131 | delegate: delegate, 132 | padding: padding, 133 | ), 134 | initializeOffset: initializePosition == null 135 | ? null 136 | : _initEndOffset( 137 | length: min(initializePosition, axisCount ?? data.length), 138 | size: size, 139 | delegate: delegate, 140 | padding: padding, 141 | ), 142 | ); 143 | } 144 | 145 | /// 计算坐标原点 146 | Offset _initOriginOffset({ 147 | required Size size, 148 | EdgeInsets padding = EdgeInsets.zero, 149 | }) { 150 | var offset = Offset( 151 | padding.left, 152 | size.height - padding.bottom, 153 | ); 154 | return offset; 155 | } 156 | 157 | /// 最右边的点,包括不可见的坐标(即:可拖动查看的最右边的点坐标) 158 | Offset _initEndOffset({ 159 | int length = 0, 160 | required Size size, 161 | AxisDelegate? delegate, 162 | EdgeInsets padding = EdgeInsets.zero, 163 | }) { 164 | var offset = Offset( 165 | length * (delegate?.domainPointSpacing ?? kDomainPointSpacing), 166 | size.height - padding.bottom, 167 | ); 168 | return offset; 169 | } 170 | -------------------------------------------------------------------------------- /lib/chart/common/base_text_element.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | abstract class BaseTextElement { 4 | /// The max width of this [BaseTextElement] during measure and layout. 5 | /// 6 | /// If the text exceeds maxWidth, the [maxWidthStrategy] is used. 7 | int? get maxWidth; 8 | 9 | set maxWidth(int? value); 10 | 11 | /// The strategy to use if this [BaseTextElement] exceeds the [maxWidth]. 12 | MaxWidthStrategy? get maxWidthStrategy; 13 | 14 | set maxWidthStrategy(MaxWidthStrategy? maxWidthStrategy); 15 | 16 | // The text of this [TextElement]. 17 | InlineSpan get text; 18 | 19 | /// The [TextMeasurement] of this [BaseTextElement] as an approximate of what 20 | /// is actually printed. 21 | /// 22 | /// Will return the [maxWidth] if set and the actual text width is larger. 23 | TextMeasurement get measurement; 24 | 25 | /// The direction to render the text relative to the coordinate. 26 | TextDirection get textDirection; 27 | 28 | set textDirection(TextDirection direction); 29 | 30 | TextAlign get textAlign; 31 | 32 | /// Return true if settings are all the same. 33 | /// 34 | /// Purposely excludes measurement because the measurement will request the 35 | /// native [BaseTextElement] to layout, which is expensive. We want to avoid the 36 | /// layout by comparing with another [BaseTextElement] to see if they have the 37 | /// same settings. 38 | static bool elementSettingsSame(BaseTextElement a, BaseTextElement b) { 39 | return a.maxWidth == b.maxWidth && 40 | a.maxWidthStrategy == b.maxWidthStrategy && 41 | a.text == b.text && 42 | a.textDirection == b.textDirection; 43 | } 44 | } 45 | 46 | enum TextDirection { 47 | ltr, 48 | rtl, 49 | center, 50 | } 51 | 52 | /// The strategy to use if a [BaseTextElement] exceeds the [maxWidth]. 53 | enum MaxWidthStrategy { 54 | truncate, 55 | ellipsize, 56 | } 57 | 58 | /// A measurement result for rendering text. 59 | class TextMeasurement { 60 | /// Rendered width of the text. 61 | final double horizontalSliceWidth; 62 | 63 | /// Vertical slice is likely based off the rendered text. 64 | /// 65 | /// This means that 'mo' and 'My' will have different heights so do not use 66 | /// this for centering vertical text. 67 | final double verticalSliceWidth; 68 | 69 | /// Baseline of the text for text vertical alignment. 70 | final double? baseline; 71 | 72 | TextMeasurement({ 73 | required this.horizontalSliceWidth, 74 | required this.verticalSliceWidth, 75 | this.baseline, 76 | }); 77 | } 78 | -------------------------------------------------------------------------------- /lib/chart/common/find.dart: -------------------------------------------------------------------------------- 1 | import 'dart:ui'; 2 | 3 | /// 根据触摸时的坐标查找到最匹配的数据和位置信息。 4 | class ChartTargetFind { 5 | final T model; 6 | final Offset offset; 7 | 8 | ChartTargetFind(this.model, this.offset); 9 | } 10 | -------------------------------------------------------------------------------- /lib/chart/common/gesture_delegate.dart: -------------------------------------------------------------------------------- 1 | import 'dart:ui'; 2 | 3 | import 'package:flutter/foundation.dart'; 4 | import 'package:flutter/material.dart'; 5 | 6 | /// 事件类型 7 | /// 1. 管理拖拽位置信息。 8 | /// 2. 一个chart值对应一个[GestureDelegate]实例,如果需要复用已有的参数,则使用 [copyWith] 9 | class GestureDelegate { 10 | /// 事件 11 | final GestureType type; 12 | 13 | /// 触摸事件的坐标信息 14 | final GesturePosition? position; 15 | 16 | /// 坐标原点 17 | final Offset originOffset; 18 | 19 | /// 最右边的坐标 20 | final Offset endOffset; 21 | 22 | /// charts初始偏移量 23 | final Offset? initializeOffset; 24 | 25 | /// 一屏的宽度 26 | final double width; 27 | 28 | GestureDelegate({ 29 | this.type = GestureType.idle, 30 | this.position, 31 | this.originOffset = Offset.zero, 32 | this.endOffset = Offset.zero, 33 | this.initializeOffset, 34 | this.width = 0, 35 | }); 36 | 37 | /// 将已有的信息保留,并且构建一个新的对象。 38 | GestureDelegate copyWith({ 39 | GestureType? type, 40 | GesturePosition? position, 41 | Offset? originOffset, 42 | Offset? endOffset, 43 | Offset? initializeOffset, 44 | double? width, 45 | }) { 46 | return GestureDelegate( 47 | type: type ?? this.type, 48 | position: position ?? this.position, 49 | originOffset: originOffset ?? this.originOffset, 50 | endOffset: endOffset ?? this.endOffset, 51 | initializeOffset: initializeOffset ?? this.initializeOffset, 52 | width: width ?? this.width, 53 | ) 54 | .._totalOffset = offset 55 | .._initDragOffset = initDragOffset; 56 | } 57 | 58 | /// 拖拽偏移量 59 | Offset _totalOffset = Offset.zero; 60 | 61 | /// 初始化偏移量。 62 | /// 每次从拖拽开始时记录初始偏移量 63 | Offset? _initDragOffset; 64 | 65 | /// 真实的偏移量,用于绘制 66 | Offset get offset { 67 | if (initDragOffset == null && initializeOffset != null) { 68 | var offset = getInitializeOffset(initializeOffset!); 69 | if (offset.dx.abs() > maxOffset.dx.abs()) { 70 | offset = Offset(-maxOffset.dx, offset.dy); 71 | } 72 | _totalOffset = offset; 73 | _initDragOffset = offset; 74 | } 75 | return _totalOffset; 76 | } 77 | 78 | Offset? get initDragOffset => _initDragOffset; 79 | 80 | /// 根据给定的点坐标计算偏移量 81 | /// 只有绘制内容超过一屏的宽度,才允许拖拽。 82 | Offset getInitializeOffset(Offset offset) { 83 | if (offset.dx - originOffset.dx <= width) { 84 | return Offset.zero; 85 | } 86 | // 将目标点位移动至原点 87 | return Offset(originOffset.dx - offset.dx, offset.dy); 88 | } 89 | 90 | /// 最大偏移量 91 | Offset get maxOffset => 92 | Offset(endOffset.dx - originOffset.dx - width, endOffset.dy); 93 | 94 | /// 是否滑动到了左右侧,此时不允许再次滑动了。 95 | bool get isRightArrived => offset.dx.abs() >= maxOffset.dx; 96 | 97 | /// 是否滑动到了最左侧,此时就允许再次滑动了。 98 | bool get isStartArrived => offset.dx >= 0; 99 | 100 | /// 只有绘制内容超过一屏的宽度,才允许拖拽。 101 | bool get isDragEnable => (endOffset - originOffset).distance > width; 102 | 103 | /// 累加拖拽的偏移量 104 | /// 拖拽位置更新时调用。 105 | /// [GestureType.onDragStart]响应时,初始距离与真正的位置更新还有一段时间, 106 | /// 所以获取位移数据需要在[GestureType.onDragUpdate]状态下计算。 107 | void addOffset(Offset offset) { 108 | /// 如果只有一屏的内容,则不允许拖拽 109 | if (!isDragEnable) { 110 | return; 111 | } 112 | if (type == GestureType.onDragUpdate) { 113 | if (_initDragOffset == null) { 114 | _initDragOffset = offset; 115 | if (kDebugMode) { 116 | print('重置拖拽开始位置:$offset}'); 117 | } 118 | return; 119 | } 120 | if (kDebugMode) { 121 | print('拖拽中...$offset'); 122 | } 123 | var dis = (offset - _initDragOffset!); 124 | _totalOffset += dis; 125 | _initDragOffset = offset; 126 | 127 | /// 到达最左侧 128 | if (isStartArrived) { 129 | _totalOffset = Offset.zero; 130 | if (kDebugMode) { 131 | print('已经拖动到最左侧了 ➡️ ,原点:$originOffset'); 132 | } 133 | return; 134 | } 135 | 136 | /// 到达最右侧 137 | if (isRightArrived) { 138 | _totalOffset = -Offset(maxOffset.dx, maxOffset.dy); 139 | if (kDebugMode) { 140 | print('已经拖动到最右侧了 ⬅️ ,最右侧:$endOffset'); 141 | } 142 | return; 143 | } 144 | 145 | if (kDebugMode) { 146 | print('拖拽总偏移量:$_totalOffset, 原点: $originOffset,右侧 : $maxOffset}'); 147 | } 148 | } 149 | } 150 | 151 | /// 当事件类型为 [GestureType.onDragStart] 时需要调用。 152 | /// 初始化偏移量,注意:此偏移量不是真实的,是为了记录拖拽开始的位置。 153 | void initOffset(Offset offset) { 154 | if (type == GestureType.onDragStart) { 155 | _initDragOffset = offset; 156 | if (kDebugMode) { 157 | print('拖拽触发'); 158 | } 159 | } 160 | } 161 | 162 | /// 是否处于拖拽模式 163 | bool isDragging() { 164 | return type == GestureType.onDragStart || 165 | type == GestureType.onDragUpdate || 166 | type == GestureType.onDragEnd; 167 | } 168 | } 169 | 170 | /// 坐标位置信息 171 | class GesturePosition { 172 | /// 相对于自身原点(0,0)的坐标 173 | final Offset? local; 174 | 175 | /// 相对于屏幕原点(0,0)的坐标 176 | final Offset? global; 177 | 178 | const GesturePosition({this.local, this.global}); 179 | } 180 | 181 | /// 事件类型 182 | enum GestureType { 183 | idle, // 初始事件,意思就是没有事件。 184 | onHover, 185 | onTapDown, 186 | onLongPressStart, 187 | onLongPressMoveUpdate, 188 | onLongPressEnd, 189 | onDragStart, 190 | onDragUpdate, 191 | onDragEnd, 192 | } 193 | -------------------------------------------------------------------------------- /lib/chart/common/popup_spec.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | import 'axis_delegate.dart'; 4 | 5 | /// [InlineSpan] 悬浮框显示文本内容,可以绘制富文本。 6 | /// [T] charts 的数据类型。 7 | typedef PopupTextFormatter = InlineSpan Function(T data); 8 | 9 | /// 对应点是否需要绘制悬浮框、气泡 10 | typedef PopupShouldDraw = bool Function(T data); 11 | 12 | /// 悬浮框 13 | class PopupSpec { 14 | /// 高亮点气泡样式 15 | final BubbleSpec? bubbleSpec; 16 | 17 | /// 辅助线样式 18 | final LineStyle? lineStyle; 19 | 20 | /// 内边距 21 | final EdgeInsets padding; 22 | 23 | /// 悬浮框背景色 24 | final Color? fill; 25 | 26 | /// 悬浮框边框阴影 27 | final Color? stroke; 28 | 29 | /// 边框宽度 30 | final double? strokeWidthPx; 31 | 32 | /// 圆角 33 | final num? radius; 34 | 35 | /// 可以分别设置上下左右的圆角 36 | final bool roundTopLeft; 37 | final bool roundTopRight; 38 | final bool roundBottomLeft; 39 | final bool roundBottomRight; 40 | 41 | /// 绘制内容 42 | final PopupTextFormatter? textFormatter; 43 | 44 | /// 是否应该显示该坐标的悬浮框 45 | final PopupShouldDraw? popupShouldDraw; 46 | 47 | /// 是否应该显示该坐标的气泡 48 | final PopupShouldDraw? bubbleShouldDraw; 49 | 50 | const PopupSpec({ 51 | this.bubbleSpec, 52 | this.lineStyle, 53 | this.padding = const EdgeInsets.symmetric(horizontal: 12, vertical: 16), 54 | this.fill, 55 | this.stroke, 56 | this.strokeWidthPx, 57 | this.radius, 58 | this.roundTopLeft = true, 59 | this.roundTopRight = true, 60 | this.roundBottomLeft = true, 61 | this.roundBottomRight = true, 62 | this.textFormatter, 63 | this.popupShouldDraw, 64 | this.bubbleShouldDraw, 65 | }); 66 | 67 | PopupSpec copyWith({ 68 | LineStyle? lineStyle, 69 | EdgeInsets? padding, 70 | BubbleSpec? bubbleSpec, 71 | Color? fill, 72 | Color? stroke, 73 | double? strokeWidthPx, 74 | num? radius, 75 | bool? roundTopLeft, 76 | bool? roundTopRight, 77 | bool? roundBottomLeft, 78 | bool? roundBottomRight, 79 | PopupTextFormatter? textFormatter, 80 | PopupShouldDraw? popupShouldDraw, 81 | PopupShouldDraw? bubbleShouldDraw, 82 | }) { 83 | return PopupSpec( 84 | lineStyle: lineStyle ?? this.lineStyle, 85 | padding: padding ?? this.padding, 86 | bubbleSpec: bubbleSpec ?? this.bubbleSpec, 87 | textFormatter: textFormatter ?? this.textFormatter, 88 | popupShouldDraw: popupShouldDraw ?? this.popupShouldDraw, 89 | bubbleShouldDraw: bubbleShouldDraw ?? this.bubbleShouldDraw, 90 | fill: fill ?? this.fill, 91 | stroke: stroke ?? this.stroke, 92 | strokeWidthPx: strokeWidthPx ?? this.strokeWidthPx, 93 | radius: radius ?? this.radius, 94 | roundTopLeft: roundTopLeft ?? this.roundTopLeft, 95 | roundTopRight: roundTopRight ?? this.roundTopRight, 96 | roundBottomLeft: roundBottomLeft ?? this.roundBottomLeft, 97 | roundBottomRight: roundBottomRight ?? this.roundBottomRight, 98 | ); 99 | } 100 | } 101 | 102 | /// 高亮点气泡样式(标注charts上的某一个点) 103 | class BubbleSpec { 104 | /// 圆角 105 | final double radius; 106 | 107 | /// 填充色 108 | final Color? fill; 109 | 110 | /// 边框颜色 111 | final Color? stroke; 112 | 113 | /// 边框宽度 114 | final double? strokeWidthPx; 115 | 116 | const BubbleSpec({ 117 | this.radius = 6, 118 | this.fill, 119 | this.stroke, 120 | this.strokeWidthPx, 121 | }); 122 | 123 | BubbleSpec copyWith({ 124 | double? radius, 125 | Color? fill, 126 | Color? stroke, 127 | double? strokeWidthPx, 128 | }) { 129 | return BubbleSpec( 130 | radius: radius ?? this.radius, 131 | fill: fill ?? this.fill, 132 | stroke: stroke ?? this.stroke, 133 | strokeWidthPx: strokeWidthPx ?? this.strokeWidthPx, 134 | ); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /lib/chart/common/style.dart: -------------------------------------------------------------------------------- 1 | /// 默认的x轴两点之间的距离 2 | const kDomainPointSpacing = 48.0; 3 | 4 | /// y轴与文字间的距离 5 | const kLabelHorizontalSpacing = 20.0; 6 | 7 | /// x轴与文字间的距 8 | const kLabelVerticalSpacing = 12.0; 9 | -------------------------------------------------------------------------------- /lib/chart/common/text_element.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_chart/chart/common/base_text_element.dart' 3 | as common 4 | show BaseTextElement, MaxWidthStrategy, TextDirection, TextMeasurement; 5 | 6 | /// Flutter implementation for text measurement and painter. 7 | class TextElement implements common.BaseTextElement { 8 | static const ellipsis = '\u{2026}'; 9 | 10 | @override 11 | final InlineSpan text; 12 | 13 | final double? textScaleFactor; 14 | 15 | var _painterReady = false; 16 | common.TextDirection _textDirection = common.TextDirection.ltr; 17 | 18 | @override 19 | TextAlign textAlign; 20 | 21 | int? _maxWidth; 22 | common.MaxWidthStrategy? _maxWidthStrategy; 23 | 24 | late TextPainter _textPainter; 25 | 26 | late common.TextMeasurement _measurement; 27 | 28 | TextElement( 29 | this.text, { 30 | this.textAlign = TextAlign.left, 31 | this.textScaleFactor, 32 | }); 33 | 34 | @override 35 | set textDirection(common.TextDirection direction) { 36 | if (_textDirection == direction) { 37 | return; 38 | } 39 | _textDirection = direction; 40 | _painterReady = false; 41 | } 42 | 43 | @override 44 | common.TextDirection get textDirection => _textDirection; 45 | 46 | @override 47 | int? get maxWidth => _maxWidth; 48 | 49 | @override 50 | set maxWidth(int? value) { 51 | if (_maxWidth == value) { 52 | return; 53 | } 54 | _maxWidth = value; 55 | _painterReady = false; 56 | } 57 | 58 | @override 59 | common.MaxWidthStrategy? get maxWidthStrategy => _maxWidthStrategy; 60 | 61 | @override 62 | set maxWidthStrategy(common.MaxWidthStrategy? maxWidthStrategy) { 63 | if (_maxWidthStrategy == maxWidthStrategy) { 64 | return; 65 | } 66 | _maxWidthStrategy = maxWidthStrategy; 67 | _painterReady = false; 68 | } 69 | 70 | @override 71 | common.TextMeasurement get measurement { 72 | if (!_painterReady) { 73 | _refreshPainter(); 74 | } 75 | 76 | return _measurement; 77 | } 78 | 79 | /// The estimated distance between where we asked to draw the text (top, left) 80 | /// and where it visually started (top + verticalFontShift, left). 81 | /// 82 | /// 10% of reported font height seems to be about right. 83 | int get verticalFontShift { 84 | if (!_painterReady) { 85 | _refreshPainter(); 86 | } 87 | 88 | return (_textPainter.height * 0.1).ceil(); 89 | } 90 | 91 | TextPainter? get textPainter { 92 | if (!_painterReady) { 93 | _refreshPainter(); 94 | } 95 | return _textPainter; 96 | } 97 | 98 | /// Create text painter and measure based on current settings 99 | void _refreshPainter() { 100 | _textPainter = TextPainter(text: text) 101 | ..textDirection = TextDirection.ltr 102 | ..textAlign = textAlign 103 | ..ellipsis = maxWidthStrategy == common.MaxWidthStrategy.ellipsize 104 | ? ellipsis 105 | : null; 106 | 107 | if (textScaleFactor != null) { 108 | _textPainter.textScaleFactor = textScaleFactor!; 109 | } 110 | 111 | _textPainter.layout(maxWidth: maxWidth?.toDouble() ?? double.infinity); 112 | 113 | final baseline = 114 | _textPainter.computeDistanceToActualBaseline(TextBaseline.alphabetic); 115 | 116 | // Estimating the actual draw height to 70% of measures size. 117 | // 118 | // The font reports a size larger than the drawn size, which makes it 119 | // difficult to shift the text around to get it to visually line up 120 | // vertically with other components. 121 | _measurement = common.TextMeasurement( 122 | horizontalSliceWidth: _textPainter.width, 123 | verticalSliceWidth: _textPainter.height * 0.7, 124 | baseline: baseline); 125 | 126 | _painterReady = true; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /lib/chart/impl/bar/bar_canvas_impl.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | import 'dart:ui'; 3 | 4 | import 'package:flutter_chart/chart/canvas/base_canvas.dart'; 5 | import 'package:flutter_chart/chart/canvas/base_chart_canvas.dart'; 6 | import 'package:flutter_chart/chart/common/base_layout_config.dart'; 7 | import 'package:flutter_chart/chart/model/chart_data_bar.dart'; 8 | 9 | /// 绘制 bar 10 | class BarCanvasImpl extends BaseCanvas { 11 | @override 12 | void draw({ 13 | required List data, 14 | required Canvas canvas, 15 | required BaseChartCanvas chartCanvas, 16 | required BaseLayoutConfig config, 17 | }) { 18 | if (config.delegate == null) return; 19 | 20 | /// 21 | var delegate = config.delegate!; 22 | var bounds = config.bounds; 23 | var gestureDelegate = config.gestureDelegate; 24 | 25 | /// x轴方向,两点之间的履历 26 | var itemWidth = delegate.domainPointSpacing; 27 | 28 | /// y轴方向每段高度。 29 | var itemHeight = bounds.height / delegate.hintLineNum; 30 | 31 | /// 1s时长对应的宽度,全程24小时,两个点之间的跨度为1小时。 32 | var dw = itemWidth / 3600; // 3600s为1小时 33 | 34 | /// bar高度 35 | var barHeight = delegate.barStyle?.height ?? 0; 36 | 37 | /// bubble 距离bar 右侧的距离 38 | var bubblePadding = 5; 39 | 40 | for (var index = 0; index < data.length; index++) { 41 | var model = data[index]; 42 | 43 | var date = model.time; 44 | var hour = date.hour; 45 | var minute = date.minute; 46 | var begin = date.second + minute * 60 + hour * 3600; 47 | 48 | var offset = Offset( 49 | // bounds.left + itemWidth * index, 50 | bounds.left + begin * dw, 51 | bounds.bottom - model.index * itemHeight - barHeight, 52 | ); 53 | 54 | /// 绘制Rect 55 | chartCanvas.drawRect( 56 | canvas: canvas, 57 | fill: model.color, 58 | stroke: delegate.barStyle?.stroke, 59 | strokeWidthPx: delegate.barStyle?.strokeWidth, 60 | bounds: Rectangle(offset.dx, offset.dy, dw * model.duration, barHeight), 61 | translate: gestureDelegate?.offset, 62 | clipBounds: Rectangle( 63 | bounds.left - (gestureDelegate?.offset.dx ?? 0), 64 | bounds.top, 65 | bounds.width, 66 | bounds.height, 67 | ), 68 | ); 69 | 70 | /// 绘制气泡 71 | if (model.hasBubble) { 72 | var style = config.popupSpec?.bubbleSpec; 73 | if (style == null) return; 74 | // 气泡与bar垂直对齐,并且距离bar右侧的距离5px 75 | var end = Offset( 76 | dw * model.duration - bubblePadding, barHeight.toDouble() / 2); 77 | var pointer = offset + end; 78 | chartCanvas.drawPoint( 79 | canvas: canvas, 80 | offset: pointer, 81 | radius: style.radius, 82 | fill: style.fill, 83 | strokeWidthPx: style.strokeWidthPx, 84 | stroke: style.stroke, 85 | translate: gestureDelegate?.offset, 86 | clipBounds: Rectangle( 87 | bounds.left - (gestureDelegate?.offset.dx ?? 0), 88 | bounds.top, 89 | bounds.width, 90 | bounds.height, 91 | ), 92 | ); 93 | } 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /lib/chart/impl/bar/bar_layout_impl.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_chart/chart/common/axis_delegate.dart'; 3 | import 'package:flutter_chart/chart/common/base_layout_config.dart'; 4 | import 'package:flutter_chart/chart/common/find.dart'; 5 | import 'package:flutter_chart/chart/common/gesture_delegate.dart'; 6 | import 'package:flutter_chart/chart/common/popup_spec.dart'; 7 | import 'package:flutter_chart/chart/model/chart_data_bar.dart'; 8 | import 'package:intl/intl.dart'; 9 | 10 | /// bar charts配置 11 | class BarLayoutConfig extends BaseLayoutConfig { 12 | BarLayoutConfig({ 13 | required super.data, 14 | required super.size, 15 | super.axisCount, 16 | super.delegate, 17 | super.gestureDelegate, 18 | super.popupSpec, 19 | super.padding, 20 | super.initializePosition, 21 | }); 22 | 23 | @override 24 | BarLayoutConfig copyWith({ 25 | List? data, 26 | Size? size, 27 | int? axisCount, 28 | int? initializePosition, 29 | AxisDelegate? delegate, 30 | GestureDelegate? gestureDelegate, 31 | PopupSpec? popupSpec, 32 | EdgeInsets? padding, 33 | }) { 34 | return BarLayoutConfig( 35 | data: data ?? this.data, 36 | size: size ?? this.size, 37 | axisCount: axisCount ?? this.axisCount, 38 | initializePosition: initializePosition ?? this.initializePosition, 39 | delegate: delegate ?? this.delegate, 40 | gestureDelegate: gestureDelegate ?? this.gestureDelegate, 41 | popupSpec: popupSpec ?? this.popupSpec, 42 | padding: padding ?? this.padding, 43 | ); 44 | } 45 | 46 | /// x轴显示的刻度数量 0-24点 47 | /// 优先级比[AxisDelegate.xAxisFormatter]。 48 | @override 49 | String? xAxisValue(int index) { 50 | var hour = index; 51 | var now = DateTime.now(); 52 | var date = DateTime(now.year, now.month, now.day, hour); 53 | return DateFormat('HH:mm').format(date); 54 | } 55 | 56 | /// 根据手势触摸坐标查找指定数据点位 57 | @override 58 | ChartTargetFind? findTarget(Offset offset) { 59 | ChartTargetFind? find; 60 | if (delegate == null) return null; 61 | // 两点之间的距离 62 | var itemWidth = delegate!.domainPointSpacing; 63 | // 选择点的最小匹配宽度 64 | var minSelectWidth = delegate!.minSelectWidth ?? itemWidth; 65 | // 当前拖拽的偏移量 66 | var dragX = (gestureDelegate!.offset).dx; 67 | 68 | /// y轴方向每段高度。 69 | var itemHeight = bounds.height / delegate!.hintLineNum; 70 | 71 | /// 1s时长对应的宽度,全程24小时,两个点之间的跨度为1小时。 72 | var dw = itemWidth / 3600; // 3600s为1小时 73 | 74 | /// bar高度 75 | var barHeight = 9; 76 | 77 | /// bubble 距离bar 右侧的距离 78 | var bubblePadding = 5; 79 | 80 | for (var index = 0; index < data.length; index++) { 81 | var model = data[index]; 82 | if (!model.hasBubble) continue; 83 | 84 | var date = model.time; 85 | var hour = date.hour; 86 | var minute = date.minute; 87 | var seconds = date.second + minute * 60 + hour * 3600 + model.duration; 88 | 89 | var curr = Offset( 90 | bounds.left + dragX + seconds * dw - bubblePadding, 91 | bounds.bottom - model.index * itemHeight - barHeight, 92 | ); 93 | if ((curr - offset).dx.abs() <= minSelectWidth) { 94 | find = ChartTargetFind(model, curr); 95 | break; 96 | } 97 | } 98 | return find; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /lib/chart/impl/bar/fixed_bar_canvas_impl.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | import 'dart:ui'; 3 | 4 | import 'package:flutter_chart/chart/canvas/base_canvas.dart'; 5 | import 'package:flutter_chart/chart/canvas/base_chart_canvas.dart'; 6 | import 'package:flutter_chart/chart/common/base_layout_config.dart'; 7 | import 'package:flutter_chart/chart/impl/bar/fixed_bar_layout_impl.dart'; 8 | import 'package:flutter_chart/chart/model/chart_data_bar.dart'; 9 | 10 | /// 绘制 bar 11 | class FixedBarCanvasImpl extends BaseCanvas { 12 | @override 13 | void draw({ 14 | required List data, 15 | required Canvas canvas, 16 | required BaseChartCanvas chartCanvas, 17 | required BaseLayoutConfig config, 18 | }) { 19 | config as FixedBarLayoutConfig; 20 | 21 | if (config.delegate == null) return; 22 | 23 | /// 24 | var delegate = config.delegate!; 25 | var bounds = config.bounds; 26 | var gestureDelegate = config.gestureDelegate; 27 | 28 | /// x轴方向,两点之间的履历 29 | var itemWidth = delegate.domainPointSpacing; 30 | 31 | /// y轴方向每段高度。 32 | var itemHeight = bounds.height / delegate.hintLineNum; 33 | 34 | /// 1s时长对应的宽度,全程24小时,两个点之间的跨度为1小时。 35 | var dw = itemWidth / 3600; // 3600s为1小时 36 | 37 | /// bar高度 38 | var barHeight = delegate.barStyle?.height ?? 0; 39 | 40 | /// bubble 距离bar 右侧的距离 41 | var bubblePadding = 5; 42 | 43 | for (var index = 0; index < data.length; index++) { 44 | var model = data[index]; 45 | int seconds = model.time.difference(config.startDate).inSeconds; 46 | var offset = Offset( 47 | bounds.left + seconds * dw, 48 | bounds.bottom - model.index * itemHeight - barHeight, 49 | ); 50 | 51 | /// 绘制Rect 52 | chartCanvas.drawRect( 53 | canvas: canvas, 54 | fill: model.color, 55 | stroke: delegate.barStyle?.stroke, 56 | strokeWidthPx: delegate.barStyle?.strokeWidth, 57 | bounds: Rectangle(offset.dx, offset.dy, dw * model.duration, barHeight), 58 | translate: gestureDelegate?.offset, 59 | clipBounds: Rectangle( 60 | bounds.left - (gestureDelegate?.offset.dx ?? 0), 61 | bounds.top, 62 | bounds.width, 63 | bounds.height, 64 | ), 65 | ); 66 | 67 | /// 绘制气泡 68 | if (model.hasBubble) { 69 | var style = config.popupSpec?.bubbleSpec; 70 | if (style == null) return; 71 | // 气泡与bar垂直对齐,并且距离bar右侧的距离5px 72 | var end = Offset( 73 | dw * model.duration - bubblePadding, barHeight.toDouble() / 2); 74 | var pointer = offset + end; 75 | chartCanvas.drawPoint( 76 | canvas: canvas, 77 | offset: pointer, 78 | radius: style.radius, 79 | fill: style.fill, 80 | strokeWidthPx: style.strokeWidthPx, 81 | stroke: style.stroke, 82 | translate: gestureDelegate?.offset, 83 | clipBounds: Rectangle( 84 | bounds.left - (gestureDelegate?.offset.dx ?? 0), 85 | bounds.top, 86 | bounds.width, 87 | bounds.height, 88 | ), 89 | ); 90 | } 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /lib/chart/impl/bar/fixed_bar_layout_impl.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_chart/chart/common/axis_delegate.dart'; 5 | import 'package:flutter_chart/chart/common/base_layout_config.dart'; 6 | import 'package:flutter_chart/chart/common/find.dart'; 7 | import 'package:flutter_chart/chart/common/gesture_delegate.dart'; 8 | import 'package:flutter_chart/chart/common/popup_spec.dart'; 9 | import 'package:flutter_chart/chart/model/chart_data_bar.dart'; 10 | import 'package:intl/intl.dart'; 11 | 12 | /// bar charts配置 13 | class FixedBarLayoutConfig extends BaseLayoutConfig { 14 | FixedBarLayoutConfig({ 15 | required super.data, 16 | required super.size, 17 | DateTime? startDateTime, 18 | super.axisCount, 19 | super.delegate, 20 | super.gestureDelegate, 21 | super.popupSpec, 22 | super.padding, 23 | super.initializePosition, 24 | }) : 25 | // 默认从当日的零时开始 26 | startDate = startDateTime ?? 27 | DateTime( 28 | DateTime.now().year, 29 | DateTime.now().month, 30 | DateTime.now().day, 31 | ); 32 | 33 | @override 34 | FixedBarLayoutConfig copyWith({ 35 | List? data, 36 | Size? size, 37 | int? axisCount, 38 | int? initializePosition, 39 | DateTime? startDate, 40 | AxisDelegate? delegate, 41 | GestureDelegate? gestureDelegate, 42 | PopupSpec? popupSpec, 43 | EdgeInsets? padding, 44 | }) { 45 | return FixedBarLayoutConfig( 46 | data: data ?? this.data, 47 | size: size ?? this.size, 48 | startDateTime: startDate ?? this.startDate, 49 | axisCount: axisCount ?? this.axisCount, 50 | initializePosition: initializePosition ?? this.initializePosition, 51 | delegate: delegate ?? this.delegate, 52 | gestureDelegate: gestureDelegate ?? this.gestureDelegate, 53 | popupSpec: popupSpec ?? this.popupSpec, 54 | padding: padding ?? this.padding, 55 | ); 56 | } 57 | 58 | /// x轴的开始时间,默认为当日的凌晨 59 | final DateTime startDate; 60 | 61 | /// 开始时间的秒数 62 | int get startTime { 63 | var hour = startDate.hour; 64 | var minute = startDate.minute; 65 | var seconds = startDate.second + minute * 60 + hour * 3600; 66 | return seconds; 67 | } 68 | 69 | /// 获取x轴指定位置的值 07:00 70 | /// 优先级比[AxisDelegate.xAxisFormatter]高。 71 | @override 72 | String? xAxisValue(int index) { 73 | var hour = index; 74 | var date = DateTime(startDate.year, startDate.month, startDate.day, hour); 75 | date = date.add(Duration(seconds: startTime)); 76 | var str = DateFormat('HH:mm').format(date); 77 | if ('00:00' == str && date.day != startDate.day) { 78 | return DateFormat('MM-dd').format(date); 79 | } 80 | return str; 81 | } 82 | 83 | /// 拖拽的最大宽度 84 | @override 85 | double? get draggableWidth => size.width - padding.horizontal; 86 | 87 | /// 初始选中点坐标 88 | @override 89 | Offset? getInitializeOffset() { 90 | if (delegate == null || 91 | initializePosition == null || 92 | initializePosition! < 0 || 93 | data.isEmpty) { 94 | return null; 95 | } 96 | // 目标点位置 97 | var position = min(initializePosition!, data.length - 1); 98 | // 两点之间的距离 99 | var itemWidth = delegate!.domainPointSpacing; 100 | // 当前拖拽的偏移量 101 | var dragX = gestureDelegate?.offset.dx ?? 0; 102 | 103 | /// y轴方向每段高度。 104 | var itemHeight = bounds.height / delegate!.hintLineNum; 105 | 106 | /// 1s时长对应的宽度,全程24小时,两个点之间的跨度为1小时。 107 | var dw = itemWidth / 3600; // 3600s为1小时 108 | 109 | /// bar高度 110 | var barHeight = 9; 111 | 112 | /// bubble 距离bar 右侧的距离 113 | var bubblePadding = 5; 114 | 115 | var model = data[position]; 116 | int seconds = model.time.difference(startDate).inSeconds + model.duration; 117 | return Offset( 118 | bounds.left + dragX + seconds * dw - bubblePadding, 119 | bounds.bottom - model.index * itemHeight - barHeight, 120 | ); 121 | } 122 | 123 | /// 根据手势触摸坐标查找指定数据点位 124 | @override 125 | ChartTargetFind? findTarget(Offset offset) { 126 | ChartTargetFind? find; 127 | if (delegate == null) return null; 128 | // 两点之间的距离 129 | var itemWidth = delegate!.domainPointSpacing; 130 | // 选择点的最小匹配宽度 131 | var minSelectWidth = delegate!.minSelectWidth ?? itemWidth; 132 | // 当前拖拽的偏移量 133 | var dragX = (gestureDelegate!.offset).dx; 134 | 135 | /// y轴方向每段高度。 136 | var itemHeight = bounds.height / delegate!.hintLineNum; 137 | 138 | /// 1s时长对应的宽度,全程24小时,两个点之间的跨度为1小时。 139 | var dw = itemWidth / 3600; // 3600s为1小时 140 | 141 | /// bar高度 142 | var barHeight = 9; 143 | 144 | /// bubble 距离bar 右侧的距离 145 | var bubblePadding = 5; 146 | 147 | for (var index = 0; index < data.length; index++) { 148 | var model = data[index]; 149 | if (!model.hasBubble) continue; 150 | 151 | int seconds = model.time.difference(startDate).inSeconds + model.duration; 152 | 153 | var curr = Offset( 154 | bounds.left + dragX + seconds * dw - bubblePadding, 155 | bounds.bottom - model.index * itemHeight - barHeight, 156 | ); 157 | if ((curr - offset).dx.abs() <= minSelectWidth) { 158 | find = ChartTargetFind(model, curr); 159 | break; 160 | } 161 | } 162 | return find; 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /lib/chart/impl/line/fixed_line_canvas_impl.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | import 'dart:ui'; 3 | 4 | import 'package:flutter_chart/chart/canvas/base_canvas.dart'; 5 | import 'package:flutter_chart/chart/canvas/base_chart_canvas.dart'; 6 | import 'package:flutter_chart/chart/common/base_layout_config.dart'; 7 | import 'package:flutter_chart/chart/impl/line/fixed_line_layout_impl.dart'; 8 | import 'package:flutter_chart/chart/model/chart_data_model.dart'; 9 | 10 | /// 绘制曲线 11 | class FixedLineCanvasImpl extends BaseCanvas { 12 | @override 13 | void draw({ 14 | required List data, 15 | required Canvas canvas, 16 | required BaseChartCanvas chartCanvas, 17 | required BaseLayoutConfig config, 18 | }) { 19 | config as FixedLayoutConfig; 20 | 21 | if (config.delegate == null) return; 22 | 23 | /// 24 | var delegate = config.delegate!; 25 | var bounds = config.bounds; 26 | var gestureDelegate = config.gestureDelegate; 27 | 28 | var points = []; 29 | 30 | var itemWidth = delegate.domainPointSpacing; 31 | var lineSize = config.delegate?.lineStyle?.strokeWidth ?? 0; 32 | var maxValue = config.maxValue; 33 | var maxHeight = bounds.height; 34 | 35 | /// 1s时长对应的宽度,全程24小时,两个点之间的跨度为1小时。 36 | var dw = itemWidth / 3600; // 3600s为1小时 37 | 38 | for (var index = 0; index < data.length; index++) { 39 | var model = data[index]; 40 | var seconds = model.xAxis.difference(config.startDate).inSeconds; 41 | var offset = Offset( 42 | bounds.left + dw * seconds, 43 | bounds.bottom - (config.yAxisValue(model) / maxValue) * maxHeight, 44 | ); 45 | points.add(offset); 46 | } 47 | 48 | /// 绘制曲线 49 | /// 这里加上[lineSize],是为了让曲线点能在top和bottom上完全显示出来。 50 | if (delegate.lineStyle?.isCurved ?? true) { 51 | chartCanvas.drawCurvedLine( 52 | canvas: canvas, 53 | points: points, 54 | color: delegate.lineStyle?.color, 55 | translate: gestureDelegate?.offset, 56 | strokeWidthPx: delegate.lineStyle?.strokeWidth, 57 | dashPattern: delegate.lineStyle?.dashPattern, 58 | roundEndCaps: true, 59 | clipBounds: Rectangle( 60 | bounds.left - lineSize - (gestureDelegate?.offset.dx ?? 0), 61 | bounds.top - lineSize, 62 | bounds.width + lineSize, 63 | bounds.height + lineSize, 64 | ), 65 | ); 66 | } else { 67 | chartCanvas.drawLine( 68 | canvas: canvas, 69 | points: points, 70 | color: delegate.lineStyle?.color, 71 | translate: gestureDelegate?.offset, 72 | strokeWidthPx: delegate.lineStyle?.strokeWidth, 73 | dashPattern: delegate.lineStyle?.dashPattern, 74 | roundEndCaps: true, 75 | clipBounds: Rectangle( 76 | bounds.left - lineSize - (gestureDelegate?.offset.dx ?? 0), 77 | bounds.top - lineSize, 78 | bounds.width + lineSize, 79 | bounds.height + lineSize, 80 | ), 81 | ); 82 | } 83 | 84 | /// 绘制气泡 85 | var style = config.popupSpec?.bubbleSpec; 86 | if (style == null) return; 87 | for (var index = 0; index < data.length; index++) { 88 | var model = data[index]; 89 | if (model.hasBubble) { 90 | var model = data[index]; 91 | var seconds = model.xAxis.difference(config.startDate).inSeconds; 92 | var pointer = Offset( 93 | bounds.left + dw * seconds, 94 | bounds.bottom - (config.yAxisValue(model) / maxValue) * maxHeight, 95 | ); 96 | chartCanvas.drawPoint( 97 | canvas: canvas, 98 | offset: pointer, 99 | radius: style.radius, 100 | fill: style.fill, 101 | strokeWidthPx: style.strokeWidthPx, 102 | stroke: style.stroke, 103 | translate: gestureDelegate?.offset, 104 | clipBounds: Rectangle( 105 | bounds.left - (gestureDelegate?.offset.dx ?? 0), 106 | bounds.top - config.padding.top, 107 | bounds.width, 108 | bounds.height + config.padding.bottom, 109 | ), 110 | ); 111 | } 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /lib/chart/impl/line/fixed_line_layout_impl.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_chart/chart/common/axis_delegate.dart'; 5 | import 'package:flutter_chart/chart/common/base_layout_config.dart'; 6 | import 'package:flutter_chart/chart/common/find.dart'; 7 | import 'package:flutter_chart/chart/common/gesture_delegate.dart'; 8 | import 'package:flutter_chart/chart/common/popup_spec.dart'; 9 | import 'package:flutter_chart/chart/model/chart_data_model.dart'; 10 | import 'package:intl/intl.dart'; 11 | 12 | /// line charts配置 13 | class FixedLayoutConfig extends BaseLayoutConfig { 14 | FixedLayoutConfig({ 15 | required super.data, 16 | required super.size, 17 | DateTime? startDateTime, 18 | super.axisCount, 19 | super.delegate, 20 | super.gestureDelegate, 21 | super.popupSpec, 22 | super.padding, 23 | super.initializePosition, 24 | }) : 25 | // 默认从当日的零时开始 26 | startDate = startDateTime ?? 27 | DateTime( 28 | DateTime.now().year, 29 | DateTime.now().month, 30 | DateTime.now().day, 31 | ); 32 | 33 | @override 34 | FixedLayoutConfig copyWith({ 35 | List? data, 36 | int? axisCount, 37 | Size? size, 38 | int? initializePosition, 39 | DateTime? startDate, 40 | AxisDelegate? delegate, 41 | GestureDelegate? gestureDelegate, 42 | PopupSpec? popupSpec, 43 | EdgeInsets? padding, 44 | }) { 45 | return FixedLayoutConfig( 46 | data: data ?? this.data, 47 | size: size ?? this.size, 48 | startDateTime: startDate ?? this.startDate, 49 | axisCount: axisCount ?? this.axisCount, 50 | initializePosition: initializePosition ?? this.initializePosition, 51 | delegate: delegate ?? this.delegate, 52 | gestureDelegate: gestureDelegate ?? this.gestureDelegate, 53 | popupSpec: popupSpec ?? this.popupSpec, 54 | padding: padding ?? this.padding, 55 | ); 56 | } 57 | 58 | /// x轴的开始时间,默认为当日的凌晨 59 | final DateTime startDate; 60 | 61 | /// 本组数据的最大值 62 | double? _maxValue; 63 | 64 | @override 65 | double get maxValue { 66 | _maxValue ??= getMaxValue(data); 67 | return _maxValue!; 68 | } 69 | 70 | @override 71 | double getMaxValue(List data) { 72 | var value = 0.0; 73 | for (var model in data) { 74 | value = max(value, model.yAxis); 75 | } 76 | return value; 77 | } 78 | 79 | /// 获取y轴的数据值 80 | @override 81 | num yAxisValue(ChartDataModel data) => data.yAxis; 82 | 83 | /// 拖拽的最大宽度 84 | @override 85 | double? get draggableWidth => size.width - padding.horizontal; 86 | 87 | /// 开始时间的秒数 88 | int get startTime => startDate.millisecondsSinceEpoch ~/ 1000; 89 | 90 | /// 获取x轴指定位置的值 07:00 91 | /// 优先级比[AxisDelegate.xAxisFormatter]高。 92 | @override 93 | String? xAxisValue(int index) { 94 | var milliseconds = (startTime + 3600 * index) * 1000; 95 | var date = DateTime.fromMillisecondsSinceEpoch(milliseconds); 96 | var str = DateFormat('HH:mm').format(date); 97 | if ('00:00' == str && date.day != startDate.day) { 98 | return DateFormat('MM-dd').format(date); 99 | } 100 | return str; 101 | } 102 | 103 | /// 初始选中点坐标 104 | @override 105 | Offset? getInitializeOffset() { 106 | if (initializePosition == null || data.isEmpty) { 107 | return null; 108 | } 109 | // 目标点位置 110 | var position = min(initializePosition!, data.length - 1); 111 | // 两点之间的距离 112 | var itemWidth = delegate!.domainPointSpacing; 113 | // 当前拖拽的偏移量 114 | var dragX = (gestureDelegate?.offset ?? Offset.zero).dx; 115 | // 1s时长对应的宽度,全程24小时,两个点之间的跨度为1小时。 116 | var dw = itemWidth / 3600; // 3600s为1小时 117 | 118 | var model = data[position]; 119 | var seconds = model.xAxis.difference(startDate).inSeconds; 120 | return Offset( 121 | bounds.left + dragX + dw * seconds, 122 | bounds.bottom - yAxisValue(model) / maxValue * bounds.height, 123 | ); 124 | } 125 | 126 | /// 根据手势触摸坐标查找指定数据点位 127 | @override 128 | ChartTargetFind? findTarget(Offset offset) { 129 | ChartTargetFind? find; 130 | // 两点之间的距离 131 | var itemWidth = delegate!.domainPointSpacing; 132 | // 选择点的最小匹配宽度 133 | var minSelectWidth = delegate!.minSelectWidth ?? itemWidth; 134 | // 当前拖拽的偏移量 135 | var dragX = (gestureDelegate?.offset ?? Offset.zero).dx; 136 | // 1s时长对应的宽度,全程24小时,两个点之间的跨度为1小时。 137 | var dw = itemWidth / 3600; // 3600s为1小时 138 | 139 | for (var index = 0; index < data.length; index++) { 140 | var model = data[index]; 141 | var seconds = model.xAxis.difference(startDate).inSeconds; 142 | var curr = Offset( 143 | bounds.left + dragX + dw * seconds, 144 | bounds.bottom - yAxisValue(model) / maxValue * bounds.height, 145 | ); 146 | if ((curr - offset).dx.abs() <= minSelectWidth) { 147 | find = ChartTargetFind(model, curr); 148 | break; 149 | } 150 | } 151 | return find; 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /lib/chart/impl/line/line_canvas_impl.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | import 'dart:ui'; 3 | 4 | import 'package:flutter_chart/chart/canvas/base_canvas.dart'; 5 | import 'package:flutter_chart/chart/canvas/base_chart_canvas.dart'; 6 | import 'package:flutter_chart/chart/common/base_layout_config.dart'; 7 | import 'package:flutter_chart/chart/model/chart_data_model.dart'; 8 | 9 | /// 绘制曲线:一个横坐标对应一个点,两个点之间不允许绘制内容。 10 | /// 即:最小刻度即为一个点的距离。 11 | class LineCanvasImpl extends BaseCanvas { 12 | @override 13 | void draw({ 14 | required List data, 15 | required Canvas canvas, 16 | required BaseChartCanvas chartCanvas, 17 | required BaseLayoutConfig config, 18 | }) { 19 | if (config.delegate == null) return; 20 | 21 | /// 22 | var delegate = config.delegate!; 23 | var bounds = config.bounds; 24 | var gestureDelegate = config.gestureDelegate; 25 | 26 | var points = []; 27 | 28 | var itemWidth = delegate.domainPointSpacing; 29 | var lineSize = config.delegate?.lineStyle?.strokeWidth ?? 0; 30 | var maxValue = config.maxValue; 31 | var maxHeight = bounds.height; 32 | 33 | for (var index = 0; index < data.length; index++) { 34 | var model = data[index]; 35 | var offset = Offset( 36 | bounds.left + itemWidth * index, 37 | bounds.bottom - (config.yAxisValue(model) / maxValue) * maxHeight, 38 | ); 39 | points.add(offset); 40 | } 41 | 42 | /// 绘制曲线 43 | /// 这里加上[lineSize],是为了让曲线点能在top和bottom上完全显示出来。 44 | if (delegate.lineStyle?.isCurved ?? true) { 45 | chartCanvas.drawCurvedLine( 46 | canvas: canvas, 47 | points: points, 48 | color: delegate.lineStyle?.color, 49 | translate: gestureDelegate?.offset, 50 | strokeWidthPx: delegate.lineStyle?.strokeWidth, 51 | dashPattern: delegate.lineStyle?.dashPattern, 52 | roundEndCaps: true, 53 | clipBounds: Rectangle( 54 | bounds.left - lineSize - (gestureDelegate?.offset.dx ?? 0), 55 | bounds.top - lineSize, 56 | bounds.width + lineSize, 57 | bounds.height + lineSize, 58 | ), 59 | ); 60 | } else { 61 | chartCanvas.drawLine( 62 | canvas: canvas, 63 | points: points, 64 | color: delegate.lineStyle?.color, 65 | translate: gestureDelegate?.offset, 66 | strokeWidthPx: delegate.lineStyle?.strokeWidth, 67 | dashPattern: delegate.lineStyle?.dashPattern, 68 | roundEndCaps: true, 69 | clipBounds: Rectangle( 70 | bounds.left - lineSize - (gestureDelegate?.offset.dx ?? 0), 71 | bounds.top - lineSize, 72 | bounds.width + lineSize, 73 | bounds.height + lineSize, 74 | ), 75 | ); 76 | } 77 | 78 | /// 绘制气泡 79 | var style = config.popupSpec?.bubbleSpec; 80 | if (style == null) return; 81 | for (var index = 0; index < data.length; index++) { 82 | var model = data[index]; 83 | if (model.hasBubble) { 84 | var pointer = Offset( 85 | bounds.left + itemWidth * index, 86 | bounds.bottom - (config.yAxisValue(model) / maxValue) * maxHeight, 87 | ); 88 | chartCanvas.drawPoint( 89 | canvas: canvas, 90 | offset: pointer, 91 | radius: style.radius, 92 | fill: style.fill, 93 | strokeWidthPx: style.strokeWidthPx, 94 | stroke: style.stroke, 95 | translate: gestureDelegate?.offset, 96 | clipBounds: Rectangle( 97 | bounds.left - (gestureDelegate?.offset.dx ?? 0), 98 | bounds.top - config.padding.top, 99 | bounds.width, 100 | bounds.height + config.padding.bottom, 101 | ), 102 | ); 103 | } 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /lib/chart/impl/line/line_layout_impl.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_chart/chart/common/axis_delegate.dart'; 5 | import 'package:flutter_chart/chart/common/base_layout_config.dart'; 6 | import 'package:flutter_chart/chart/common/find.dart'; 7 | import 'package:flutter_chart/chart/common/gesture_delegate.dart'; 8 | import 'package:flutter_chart/chart/common/popup_spec.dart'; 9 | import 'package:flutter_chart/chart/model/chart_data_model.dart'; 10 | 11 | /// line charts配置 12 | /// 一个横坐标对应一个点,两个点之间不允许绘制内容。 13 | /// 即:最小刻度即为一个点的距离。 14 | class LineLayoutConfig extends BaseLayoutConfig { 15 | LineLayoutConfig({ 16 | required super.data, 17 | required super.size, 18 | super.axisCount, 19 | super.initializePosition, 20 | super.delegate, 21 | super.gestureDelegate, 22 | super.popupSpec, 23 | super.padding, 24 | }); 25 | 26 | @override 27 | LineLayoutConfig copyWith({ 28 | List? data, 29 | int? axisCount, 30 | Size? size, 31 | int? initializePosition, 32 | AxisDelegate? delegate, 33 | GestureDelegate? gestureDelegate, 34 | PopupSpec? popupSpec, 35 | EdgeInsets? padding, 36 | }) { 37 | return LineLayoutConfig( 38 | data: data ?? this.data, 39 | size: size ?? this.size, 40 | axisCount: axisCount ?? this.axisCount, 41 | initializePosition: initializePosition ?? this.initializePosition, 42 | delegate: delegate ?? this.delegate, 43 | gestureDelegate: gestureDelegate ?? this.gestureDelegate, 44 | popupSpec: popupSpec ?? this.popupSpec, 45 | padding: padding ?? this.padding, 46 | ); 47 | } 48 | 49 | /// 本组数据的最大值 50 | double? _maxValue; 51 | 52 | @override 53 | double get maxValue { 54 | _maxValue ??= getMaxValue(data); 55 | return _maxValue!; 56 | } 57 | 58 | @override 59 | double getMaxValue(List data) { 60 | var value = 0.0; 61 | for (var model in data) { 62 | value = max(value, model.yAxis); 63 | } 64 | return value; 65 | } 66 | 67 | /// 获取y轴的数据值 68 | @override 69 | num yAxisValue(ChartDataModel data) => data.yAxis; 70 | 71 | /// 拖拽的最大宽度 72 | @override 73 | double? get draggableWidth => size.width - padding.horizontal; 74 | 75 | /// 根据手势触摸坐标查找指定数据点位 76 | @override 77 | ChartTargetFind? findTarget(Offset offset) { 78 | ChartTargetFind? find; 79 | // 两点之间的距离 80 | var itemWidth = delegate!.domainPointSpacing; 81 | // 选择点的最小匹配宽度 82 | var minSelectWidth = delegate!.minSelectWidth ?? itemWidth; 83 | // 当前拖拽的偏移量 84 | var dragX = (gestureDelegate?.offset ?? Offset.zero).dx; 85 | 86 | for (var index = 0; index < data.length; index++) { 87 | var model = data[index]; 88 | var curr = Offset( 89 | bounds.left + dragX + itemWidth * index, 90 | bounds.bottom - yAxisValue(model) / maxValue * bounds.height, 91 | ); 92 | if ((curr - offset).dx.abs() <= minSelectWidth) { 93 | find = ChartTargetFind(model, curr); 94 | break; 95 | } 96 | } 97 | return find; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /lib/chart/model/chart_data_bar.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | /// 白天行动轨迹、深浅睡眠 4 | class ChartDataBar implements Comparable { 5 | /// 对应与y轴刻度的索引 6 | final int index; 7 | 8 | /// 开始时间 9 | final DateTime time; 10 | 11 | /// 持续时长 12 | final int duration; 13 | 14 | /// 填充色 15 | final Color color; 16 | 17 | /// 是否有气泡点 18 | final bool hasBubble; 19 | 20 | const ChartDataBar({ 21 | required this.index, 22 | required this.time, 23 | required this.duration, 24 | Color? color, 25 | bool? hasBubble, 26 | }) : color = color ?? Colors.transparent, 27 | hasBubble = hasBubble ?? false; 28 | 29 | @override 30 | int compareTo(ChartDataBar other) => time.compareTo(other.time); 31 | 32 | @override 33 | String toString() { 34 | return '{"index":"$index","time":"$time","duration":"$duration","hasBubble":"$hasBubble","color":"$color"}'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lib/chart/model/chart_data_model.dart: -------------------------------------------------------------------------------- 1 | /// Chart 数据源 2 | class ChartDataModel implements Comparable { 3 | final double yAxis; // y轴数据 4 | /// 时间 5 | final DateTime xAxis; // x轴数据,单位是秒,时间戳 6 | /// 是否有气泡点 7 | final bool hasBubble; 8 | 9 | const ChartDataModel({ 10 | required this.yAxis, 11 | required this.xAxis, 12 | this.hasBubble = false, 13 | }); 14 | 15 | @override 16 | int compareTo(ChartDataModel other) => xAxis.compareTo(other.xAxis); 17 | 18 | @override 19 | String toString() { 20 | return '{"xAxis":"$xAxis","yAxis":$yAxis,"hasBubble":$hasBubble}'; 21 | } 22 | } -------------------------------------------------------------------------------- /lib/chart/painter/base_painter.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_chart/chart/chart_bean.dart'; 3 | 4 | /// Base 5 | class BasePainter extends CustomPainter { 6 | @override 7 | void paint(Canvas canvas, Size size) {} 8 | 9 | @override 10 | bool shouldRepaint(CustomPainter oldDelegate) { 11 | return true; 12 | } 13 | 14 | /// 计算极值 最大值,最小值 15 | List calculateMaxMin(List? chatBeans) { 16 | if (chatBeans == null || chatBeans.length == 0) return [0, 0]; 17 | double max = 0.0, min = 0.0; 18 | for (ChartBean bean in chatBeans) { 19 | if (max < bean.y) { 20 | max = bean.y; 21 | } 22 | if (min > bean.y) { 23 | min = bean.y; 24 | } 25 | } 26 | return [max, min]; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/chart/painter/chart_pie_painter.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_chart/chart/painter/base_painter.dart'; 5 | 6 | import '../chart_pie_bean.dart'; 7 | 8 | /// 饼图 9 | class ChartPiePainter extends BasePainter { 10 | double value; //当前动画值 11 | List? chartBeans; 12 | late double startX, endX, startY, endY; 13 | double? R, centerR; //圆弧半径,中心圆半径 14 | late double centerX, centerY; //圆心 15 | double fontSize; //刻度文本大小 16 | Color? fontColor; //文本颜色 17 | Color? centerColor; //中心圆颜色 18 | static const double basePadding = 16; //默认的边距 19 | static const Color defaultColor = Colors.deepPurple; 20 | 21 | ChartPiePainter( 22 | this.chartBeans, { 23 | this.value = 1, 24 | this.R, 25 | this.centerR = 0, 26 | this.centerColor = defaultColor, 27 | this.fontSize = 12, 28 | this.fontColor, 29 | }); 30 | 31 | @override 32 | void paint(Canvas canvas, Size size) { 33 | init(size); 34 | drawPie(canvas); //画圆弧 35 | drawCenter(canvas); //画中心圆 36 | } 37 | 38 | @override 39 | bool shouldRepaint(ChartPiePainter oldDelegate) { 40 | return oldDelegate.value != value; 41 | } 42 | 43 | /// 初始化 44 | init(Size size) { 45 | startX = basePadding; 46 | endX = size.width - basePadding; 47 | startY = size.height - basePadding; 48 | endY = basePadding; 49 | 50 | centerX = startX + (endX - startX) / 2; 51 | centerY = endY + (startY - endY) / 2; 52 | double xR = endX - centerX; 53 | double yR = startY - centerY; 54 | double realR = xR.compareTo(yR) > 0 ? yR : xR; 55 | 56 | if (R == null || R == 0) { 57 | R = realR; 58 | } else { 59 | if (R! > realR) R = realR; 60 | } 61 | if (centerR! > R!) centerR = R; 62 | 63 | setPieAngle(); //计算角度 64 | } 65 | 66 | void drawPie(Canvas canvas) { 67 | if (chartBeans?.isEmpty ?? true) { 68 | return; 69 | } 70 | Paint paint = Paint()..isAntiAlias = true; 71 | var rect = Rect.fromCircle(center: Offset(centerX, centerY), radius: R!); 72 | var realAngle = value * 2 * pi; //当前动画值对应的总角度 73 | for (var bean in chartBeans!) { 74 | var targetAngle = bean.startAngle! + bean.sweepAngle!; 75 | paint..color = bean.color!; 76 | if (targetAngle <= realAngle) { 77 | canvas.drawArc(rect, bean.startAngle!, bean.sweepAngle!, true, paint); 78 | } else if (bean.startAngle! < realAngle) { 79 | double sweepAngle = realAngle - bean.startAngle!; 80 | canvas.drawArc(rect, bean.startAngle!, sweepAngle, true, paint); 81 | } 82 | } 83 | } 84 | 85 | void drawCenter(Canvas canvas) { 86 | Paint paint = Paint() 87 | ..color = centerColor! 88 | ..style = PaintingStyle.fill 89 | ..strokeCap = StrokeCap.round 90 | ..isAntiAlias = true; 91 | canvas.drawCircle(Offset(centerX, centerY), centerR!, paint); 92 | } 93 | 94 | /// 计算各个扇形的起始角度 95 | setPieAngle() { 96 | if (chartBeans?.isEmpty ?? true) { 97 | return; 98 | } 99 | double total = getTotal(chartBeans!); 100 | double rate = 0; 101 | double startAngle = 0; // 扇形开始的角度 正上方 102 | for (var bean in chartBeans!) { 103 | rate = bean.value / total; //当前对象值所占比例 104 | bean.rate = rate; 105 | bean.startAngle = startAngle; 106 | bean.sweepAngle = rate * 2 * pi; //当前对象所占比例 对应的 角度 107 | startAngle += bean.sweepAngle!; 108 | } 109 | } 110 | 111 | /// 计算数据总和 112 | getTotal(List data) { 113 | double total = 0; 114 | for (var bean in data) { 115 | total += bean.value; 116 | } 117 | return total; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /lib/chart/view/chart_pie.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/foundation.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_chart/chart/painter/chart_pie_painter.dart'; 4 | 5 | import '../chart_pie_bean.dart'; 6 | 7 | /// 饼状图 8 | class ChartPie extends StatefulWidget { 9 | final Duration duration; 10 | final Size size; 11 | final List chartBeans; 12 | final Color? backgroundColor; //绘制的背景色 13 | final bool isAnimation; //是否执行动画 14 | final double? R, centerR; //半径,中心圆半径 15 | final Color? centerColor; //中心圆颜色 16 | final double fontSize; //刻度文本大小 17 | final Color? fontColor; //文本颜色 18 | 19 | const ChartPie({ 20 | Key? key, 21 | required this.size, 22 | required this.chartBeans, 23 | this.duration = const Duration(milliseconds: 800), 24 | this.backgroundColor, 25 | this.isAnimation = true, 26 | this.R, 27 | this.centerR, 28 | this.centerColor, 29 | this.fontSize = 12, 30 | this.fontColor, 31 | }) : super(key: key); 32 | 33 | @override 34 | State createState() => ChartPieState(); 35 | } 36 | 37 | class ChartPieState extends State 38 | with SingleTickerProviderStateMixin { 39 | AnimationController? _controller; 40 | double _value = 0; 41 | double begin = 0.0, end = 360; 42 | 43 | @override 44 | void initState() { 45 | super.initState(); 46 | if (widget.isAnimation) { 47 | _controller = AnimationController(vsync: this, duration: widget.duration); 48 | Tween(begin: begin, end: end).animate(_controller!) 49 | ..addStatusListener((status) { 50 | if (status == AnimationStatus.completed) { 51 | if (kDebugMode) { 52 | print('绘制完成'); 53 | } 54 | } 55 | }) 56 | ..addListener(() { 57 | if (mounted) { 58 | _value = _controller!.value; 59 | setState(() {}); 60 | } 61 | }); 62 | _controller!.forward(); 63 | } 64 | } 65 | 66 | @override 67 | void dispose() { 68 | if (_controller != null) _controller!.dispose(); 69 | super.dispose(); 70 | } 71 | 72 | @override 73 | Widget build(BuildContext context) { 74 | var painter = ChartPiePainter( 75 | widget.chartBeans, 76 | value: _value, 77 | R: widget.R, 78 | centerR: widget.centerR, 79 | centerColor: widget.centerColor, 80 | fontSize: widget.fontSize, 81 | fontColor: widget.fontColor, 82 | ); 83 | return CustomPaint( 84 | size: widget.size, 85 | foregroundPainter: widget.backgroundColor != null ? painter : null, 86 | child: widget.backgroundColor != null 87 | ? Container( 88 | width: widget.size.width, 89 | height: widget.size.height, 90 | color: widget.backgroundColor, 91 | ) 92 | : null, 93 | painter: widget.backgroundColor == null ? painter : null); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /lib/flutter_chart.dart: -------------------------------------------------------------------------------- 1 | library flutter_chart; 2 | 3 | export 'package:flutter_chart/chart/chart_bean.dart'; 4 | export 'package:flutter_chart/chart/chart_pie_bean.dart'; 5 | export 'package:flutter_chart/chart/view/chart_bar.dart'; 6 | export 'package:flutter_chart/chart/view/chart_line.dart'; 7 | export 'package:flutter_chart/chart/view/chart_pie.dart'; 8 | -------------------------------------------------------------------------------- /pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | async: 5 | dependency: transitive 6 | description: 7 | name: async 8 | url: "https://pub.flutter-io.cn" 9 | source: hosted 10 | version: "2.8.2" 11 | boolean_selector: 12 | dependency: transitive 13 | description: 14 | name: boolean_selector 15 | url: "https://pub.flutter-io.cn" 16 | source: hosted 17 | version: "2.1.0" 18 | characters: 19 | dependency: transitive 20 | description: 21 | name: characters 22 | url: "https://pub.flutter-io.cn" 23 | source: hosted 24 | version: "1.2.0" 25 | charcode: 26 | dependency: transitive 27 | description: 28 | name: charcode 29 | url: "https://pub.flutter-io.cn" 30 | source: hosted 31 | version: "1.3.1" 32 | clock: 33 | dependency: transitive 34 | description: 35 | name: clock 36 | url: "https://pub.flutter-io.cn" 37 | source: hosted 38 | version: "1.1.0" 39 | collection: 40 | dependency: transitive 41 | description: 42 | name: collection 43 | url: "https://pub.flutter-io.cn" 44 | source: hosted 45 | version: "1.16.0" 46 | fake_async: 47 | dependency: transitive 48 | description: 49 | name: fake_async 50 | url: "https://pub.flutter-io.cn" 51 | source: hosted 52 | version: "1.3.0" 53 | flutter: 54 | dependency: "direct main" 55 | description: flutter 56 | source: sdk 57 | version: "0.0.0" 58 | flutter_test: 59 | dependency: "direct dev" 60 | description: flutter 61 | source: sdk 62 | version: "0.0.0" 63 | intl: 64 | dependency: "direct main" 65 | description: 66 | name: intl 67 | url: "https://pub.flutter-io.cn" 68 | source: hosted 69 | version: "0.17.0" 70 | matcher: 71 | dependency: transitive 72 | description: 73 | name: matcher 74 | url: "https://pub.flutter-io.cn" 75 | source: hosted 76 | version: "0.12.11" 77 | material_color_utilities: 78 | dependency: transitive 79 | description: 80 | name: material_color_utilities 81 | url: "https://pub.flutter-io.cn" 82 | source: hosted 83 | version: "0.1.4" 84 | meta: 85 | dependency: transitive 86 | description: 87 | name: meta 88 | url: "https://pub.flutter-io.cn" 89 | source: hosted 90 | version: "1.7.0" 91 | path: 92 | dependency: transitive 93 | description: 94 | name: path 95 | url: "https://pub.flutter-io.cn" 96 | source: hosted 97 | version: "1.8.1" 98 | sky_engine: 99 | dependency: transitive 100 | description: flutter 101 | source: sdk 102 | version: "0.0.99" 103 | source_span: 104 | dependency: transitive 105 | description: 106 | name: source_span 107 | url: "https://pub.flutter-io.cn" 108 | source: hosted 109 | version: "1.8.2" 110 | stack_trace: 111 | dependency: transitive 112 | description: 113 | name: stack_trace 114 | url: "https://pub.flutter-io.cn" 115 | source: hosted 116 | version: "1.10.0" 117 | stream_channel: 118 | dependency: transitive 119 | description: 120 | name: stream_channel 121 | url: "https://pub.flutter-io.cn" 122 | source: hosted 123 | version: "2.1.0" 124 | string_scanner: 125 | dependency: transitive 126 | description: 127 | name: string_scanner 128 | url: "https://pub.flutter-io.cn" 129 | source: hosted 130 | version: "1.1.0" 131 | term_glyph: 132 | dependency: transitive 133 | description: 134 | name: term_glyph 135 | url: "https://pub.flutter-io.cn" 136 | source: hosted 137 | version: "1.2.0" 138 | test_api: 139 | dependency: transitive 140 | description: 141 | name: test_api 142 | url: "https://pub.flutter-io.cn" 143 | source: hosted 144 | version: "0.4.9" 145 | vector_math: 146 | dependency: transitive 147 | description: 148 | name: vector_math 149 | url: "https://pub.flutter-io.cn" 150 | source: hosted 151 | version: "2.1.2" 152 | sdks: 153 | dart: ">=2.17.0 <3.0.0" 154 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_chart 2 | description: Flutter Canvas draws Bezier curves and histograms, embeds animations,The gesture touch function for graphs, line graphs, and histograms is now supported. 3 | version: 0.2.0 4 | homepage: https://github.com/good-good-study/flutter_chart 5 | 6 | environment: 7 | sdk: '>=2.17.0 <3.0.0' 8 | 9 | dependencies: 10 | flutter: 11 | sdk: flutter 12 | 13 | intl: ^0.17.0 14 | 15 | dev_dependencies: 16 | flutter_test: 17 | sdk: flutter 18 | 19 | flutter: 20 | 21 | -------------------------------------------------------------------------------- /test/flutter_chart_test.dart: -------------------------------------------------------------------------------- 1 | void main() {} 2 | -------------------------------------------------------------------------------- /ui_chart_all.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/ui_chart_all.gif -------------------------------------------------------------------------------- /ui_chart_bar.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/ui_chart_bar.gif -------------------------------------------------------------------------------- /ui_chart_curve.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/ui_chart_curve.gif -------------------------------------------------------------------------------- /ui_chart_line.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/good-good-study/flutter_chart/81ce6e355e47da19e40e1c0939128d7cb2fe3717/ui_chart_line.gif --------------------------------------------------------------------------------