├── .gitignore
├── LICENSE
├── README.md
├── README.zh-CN.md
├── preview
├── 1.png
├── 2.png
├── ali.jpg
└── wechat-m.jpeg
└── stocks
├── .gitignore
├── .metadata
├── README.md
├── android
├── .gitignore
├── app
│ ├── build.gradle
│ └── src
│ │ ├── debug
│ │ └── AndroidManifest.xml
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── kotlin
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── stocks
│ │ │ │ └── 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
├── 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
├── components
│ ├── button
│ │ └── button_ wrapped.dart
│ ├── chart
│ │ ├── chart_container.dart
│ │ ├── chart_models.dart
│ │ ├── chart_tools.dart
│ │ ├── chart_view.dart
│ │ └── renders
│ │ │ ├── chart_kline_render.dart
│ │ │ ├── chart_render_tools.dart
│ │ │ └── chart_vol_render.dart
│ ├── exchange_symbols
│ │ └── exchange_symbols.dart
│ ├── search
│ │ └── search.dart
│ ├── space
│ │ └── space.dart
│ ├── text
│ │ └── text.dart
│ └── tooltip
│ │ └── tooltip.dart
├── main.dart
├── manager
│ ├── exchange_manager.dart
│ ├── localizations_manager.dart
│ ├── method_channel_manger.dart
│ ├── responsive.dart
│ ├── symbols_manager.dart
│ ├── theme_manager.dart
│ └── themes
│ │ ├── dark.json
│ │ └── default.json
├── models
│ ├── dataModel.dart
│ └── tokenModel.dart
├── nav
│ └── nav.dart
├── net
│ ├── api_manager.dart
│ ├── hq_net.dart
│ ├── http.dart
│ ├── net_adapter.dart
│ └── socket_manager.dart
├── pages
│ ├── detail_view
│ │ └── detail_view.dart
│ ├── list_view
│ │ └── list_view.dart
│ ├── main_view
│ │ └── main_view.dart
│ ├── menu_view
│ │ └── menu_view.dart
│ ├── page_action.dart
│ └── test
│ │ └── test.dart
├── src
│ └── map.json
├── tools
│ ├── GNLog.dart
│ └── tools.dart
└── window
│ └── window.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
│ └── stocksProfile.entitlements
├── pubspec.yaml
├── test
└── widget_test.dart
├── web
├── favicon.png
├── icons
│ ├── Icon-192.png
│ └── Icon-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
├── run_loop.cpp
├── run_loop.h
├── runner.exe.manifest
├── utils.cpp
├── utils.h
├── win32_window.cpp
└── win32_window.h
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://www.dartlang.org/guides/libraries/private-files
2 |
3 | # Files and directories created by pub
4 | .dart_tool/
5 | .packages
6 | build/
7 | # If you're building an application, you may want to check-in your pubspec.lock
8 | pubspec.lock
9 |
10 | # Directory created by dartdoc
11 | # If you don't generate documentation locally you can remove this line.
12 | doc/api/
13 |
14 | # Avoid committing generated Javascript files:
15 | *.dart.js
16 | *.info.json # Produced by the --dump-info flag.
17 | *.js # When generated by dart2js. Don't specify *.js if your
18 | # project includes source files written in JavaScript.
19 | *.js_
20 | *.js.deps
21 | *.js.map
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Stocks
2 |
3 | Flutter KLine Chart
4 |
5 | [](./README.zh-CN.md)
7 |
8 | ## Desc
9 |
10 | Tokens kline
11 |
12 | ### Servers
13 |
14 | websocket
15 |
16 | - Binance
17 | - Huobi
18 | - OKEX
19 |
20 | ## Screenshot
21 |
22 | 
23 | 
24 |
25 | ## Start
26 |
27 | __Recommend: Mac OS > iOS > Android__
28 |
29 | ## Attention
30 |
31 | ### China
32 |
33 | set Proxy:
34 |
35 | lib/net/net_adapter.dart
36 | - http_proxy default: 127.0.0.1:7890
37 | - https_proxy default: 127.0.0.1:7890
38 |
39 | close proxy:
40 |
41 | lib/net/net_adapter.dart
42 | - http_proxy = ""
43 | - https_proxy = ""
44 |
45 | ### Other Region
46 |
47 | close Proxy:
48 |
49 | lib/net/net_adapter.dart
50 | - http_proxy = ""
51 | - https_proxy = ""
52 |
53 | ## Warning
54 |
55 | no run web
56 | ## Hope to help you
57 |
58 | 如代码有迷糊行为请吐槽,谢谢
59 |
--------------------------------------------------------------------------------
/README.zh-CN.md:
--------------------------------------------------------------------------------
1 | # Stocks
2 |
3 | Flutter KLine Chart
4 |
5 | ## Desc
6 |
7 | Tokens kline
8 |
9 | ### Servers
10 |
11 | websocket
12 |
13 | - Binance
14 | - Huobi
15 | - OKEX
16 |
17 | ## Screenshot
18 |
19 | 
20 | 
21 |
22 | ## Start
23 |
24 | 推荐运行在 Mac os 平台,其次 iOS,Android
25 |
26 | ## Attention
27 |
28 | ### 大陆
29 |
30 | 默认设置了本地代理,由于不可描述原因,需要代理,科学上网
31 |
32 | set Proxy: 设置代理
33 |
34 | lib/net/net_adapter.dart
35 | - http_proxy default: 127.0.0.1:7890
36 | - https_proxy default: 127.0.0.1:7890
37 |
38 | close proxy: 关闭代理
39 |
40 | lib/net/net_adapter.dart
41 | - http_proxy = "" // 给空字符串
42 | - https_proxy = "" // 给空字符串
43 |
44 | ### Other Region
45 |
46 | close Proxy:
47 |
48 | lib/net/net_adapter.dart
49 | - http_proxy = ""
50 | - https_proxy = ""
51 |
52 | ## Warning
53 |
54 | 不要运行 web 平台,因为没有适配,可能会发生一些莫名其妙 bug
55 | no run web
56 |
57 | ## Hope to help you
58 |
59 | 如代码有迷糊行为请吐槽,谢谢
60 |
61 | ### 要不请我喝杯奶茶胖死我 😜
62 |
63 |
64 |

65 |

66 |
--------------------------------------------------------------------------------
/preview/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/preview/1.png
--------------------------------------------------------------------------------
/preview/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/preview/2.png
--------------------------------------------------------------------------------
/preview/ali.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/preview/ali.jpg
--------------------------------------------------------------------------------
/preview/wechat-m.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/preview/wechat-m.jpeg
--------------------------------------------------------------------------------
/stocks/.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 | # The .vscode folder contains launch configuration and tasks you configure in
19 | # VS Code which you may wish to be included in version control, so this line
20 | # is commented out by default.
21 | #.vscode/
22 |
23 | # Flutter/Dart/Pub related
24 | **/doc/api/
25 | **/ios/Flutter/.last_build_id
26 | .dart_tool/
27 | .flutter-plugins
28 | .flutter-plugins-dependencies
29 | .packages
30 | .pub-cache/
31 | .pub/
32 | /build/
33 |
34 | # Web related
35 | lib/generated_plugin_registrant.dart
36 |
37 | # Symbolication related
38 | app.*.symbols
39 |
40 | # Obfuscation related
41 | app.*.map.json
42 |
43 | # Android Studio will place build artifacts here
44 | /android/app/debug
45 | /android/app/profile
46 | /android/app/release
47 |
--------------------------------------------------------------------------------
/stocks/.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: f4abaa0735eba4dfd8f33f73363911d63931fe03
8 | channel: stable
9 |
10 | project_type: app
11 |
--------------------------------------------------------------------------------
/stocks/README.md:
--------------------------------------------------------------------------------
1 | # stocks
2 |
3 | A new Flutter project.
4 |
5 | ## Getting Started
6 |
7 | This project is a starting point for a Flutter application.
8 |
9 | A few resources to get you started if this is your first Flutter project:
10 |
11 | - [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
12 | - [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)
13 |
14 | For help getting started with Flutter, view our
15 | [online documentation](https://flutter.dev/docs), which offers tutorials,
16 | samples, guidance on mobile development, and a full API reference.
17 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/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 30
30 |
31 | sourceSets {
32 | main.java.srcDirs += 'src/main/kotlin'
33 | }
34 |
35 | defaultConfig {
36 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
37 | applicationId "com.example.stocks"
38 | minSdkVersion 16
39 | targetSdkVersion 30
40 | versionCode flutterVersionCode.toInteger()
41 | versionName flutterVersionName
42 | }
43 |
44 | buildTypes {
45 | release {
46 | // TODO: Add your own signing config for the release build.
47 | // Signing with the debug keys for now, so `flutter run --release` works.
48 | signingConfig signingConfigs.debug
49 | }
50 | }
51 | }
52 |
53 | flutter {
54 | source '../..'
55 | }
56 |
57 | dependencies {
58 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
59 | }
60 |
--------------------------------------------------------------------------------
/stocks/android/app/src/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/stocks/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
6 |
13 |
17 |
21 |
26 |
30 |
31 |
32 |
33 |
34 |
35 |
37 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/stocks/android/app/src/main/kotlin/com/example/stocks/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.example.stocks
2 |
3 | import io.flutter.embedding.android.FlutterActivity
4 |
5 | class MainActivity: FlutterActivity() {
6 | }
7 |
--------------------------------------------------------------------------------
/stocks/android/app/src/main/res/drawable-v21/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/stocks/android/app/src/main/res/drawable/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/stocks/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/stocks/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/stocks/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/stocks/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/stocks/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/stocks/android/app/src/main/res/values-night/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/stocks/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/stocks/android/app/src/profile/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/stocks/android/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = '1.3.50'
3 | repositories {
4 | google()
5 | jcenter()
6 | }
7 |
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:4.1.0'
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | google()
17 | jcenter()
18 | }
19 | }
20 |
21 | rootProject.buildDir = '../build'
22 | subprojects {
23 | project.buildDir = "${rootProject.buildDir}/${project.name}"
24 | project.evaluationDependsOn(':app')
25 | }
26 |
27 | task clean(type: Delete) {
28 | delete rootProject.buildDir
29 | }
30 |
--------------------------------------------------------------------------------
/stocks/android/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Xmx1536M
2 | android.useAndroidX=true
3 | android.enableJetifier=true
4 |
--------------------------------------------------------------------------------
/stocks/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-6.7-all.zip
7 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/ios/.gitignore:
--------------------------------------------------------------------------------
1 | *.mode1v3
2 | *.mode2v3
3 | *.moved-aside
4 | *.pbxuser
5 | *.perspectivev3
6 | **/*sync/
7 | .sconsign.dblite
8 | .tags*
9 | **/.vagrant/
10 | **/DerivedData/
11 | Icon?
12 | **/Pods/
13 | **/.symlinks/
14 | profile
15 | xcuserdata
16 | **/.generated/
17 | Flutter/App.framework
18 | Flutter/Flutter.framework
19 | Flutter/Flutter.podspec
20 | Flutter/Generated.xcconfig
21 | Flutter/ephemeral/
22 | Flutter/app.flx
23 | Flutter/app.zip
24 | Flutter/flutter_assets/
25 | Flutter/flutter_export_environment.sh
26 | ServiceDefinitions.json
27 | Runner/GeneratedPluginRegistrant.*
28 |
29 | # Exceptions to above rules.
30 | !default.mode1v3
31 | !default.mode2v3
32 | !default.pbxuser
33 | !default.perspectivev3
34 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/ios/Flutter/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include "Generated.xcconfig"
2 |
--------------------------------------------------------------------------------
/stocks/ios/Flutter/Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include "Generated.xcconfig"
2 |
--------------------------------------------------------------------------------
/stocks/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/stocks/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/stocks/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/stocks/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
75 |
81 |
82 |
83 |
84 |
86 |
87 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/stocks/ios/Runner.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/stocks/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/stocks/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png
--------------------------------------------------------------------------------
/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png
--------------------------------------------------------------------------------
/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png
--------------------------------------------------------------------------------
/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png
--------------------------------------------------------------------------------
/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png
--------------------------------------------------------------------------------
/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png
--------------------------------------------------------------------------------
/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png
--------------------------------------------------------------------------------
/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png
--------------------------------------------------------------------------------
/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png
--------------------------------------------------------------------------------
/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png
--------------------------------------------------------------------------------
/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png
--------------------------------------------------------------------------------
/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png
--------------------------------------------------------------------------------
/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png
--------------------------------------------------------------------------------
/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png
--------------------------------------------------------------------------------
/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png
--------------------------------------------------------------------------------
/stocks/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png
--------------------------------------------------------------------------------
/stocks/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png
--------------------------------------------------------------------------------
/stocks/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.
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/ios/Runner/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | stocks
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | $(FLUTTER_BUILD_NAME)
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | $(FLUTTER_BUILD_NUMBER)
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UISupportedInterfaceOrientations
30 |
31 | UIInterfaceOrientationPortrait
32 | UIInterfaceOrientationLandscapeLeft
33 | UIInterfaceOrientationLandscapeRight
34 |
35 | UISupportedInterfaceOrientations~ipad
36 |
37 | UIInterfaceOrientationPortrait
38 | UIInterfaceOrientationPortraitUpsideDown
39 | UIInterfaceOrientationLandscapeLeft
40 | UIInterfaceOrientationLandscapeRight
41 |
42 | UIViewControllerBasedStatusBarAppearance
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/stocks/ios/Runner/Runner-Bridging-Header.h:
--------------------------------------------------------------------------------
1 | #import "GeneratedPluginRegistrant.h"
2 |
--------------------------------------------------------------------------------
/stocks/lib/components/button/button_ wrapped.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:stocks/manager/theme_manager.dart';
3 |
4 | class GKWrappedButton extends MaterialButton {
5 | GKWrappedButton({
6 | required VoidCallback onPressed,
7 | Widget? child,
8 | }) : super(
9 | onPressed: onPressed,
10 | child: child,
11 | color: Colors.transparent,
12 | elevation: 0,
13 | enableFeedback: false,
14 | hoverElevation: 0,
15 | hoverColor: GNTheme().bGColorType(BGColorType.highlight),
16 | padding: EdgeInsets.all(16),
17 | );
18 | }
19 |
--------------------------------------------------------------------------------
/stocks/lib/components/chart/chart_models.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:stocks/manager/theme_manager.dart';
3 | import 'package:stocks/models/dataModel.dart';
4 |
5 | enum ChartType {
6 | Kline,
7 | Vol,
8 | FS,
9 | }
10 | enum ChartIndexType { MA }
11 |
12 | enum ChartMAIndexType { SPJ, CJL }
13 |
14 | class HqChartData extends HQData {
15 | bool isEmpty = false; // 是否为空模型,为 true 时候,为填充作用
16 | List ma = []; // 数据下标对应着,配置里指数配置的下标
17 | List cjlMa = [];
18 | int hqChartDataIndex = 0; // 原始数据下标
19 | }
20 |
21 | // 基础元素绘制属性
22 | class ChartLineBaseConfig {
23 | double lineWidth = 0.5;
24 | Color lineColor = Colors.grey.withAlpha(80);
25 | }
26 |
27 | class ChartFontBaseConfig {
28 | double fontSize = GNTheme().fontSizeType(FontSizeType.s);
29 | Color fontColor = GNTheme().fontColorType(FontColorType.bright);
30 | Color fontBackground = Colors.transparent;
31 | }
32 |
33 | class ChartElementBaseConfig {
34 | int minWidth = 10;
35 | int maxWidth = 20;
36 | int nowWidth = 10;
37 | }
38 |
39 | // 背景网格
40 | class GridConfig extends ChartLineBaseConfig with ChartFontBaseConfig {
41 | int row = 3;
42 | int column = 3;
43 | }
44 |
45 | // 指标图基础配置属性
46 | class ChartIndexBaseConfig {
47 | ChartIndexType indexType = ChartIndexType.MA;
48 | }
49 |
50 | class ChartMAIndexConfig extends ChartIndexBaseConfig with ChartLineBaseConfig {
51 | Color lineColor = Colors.yellowAccent;
52 | int ma = 5;
53 | ChartMAIndexType maIndexType = ChartMAIndexType.SPJ;
54 | }
55 |
56 | // 基础配置属性
57 | class ChartBaseConfig {
58 | int width = 500; // 宽度可以自适应
59 | int height = 300;
60 | double lineWidth = 1;
61 | ChartType type = ChartType.Kline;
62 | List maIndexTypes = []; // 需要的指标配置,需要在图上绘制的
63 |
64 | bool isAutoWidth = false;
65 | int paddingTop = 8;
66 | int paddingBottom = 8;
67 | int paddingRight = 100;
68 | Color buy = GNTheme().getZDColor(ZDColorType.up);
69 | Color sell = GNTheme().getZDColor(ZDColorType.down);
70 |
71 | GridConfig? gridConfig = GridConfig();
72 |
73 |
74 | }
75 |
76 | // 单独主图属性配置
77 |
78 | // kline
79 | class KlineChartConfig extends ChartBaseConfig with ChartElementBaseConfig {
80 | ChartType type = ChartType.Kline;
81 | }
82 |
83 | // vol
84 | class VolChartConfig extends ChartBaseConfig with ChartElementBaseConfig {
85 | int height = 100;
86 | ChartType type = ChartType.Vol;
87 | }
88 |
--------------------------------------------------------------------------------
/stocks/lib/components/chart/chart_tools.dart:
--------------------------------------------------------------------------------
1 | final double Precision = 0.5;
2 |
3 | class ChartTools {
4 | static double convertY(double source, double height, double max, double min) {
5 | return height - ((source - min) / (max - min)) * height;
6 | }
7 |
8 | static double yConvert(double source, double height, double max, double min) {
9 | return ((height - source) / height) * (max - min) + min;
10 | // return height - ((source - min) / (max - min)) * height;
11 | }
12 |
13 | static double convertH(double source, double height, double max, double min) {
14 | double h = (source / (max - min)) * height;
15 | return h < Precision ? Precision : h;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/stocks/lib/components/chart/chart_view.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:stocks/components/chart/chart_container.dart';
3 | import 'package:stocks/components/chart/chart_models.dart';
4 |
5 | class ChartView extends StatelessWidget {
6 | final List? datas;
7 | final List? configs;
8 | const ChartView({Key? key, this.datas, this.configs}) : super(key: key);
9 |
10 | @override
11 | Widget build(BuildContext context) {
12 | return OrientationBuilder(builder: (context, o) {
13 | return Container(
14 | child: ChartContainer(configs: configs ?? [], datas: datas ?? []),
15 | );
16 | });
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/stocks/lib/components/chart/renders/chart_render_tools.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'dart:math';
3 |
4 | final double Precision = 0.5;
5 |
6 | class ChartRenderTools {
7 | static drawCross(
8 | Canvas canvas,
9 | Paint paint,
10 | Size size,
11 | Offset point,
12 | ) {
13 | drawDash(canvas, paint, Offset(0, point.dy), Offset(size.width, point.dy));
14 | drawDash(canvas, paint, Offset(point.dx, 0), Offset(point.dx, size.height));
15 | }
16 |
17 | static drawRect(
18 | Canvas canvas,
19 | Paint paint,
20 | Offset offset,
21 | double width,
22 | double height,
23 | ) {
24 | if (height <= 1) {
25 | paint.strokeWidth = height <= Precision ? Precision : height;
26 | drawLine(canvas, paint, offset, Offset(offset.dx + width, offset.dy));
27 | } else {
28 | Rect r = Rect.fromLTWH(offset.dx, offset.dy, width, height);
29 | canvas.drawRect(r, paint);
30 | }
31 | }
32 |
33 | static drawLine(Canvas canvas, Paint paint, Offset from, Offset to) {
34 | if (Point(from.dx, from.dy).distanceTo(Point(to.dx, to.dy)) > 1) {
35 | canvas.drawLine(from, to, paint);
36 | }
37 | }
38 |
39 | static drawDash_(Canvas canvas, Paint paint, double length, Offset from,
40 | {int dashWidth = 5, int dashSpace = 5}) {
41 | double max = length;
42 | double startX = from.dx;
43 | final space = (dashSpace + dashWidth);
44 | while (startX < max) {
45 | canvas.drawLine(
46 | Offset(startX, from.dy), Offset(startX + dashWidth, from.dy), paint);
47 | startX += space;
48 | }
49 | }
50 |
51 | static drawDash(Canvas canvas, Paint paint, Offset from, Offset to,
52 | {int dashWidth = 5, int dashSpace = 5}) {
53 | // double max = (from.dx - to.dx) * (from.dx - to.dx) + (from.dy - to.dy) * (from.dy - to.dy);
54 | double max = Point(from.dx, from.dy).distanceTo(Point(to.dx, to.dy));
55 |
56 | double startX = from.dx;
57 | double startY = from.dy;
58 | int space = dashSpace + dashWidth;
59 | int num = max ~/ space;
60 | double h = (to.dy - from.dy).abs();
61 | double w = (to.dx - from.dx).abs();
62 | double sh = h / num;
63 | double sw = w / num;
64 | double d = dashWidth / space;
65 | double endx = startX + sw * d;
66 | double endy = startY + sh * d;
67 |
68 | double nowLength = 0;
69 | while (nowLength < max) {
70 | // double distance = Point(startX, startY).distanceTo(Point(sw, sh)) - dashSpace;
71 | drawLine(canvas, paint, Offset(startX, startY), Offset(endx, endy));
72 | startX += sw;
73 | startY += sh;
74 | endx += sw;
75 | endy += sh;
76 | nowLength += space;
77 | }
78 | }
79 |
80 | static int drawText(Canvas canvas, Paint paint, String text, Offset from,
81 | {TextStyle? textStyle, bool isFromLeftDraw = false}) {
82 | TextStyle ts = textStyle ?? TextStyle(color: paint.color, fontSize: 10);
83 | TextSpan span = TextSpan(text: text, style: ts);
84 | TextPainter tp = TextPainter(
85 | text: span,
86 | textAlign: TextAlign.left,
87 | textDirection: TextDirection.ltr);
88 | tp.layout();
89 | Offset from_ = from;
90 | int textOffset = tp.size.width.toInt();
91 | if (isFromLeftDraw) {
92 | from_ = Offset(from_.dx - textOffset, from_.dy);
93 | }
94 | tp.paint(canvas, from_);
95 | return textOffset;
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/stocks/lib/components/chart/renders/chart_vol_render.dart:
--------------------------------------------------------------------------------
1 | import 'dart:math';
2 | import 'package:flutter/material.dart';
3 | import 'package:stocks/components/chart/chart_models.dart';
4 | import 'package:stocks/components/chart/chart_tools.dart';
5 |
6 | class VolModel extends HqChartData {
7 | int index = 0;
8 | double maxValue = 0;
9 | double minValue = 0;
10 | int renderOffset = 0;
11 | final VolChartConfig config;
12 | VolModel(HqChartData data, this.config, this.renderOffset) {
13 | // config = _config;
14 | time = data.time;
15 | exchangeSymbol = data.exchangeSymbol;
16 | symbol = data.symbol;
17 | nowPrice = data.nowPrice;
18 | zdf = data.zdf;
19 | kpj = data.kpj;
20 | spj = data.spj;
21 | maxPrice = data.maxPrice;
22 | minPrice = data.minPrice;
23 | cjl = data.cjl;
24 | cje = data.cje;
25 | isEmpty = data.isEmpty;
26 | cjlMa = data.cjlMa;
27 | }
28 |
29 | Color get color {
30 | return double.parse(spj) > double.parse(kpj) ? config.buy : config.sell;
31 | }
32 |
33 | convertY(double source) {
34 | return ChartTools.convertY(source, config.height * 1.0, maxValue, minValue);
35 | }
36 |
37 | convertH(double source) {
38 | return ChartTools.convertH(source, config.height * 1.0, maxValue, minValue);
39 | }
40 |
41 | Size get size {
42 | double width = config.nowWidth.toDouble();
43 | double height = convertH(double.parse(cjl) - minValue);
44 | return Size(width, height);
45 | }
46 |
47 | Point get point {
48 | num x = index * config.nowWidth;
49 | num y = convertY(double.parse(cjl));
50 | return Point(x - renderOffset, y);
51 | }
52 | }
53 |
54 | class VolPainter extends CustomPainter {
55 | late VolChartConfig config;
56 | List _paintModels = [];
57 |
58 | VolPainter(List _datas, VolChartConfig _config, int _renderOffset) {
59 | config = _config;
60 | if (_datas.length > 0) {
61 | List nums = [];
62 | _datas.forEach((element) {
63 | if (!element.isEmpty) {
64 | nums.add(double.parse(element.cjl));
65 | nums = [...nums, ...element.cjlMa];
66 | }
67 | });
68 |
69 | double maxValue = nums.reduce(max);
70 | double minValue = nums.reduce(min);
71 |
72 | double pt = (config.paddingTop / config.height) * (maxValue - minValue);
73 | double pb =
74 | (config.paddingBottom / config.height) * (maxValue - minValue);
75 | maxValue += pt;
76 | minValue -= pb;
77 |
78 | int index = 0;
79 | _datas.forEach((element) {
80 | VolModel m = VolModel(element, _config, _renderOffset);
81 | m.maxValue = maxValue;
82 | m.minValue = minValue;
83 | m.index = index;
84 | _paintModels.add(m);
85 | index++;
86 | });
87 | }
88 | }
89 |
90 | paintMa(Canvas canvas, Size size, Paint paint, List points,
91 | ChartMAIndexConfig config) {
92 | paint.style = PaintingStyle.stroke;
93 | paint.strokeWidth = config.lineWidth;
94 | Path path = Path();
95 | bool isMove = false;
96 | points.forEach((element) {
97 | if (isMove) {
98 | path.lineTo(element.dx, element.dy);
99 | }
100 | if (element.dx != 0 && !isMove) {
101 | path.moveTo(element.dx, element.dy);
102 | isMove = true;
103 | }
104 | });
105 | canvas.drawPath(path, paint..color = config.lineColor);
106 | }
107 |
108 | @override
109 | paint(Canvas canvas, Size size) {
110 | Paint paint = Paint();
111 | Rect rect = Rect.fromLTWH(0, 0, size.width, size.height);
112 | canvas.clipRect(rect);
113 | paint.strokeWidth = 1;
114 | List> maPoints = [];
115 | _paintModels.forEach((element) {
116 | if (!element.isEmpty) {
117 | Point p = element.point;
118 | Size s = element.size;
119 | // print(
120 | // "$p|$s|${element.kpj}:${element.spj} || ${element.convertH(double.parse(element.kpj) - double.parse(element.spj))}");
121 | Rect r = Rect.fromLTWH(
122 | p.x.toDouble() + 1, p.y.toDouble(), s.width - 1, s.height);
123 | // print(DateTime.fromMillisecondsSinceEpoch(element.time));
124 | canvas.drawRect(r, paint..color = element.color);
125 |
126 | if (element.cjlMa.length > 0) {
127 | int maIndex = 0;
128 | element.cjlMa.forEach((element1) {
129 | if (maPoints.length <= maIndex) {
130 | maPoints.add([]);
131 | }
132 | maPoints[maIndex].add(Offset(
133 | element.point.x.toDouble() + s.width / 2,
134 | element.convertY(element.cjlMa[maIndex])));
135 | maIndex++;
136 | });
137 | }
138 | }
139 | });
140 |
141 | int index = 0;
142 | config.maIndexTypes.forEach((element) {
143 | if (maPoints.length > index) {
144 | paintMa(canvas, size, paint, maPoints[index], element);
145 | }
146 | index++;
147 | });
148 | }
149 |
150 | @override
151 | bool shouldRepaint(CustomPainter oldDelegate) {
152 | return true;
153 | }
154 | }
155 |
--------------------------------------------------------------------------------
/stocks/lib/components/exchange_symbols/exchange_symbols.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:stocks/components/text/text.dart';
3 | import 'package:stocks/manager/exchange_manager.dart';
4 | import 'package:stocks/manager/theme_manager.dart';
5 |
6 | class ExchangeSymbols extends StatelessWidget {
7 | final List exchangeSymbol;
8 | const ExchangeSymbols(this.exchangeSymbol, {Key? key}) : super(key: key);
9 | List getExchangeLogo() {
10 | List r = [];
11 | exchangeSymbol.forEach((element) {
12 | ExchangeModel? exchange = ExchangeManager.getExchangeModel(element);
13 | r.add(getImg(exchange));
14 | });
15 | return r;
16 | }
17 |
18 | Widget getImg(ExchangeModel? exchange) {
19 | if (exchange != null) {
20 | GNText text = GNText(
21 | "${exchange.name} ",
22 | color: exchange.mainColor,
23 | );
24 | return exchange.logo != null && exchange.logo!.length > 0
25 | ? Image.network(
26 | exchange.logo!,
27 | width: GNTheme().fontSizeType(FontSizeType.s),
28 | loadingBuilder: (context, o, s) {
29 | if (s == null) {
30 | return Padding(
31 | padding: EdgeInsets.only(right: 2, top: 2),
32 | child: o,
33 | );
34 | }
35 | return text;
36 | },
37 | errorBuilder: (context, o, s) {
38 | return text;
39 | },
40 | )
41 | : text;
42 | }
43 | return Container();
44 | }
45 |
46 | @override
47 | Widget build(BuildContext context) {
48 | return exchangeSymbol.length > 0
49 | ? Container(
50 | child: exchangeSymbol.length == 1
51 | ? getImg(ExchangeManager.getExchangeModel(exchangeSymbol[0]))
52 | : Row(children: getExchangeLogo()))
53 | : Container();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/stocks/lib/components/search/search.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:stocks/components/exchange_symbols/exchange_symbols.dart';
3 | import 'package:stocks/components/space/space.dart';
4 | import 'package:stocks/manager/exchange_manager.dart';
5 | import 'package:stocks/models/tokenModel.dart';
6 | import 'package:stocks/nav/nav.dart';
7 | import 'package:stocks/components/text/text.dart';
8 | import 'package:stocks/manager/theme_manager.dart';
9 | import 'package:stocks/manager/symbols_manager.dart';
10 | import 'package:stocks/manager/localizations_manager.dart';
11 | import 'package:stocks/components/button/button_ wrapped.dart';
12 |
13 | class GKSearchView extends StatefulWidget {
14 | void Function(Pair)? onSelected;
15 | GKSearchView(this.onSelected);
16 | @override
17 | _GKSearchViewState createState() => _GKSearchViewState(this.onSelected);
18 | }
19 |
20 | class _GKSearchViewState extends State
21 | with SymbolsSearchProtocal {
22 | List _result = [];
23 | String searchStr = "";
24 | void Function(Pair)? _onSelected;
25 |
26 | @override
27 | void initState() {
28 | super.initState();
29 | SymbolsManager.registerDelegate(this);
30 | }
31 |
32 | @override
33 | void dispose() {
34 | SymbolsManager.disposeDelegate(this);
35 | super.dispose();
36 | }
37 |
38 | @override
39 | result(List list) {
40 | setState(() {
41 | _result = list;
42 | });
43 | }
44 |
45 | _GKSearchViewState(this._onSelected);
46 | List getExchangeLogo(Pair pair) {
47 | List r = [];
48 | pair.exchangeSymbol.forEach((exchangeSymbol) {
49 | ExchangeModel? exchange =
50 | ExchangeManager.getExchangeModel(exchangeSymbol);
51 | if (exchange != null) {
52 | r.add(exchange.logo != null && exchange.logo!.length > 0
53 | ? Image.network(
54 | exchange.logo!,
55 | width: GNTheme().fontSizeType(FontSizeType.s),
56 | loadingBuilder: (context, o, s) {
57 | return GNText(
58 | "${exchange.name} ",
59 | color: exchange.mainColor,
60 | );
61 | },
62 | errorBuilder: (context, o, s) {
63 | return GNText("${exchange.name} ", color: exchange.mainColor);
64 | },
65 | )
66 | : GNText("${exchange.name}", color: exchange.mainColor));
67 | }
68 | });
69 | return r;
70 | }
71 |
72 | List getRow() {
73 | List r = [];
74 | _result.forEach((element) {
75 | r.add(GKWrappedButton(
76 | onPressed: () {
77 | this._onSelected!(element);
78 | },
79 | child: Row(
80 | children: [
81 | Column(
82 | mainAxisAlignment: MainAxisAlignment.start,
83 | crossAxisAlignment: CrossAxisAlignment.start,
84 | children: [
85 | Row(
86 | children: [
87 | heighlightText(searchStr.toLowerCase(),
88 | element.token0.symbol.toLowerCase()),
89 | GNText("/"),
90 | heighlightText(searchStr.toLowerCase(),
91 | element.token1.symbol.toLowerCase()),
92 | ],
93 | ),
94 | ExchangeSymbols(element.exchangeSymbol)
95 | ],
96 | )
97 | ],
98 | ),
99 | ));
100 | });
101 | return r;
102 | }
103 |
104 | heighlightText(String str, String sourceStr) {
105 | List sa = sourceStr.split(str);
106 | List r = [];
107 | int index = 0;
108 | sa.forEach((element) {
109 | r.add(TextSpan(
110 | text: element.toUpperCase(),
111 | style: TextStyle(
112 | color: GNTheme().fontColorType(FontColorType.content))));
113 | if (index != sa.length - 1) {
114 | r.add(TextSpan(
115 | text: str.toUpperCase(),
116 | style: TextStyle(
117 | color: GNTheme().fontColorType(FontColorType.bright))));
118 | }
119 | index++;
120 | });
121 | return RichText(
122 | text: TextSpan(
123 | children: r,
124 | style: TextStyle(
125 | fontSize: GNTheme().fontSizeType(FontSizeType.md),
126 | )));
127 | // print(sa);
128 | // print(str);
129 | // print(sourceStr);
130 | }
131 |
132 | @override
133 | Widget build(BuildContext context) {
134 | GNTheme theme = GNTheme();
135 | return Column(
136 | children: [
137 | Container(
138 | height: 30,
139 | child: TextField(
140 | textAlign: TextAlign.start,
141 | textAlignVertical: TextAlignVertical.bottom,
142 | onChanged: (value) {
143 | searchStr = value;
144 | if (value == "") {
145 | setState(() {
146 | _result = [];
147 | });
148 | } else {
149 | SymbolsManager.searchWithWidget(this, searchStr);
150 | // SymbolsManager.search(value, (List r) {
151 | // if (searchStr != "") {
152 | // setState(() {
153 | // _result = r;
154 | // });
155 | // }
156 | // });
157 | }
158 | },
159 | cursorColor: theme.fontColorType(FontColorType.bright),
160 | style: TextStyle(
161 | fontWeight: FontWeight.w300,
162 | fontSize: theme.fontSizeType(FontSizeType.md),
163 | color: theme.fontColorType(FontColorType.title)),
164 | decoration: InputDecoration(
165 | alignLabelWithHint: true,
166 | hoverColor: theme.bGColorType(BGColorType.highlight),
167 | hintStyle: TextStyle(
168 | fontWeight: FontWeight.w300,
169 | fontSize: theme.fontSizeType(FontSizeType.md),
170 | color: theme.fontColorType(FontColorType.bright)),
171 | border: InputBorder.none,
172 | fillColor: Colors.transparent,
173 | filled: true,
174 | hintText: GNLocalizations.str("Input here")),
175 | )),
176 | GNSpace(),
177 | Expanded(
178 | child: SingleChildScrollView(
179 | child: Column(
180 | children: getRow(),
181 | ),
182 | ))
183 | ],
184 | );
185 | }
186 | }
187 |
188 | class GKSearch {
189 | void Function(Pair)? onSelected;
190 | Function(GKSearch)? onPressedCancel;
191 | GKSearch({
192 | this.onSelected,
193 | this.onPressedCancel,
194 | });
195 | close() {
196 | Nav().pop();
197 | }
198 |
199 | show() {
200 | GNTheme theme = GNTheme();
201 | showDialog(
202 | context: Nav().context,
203 | barrierDismissible: false, // user must tap button!
204 | builder: (BuildContext context) {
205 | return AlertDialog(
206 | shape: RoundedRectangleBorder(
207 | borderRadius: BorderRadius.all(Radius.circular(16.0))),
208 | title: GNText(
209 | "Search",
210 | fontSize: theme.fontSizeType(FontSizeType.lg),
211 | color: theme.fontColorType(FontColorType.bright),
212 | ),
213 | content: GKSearchView(this.onSelected),
214 | actions: [
215 | TextButton(
216 | child: GNText(
217 | 'Cancel',
218 | color: theme.fontColorType(FontColorType.bright),
219 | isi18n: true,
220 | ),
221 | onPressed: () {
222 | close();
223 | }),
224 | ],
225 | );
226 | },
227 | );
228 | }
229 | }
230 |
--------------------------------------------------------------------------------
/stocks/lib/components/space/space.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | class GNSpace extends StatelessWidget {
4 | double height;
5 | double width;
6 | Color color;
7 | GNSpace({ this.height = 8, this.width = 0, this.color = Colors.transparent });
8 | @override
9 | Widget build(BuildContext context) {
10 | return Container(
11 | color: this.color,
12 | height: this.height,
13 | width: this.width,
14 | );
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/stocks/lib/components/text/text.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:stocks/manager/localizations_manager.dart';
3 | import 'package:stocks/manager/theme_manager.dart';
4 | class GNText extends Text {
5 | GNText(
6 | String text,
7 | {
8 | bool isi18n = false,
9 | double? fontSize,
10 | Color? color,
11 | String? fontFamily,
12 | TextAlign? textAlign,
13 | FontWeight? fontWeight,
14 | double? height,
15 | int? maxLines,
16 | TextOverflow? overflow
17 | }
18 | ) : super(
19 | isi18n ? GNLocalizations.str(text) : text,
20 | maxLines: maxLines,
21 | overflow: overflow,
22 | style: TextStyle(
23 | height: height,
24 | decoration: TextDecoration.none,
25 | fontWeight: fontWeight == null ? FontWeight.normal : fontWeight,
26 | fontSize: fontSize == null ? GNTheme().fontSizeType(FontSizeType.md) : fontSize,
27 | color: color == null ? GNTheme().fontColorType(FontColorType.content) : color,
28 | fontFamily: fontFamily == null ? GNTheme().fontFamilyType(FontFamilyType.content) : fontFamily
29 | // fontSize: 20.0,
30 | // color: Color(0xFF0F4C75),
31 | // fontFamily: ''
32 | )
33 | );
34 | }
35 |
--------------------------------------------------------------------------------
/stocks/lib/components/tooltip/tooltip.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:stocks/manager/localizations_manager.dart';
3 |
4 | class GNTooltip extends StatelessWidget {
5 | Widget? child;
6 | String message;
7 | bool isi18n = false;
8 | GNTooltip({this.child,this.message = "--", this.isi18n = false});
9 | @override
10 | Widget build(BuildContext context) {
11 | // GNTheme theme = GNTheme(context);
12 | return Tooltip(
13 | child: child,
14 | message: isi18n ? GNLocalizations.str(message) : message,
15 | // due to: PopupMenuButton can't custom tooltip the style
16 | // decoration: BoxDecoration(
17 | // color: theme.bGColorType(BGColorType.background)
18 | // // shape: BoxShape.circle,
19 | // ),
20 | // textStyle: TextStyle(
21 | // color: theme.fontColorType(FontColorType.bright),
22 | // fontSize: theme.fontSizeType(FontSizeType.s)
23 | // // backgroundColor: theme.bGColorType(BGColorType.background)
24 | // ),
25 | );
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/stocks/lib/main.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import './window/window.dart';
3 |
4 | void main() {
5 | runApp(Window());
6 | }
7 |
--------------------------------------------------------------------------------
/stocks/lib/manager/exchange_manager.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:stocks/manager/theme_manager.dart';
3 | import 'package:stocks/models/tokenModel.dart';
4 |
5 | enum ExchangeSymbol {
6 | BSC,
7 | HB,
8 | OK,
9 | }
10 |
11 | class ExchangeModel {
12 | ExchangeSymbol symbol = ExchangeSymbol.BSC;
13 | Currency? currency;
14 | String name = '--';
15 | bool isDefi = false;
16 | String desc = '--';
17 | String webUrl = '--';
18 | int index = 0;
19 | String? logo = "";
20 | String apiKey = '';
21 | Color? mainColor = GNTheme().fontColorType(FontColorType.content);
22 | ExchangeModel(this.symbol, this.name, this.isDefi, this.desc, this.webUrl,
23 | this.apiKey, this.index,
24 | {this.currency, this.logo, this.mainColor});
25 | }
26 |
27 | class ExchangeManager {
28 | static Map exchanges = {
29 | ExchangeSymbol.BSC: ExchangeModel(ExchangeSymbol.BSC, 'Binance', false, '币安交易所',
30 | 'https://www.binance.com/', '', 0,
31 | currency: Currency('Bnb', 'Bnb'),
32 | logo: "https://bin.bnbstatic.com/static/images/common/favicon.ico",
33 | mainColor: Colors.orange),
34 | ExchangeSymbol.HB: ExchangeModel(ExchangeSymbol.HB, 'Huobi', false, '火币交易所',
35 | 'https://www.huobi.com/', '', 0,
36 | currency: Currency('HB', 'HB'),
37 | logo: "https://www.huobi.com/favicon.ico",
38 | mainColor: Colors.blue),
39 | ExchangeSymbol.OK: ExchangeModel(ExchangeSymbol.OK, 'OKEX', false, '欧易交易所',
40 | 'https://www.okex.com/', '', 0,
41 | currency: Currency('OKB', 'OKB'),
42 | logo: "https://www.okex.com/favicon.ico",
43 | mainColor: Colors.lightBlue)
44 | };
45 |
46 | List nowSelecteds = [ExchangeSymbol.BSC];
47 |
48 | static ExchangeManager? _instance;
49 |
50 | ExchangeManager._();
51 |
52 | static ExchangeManager instance() {
53 | if (_instance == null) {
54 | _instance = ExchangeManager._();
55 | }
56 | return _instance!;
57 | }
58 |
59 | static ExchangeModel? getExchangeModel(ExchangeSymbol symbol) {
60 | return ExchangeManager.exchanges[symbol];
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/stocks/lib/manager/localizations_manager.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:flutter/foundation.dart' show SynchronousFuture;
3 | import 'package:flutter/cupertino.dart';
4 | import 'package:flutter_localizations/flutter_localizations.dart';
5 | import '../nav/nav.dart';
6 | import '../tools/GNLog.dart';
7 |
8 | class GNLocalizations {
9 | static Iterable> localizationsDelegates = [
10 | GNLocalizationsDelegate.delegate,
11 | GlobalWidgetsLocalizations.delegate,
12 | GlobalCupertinoLocalizations.delegate,
13 | GlobalMaterialLocalizations.delegate
14 | ];
15 | static Iterable supportedLocales = [
16 | Locale('zh'),
17 | Locale('en'),
18 | ];
19 |
20 | static GNLocalizations? _instance;
21 |
22 | GNLocalizations._internal();
23 |
24 | Locale? locale;
25 | Localizations? localizations;
26 | factory GNLocalizations() {
27 | if (_instance == null) {
28 | _instance = GNLocalizations._internal();
29 | }
30 | return _instance!;
31 | }
32 |
33 | setLocale(Locale locale) {
34 | this.locale = locale;
35 | }
36 |
37 | static GNLocalizations of(BuildContext _context) {
38 | return Localizations.of(_context, GNLocalizations);
39 | }
40 |
41 | static Map> _localizedValues = {
42 | 'en': {
43 | 'Token': 'Token',
44 | },
45 | 'zh': {
46 | 'Input here': '这儿',
47 | 'Add tag': '添加标签',
48 | 'empty!': '不能为空!',
49 | 'There are multiple files in this folder. Are you sure to delete them?':
50 | '此文件夹包含了多个文件,确定要删除吗?',
51 | 'warning': '提醒',
52 | 'input file name': '文件名',
53 | 'new note': '新建笔记',
54 | 'change layout': '切换布局',
55 | 'rename and edit mark': '重命名,编辑标记',
56 | 'drag left and right': '左右拖动',
57 | 'open directory': '打开一个目录',
58 | 'input category name': '请输入类别名称',
59 | 'Cancel': '取消',
60 | 'OK': '确定',
61 | 'show add category menu': '创建类别',
62 | 'Powered by Flutter': '基于 Flutter',
63 | 'Login': '登录',
64 | 'Token': '代币',
65 | },
66 | };
67 |
68 | getStr(String str) {
69 | if (this.locale != null) {
70 | String? strTemp = _localizedValues[locale!.languageCode]?[str];
71 | if (strTemp == null) {
72 | if (locale!.languageCode != 'en') {
73 | GNLog.w('no Localizations ${locale!.languageCode}: "$str"');
74 | }
75 | return str;
76 | }
77 | return strTemp;
78 | }
79 |
80 | return str;
81 | }
82 |
83 | static String str(String str) {
84 | return GNLocalizations.of(Nav().context).getStr(str);
85 | }
86 | }
87 |
88 | class GNLocalizationsDelegate extends LocalizationsDelegate {
89 | const GNLocalizationsDelegate();
90 | @override
91 | bool isSupported(Locale locale) {
92 | return ['en', 'zh'].contains(locale.languageCode);
93 | }
94 |
95 | @override
96 | Future load(Locale locale) {
97 | GNLocalizations t = GNLocalizations();
98 | t.setLocale(locale);
99 | return SynchronousFuture(t);
100 | }
101 |
102 | @override
103 | bool shouldReload(LocalizationsDelegate old) {
104 | return false;
105 | }
106 |
107 | static const GNLocalizationsDelegate delegate = GNLocalizationsDelegate();
108 | }
109 |
--------------------------------------------------------------------------------
/stocks/lib/manager/method_channel_manger.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/services.dart';
2 | import '../tools/GNLog.dart';
3 |
4 | const FilePlugin = MethodChannel('FilePlugin');
5 | const Map FilePluginFuncMap = {
6 | FilePluginFunc.OpenNativePath: "OpenNativePath",
7 | FilePluginFunc.TryOpenLastPath: "TryOpenLastPath"
8 | };
9 | enum FilePluginFunc { TryOpenLastPath, OpenNativePath }
10 |
11 | class GNMethodChannelModel {
12 | int? code;
13 | Map? body;
14 | GNMethodChannelModel({this.code, this.body});
15 |
16 | @override
17 | String toString() {
18 | // TODO: implement toString
19 | return "code:${code}, body:${body.toString()}";
20 | }
21 | }
22 |
23 | class GNMethodChannel {
24 | static callFilePlugin(FilePluginFunc funcName, [Map? data]) async {
25 | try {
26 | final Map result =
27 | await FilePlugin.invokeMethod("${FilePluginFuncMap[funcName]}");
28 | return GNMethodChannelModel(code: result["code"], body: result["body"]);
29 | } on PlatformException catch (e) {
30 | GNLog.w("${funcName}:${e.message}");
31 | return GNMethodChannelModel(code: -1, body: {"info": e.message});
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/stocks/lib/manager/responsive.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'dart:math';
3 |
4 | typedef ResponsiveCallback = Widget Function(GNMainViewSize);
5 |
6 | enum GNMainViewStatus { standard, detail }
7 | enum GNMainViewSize { big, middle, small }
8 |
9 | abstract class GNResponsiveProtocol {
10 | changeMainViewStatus(GNMainViewStatus status) {}
11 | changeMainViewSize(GNMainViewSize size) {}
12 | }
13 |
14 | class GNResponsive {
15 | List widgetDelegates = [];
16 | GNMainViewStatus nowMainViewStatus = GNMainViewStatus.standard;
17 | GNMainViewSize nowSize = GNMainViewSize.big;
18 | static MediaQueryData? MQ;
19 | static double? Height;
20 | static double? Width;
21 | static double? MinL;
22 | static bool AllowFontScaling = false;
23 |
24 | static GNResponsive? _m;
25 | factory GNResponsive([BuildContext? context]) {
26 | if (_m == null) {
27 | _m = GNResponsive._internal();
28 | }
29 | if (context != null) {
30 | GNResponsive.MQ = MediaQuery.of(context);
31 | Size size = MQ!.size;
32 | Width = size.width;
33 | Height = size.height;
34 | MinL = min(size.width, size.height);
35 | }
36 | return _m!;
37 | }
38 | GNResponsive._internal();
39 |
40 | static orientation(Widget Function() portrait, Widget Function() landscape) {
41 | return OrientationBuilder(builder: (_, orientation) {
42 | Size size = MQ!.size;
43 | Width = size.width;
44 | Height = size.height;
45 | if (MediaQuery.of(_).orientation == Orientation.portrait) {
46 | return portrait();
47 | } else {
48 | return landscape();
49 | }
50 | });
51 | }
52 |
53 | static double get smScreenMinWidth => 375;
54 | static double get smScreenMaxWidth => 600;
55 | static double get midScreenMinWidth => smScreenMaxWidth;
56 | static double get midScreenMaxWidth => smScreenMaxWidth * 1.5;
57 | static double get bigScreenWidth => midScreenMaxWidth;
58 |
59 | static getResponsive(ResponsiveCallback nowViewSizeCallback) {
60 | return OrientationBuilder(builder: (_, orientation) {
61 | Size size = MQ!.size;
62 | Width = size.width;
63 | Height = size.height;
64 | GNMainViewSize s = GNMainViewSize.small;
65 | if (Width! <= smScreenMaxWidth) {
66 | s = GNMainViewSize.small;
67 | }
68 | if (Width! > smScreenMaxWidth && Width! <= midScreenMaxWidth) {
69 | s = GNMainViewSize.middle;
70 | }
71 | if (Width! >= bigScreenWidth) {
72 | s = GNMainViewSize.big;
73 | }
74 | if (GNResponsive().nowSize != s) {
75 | GNResponsive().nowSize = s;
76 | GNResponsive.changeMainViewSize();
77 | }
78 |
79 | return nowViewSizeCallback(s);
80 | });
81 | }
82 |
83 | static changeMainViewStatus([GNMainViewStatus mainViewStatus = GNMainViewStatus.standard]) {
84 | GNResponsive m = GNResponsive();
85 | GNMainViewStatus status = mainViewStatus;
86 | if (status == null) {
87 | status = m.nowMainViewStatus;
88 | switch (m.nowMainViewStatus) {
89 | case GNMainViewStatus.standard:
90 | status = GNMainViewStatus.detail;
91 | break;
92 | default:
93 | status = GNMainViewStatus.standard;
94 | }
95 | }
96 | m.nowMainViewStatus = status;
97 | if (m.widgetDelegates.length > 0) {
98 | m.widgetDelegates.forEach((element) {
99 | if (element != null) {
100 | element.changeMainViewStatus(status);
101 | }
102 | });
103 | }
104 | }
105 |
106 |
107 | static changeMainViewSize() {
108 | GNResponsive m = GNResponsive();
109 | if (m.widgetDelegates.length > 0) {
110 | m.widgetDelegates.forEach((element) {
111 | if (element != null) {
112 | element.changeMainViewSize(m.nowSize);
113 | }
114 | });
115 | }
116 | }
117 |
118 | static registerDelegate(GNResponsiveProtocol widget) {
119 | GNResponsive m = GNResponsive();
120 | m.widgetDelegates.add(widget);
121 | }
122 |
123 | static disposeDelegate(Object widget) {
124 | GNResponsive m = GNResponsive();
125 | if (m.widgetDelegates.length > 0) {
126 | m.widgetDelegates.remove(widget);
127 | }
128 | // m.widgetDelegates.add(widget);
129 | }
130 |
131 | static bool get isPortrait => MQ!.orientation == Orientation.portrait;
132 | }
133 |
--------------------------------------------------------------------------------
/stocks/lib/manager/symbols_manager.dart:
--------------------------------------------------------------------------------
1 | import 'dart:convert';
2 | import 'package:stocks/manager/exchange_manager.dart';
3 | import 'package:stocks/models/tokenModel.dart';
4 | import 'package:stocks/net/api_manager.dart';
5 | import 'package:stocks/net/http.dart';
6 | import 'package:stocks/tools/tools.dart';
7 |
8 | mixin SymbolsSearchProtocal {
9 | result(List pair) {}
10 | }
11 |
12 | class SymbolsManager {
13 | Map pairsMap = {};
14 | Map> searchTemp = {};
15 | Function? debounceSearch;
16 | Map delegateMap = {};
17 | static SymbolsManager? _instance;
18 |
19 | static SymbolsManager instance() {
20 | if (_instance == null) {
21 | _instance = SymbolsManager._();
22 | ExchangeManager.exchanges.forEach((key, value) {
23 | _instance?._updateSymbols(key);
24 | });
25 | }
26 | return _instance!;
27 | }
28 |
29 | SymbolsManager._();
30 |
31 | Function _debounceS = GNTools().debounce((str, result) {
32 | SymbolsManager m = SymbolsManager.instance();
33 | result(m._search(str));
34 | }, 500);
35 |
36 | static registerDelegate(SymbolsSearchProtocal widget) {
37 | SymbolsManager.instance().delegateMap[widget] = "";
38 | }
39 |
40 | static disposeDelegate(SymbolsSearchProtocal widget) {
41 | SymbolsManager.instance().delegateMap.remove(widget);
42 | }
43 |
44 | static searchWithWidget(SymbolsSearchProtocal widget, String str) {
45 | SymbolsManager m = SymbolsManager.instance();
46 | if (m.delegateMap[widget] != null) {
47 | m.delegateMap[widget] = str;
48 | m._debounceS([
49 | str,
50 | (List pair) {
51 | if (widget != null) {
52 | widget.result(pair);
53 | }
54 | }
55 | ]);
56 | }
57 | }
58 |
59 | static search(String str, Function(List) result) {
60 | SymbolsManager.instance()._debounceS([str, result]);
61 | }
62 |
63 | List _search(String str) {
64 | String searchStr = str.toLowerCase().trim();
65 | print("_search $str ${pairsMap.keys.length}");
66 | if (searchStr == "") {
67 | return [];
68 | }
69 | // 查看缓存里有没有之前的搜索记录
70 | List? tempStrs = searchTemp[searchStr];
71 | List nextKeys = [];
72 | if (tempStrs != null) {
73 | // 有记录直接先记下缓存的 keys
74 | nextKeys = tempStrs;
75 | } else {
76 | // 没有记录再去查单独的字母
77 | if (searchStr.length > 1) {
78 | tempStrs = searchTemp[searchStr[0]];
79 | if (tempStrs != null) {
80 | tempStrs.forEach((element) {
81 | if (element.indexOf(searchStr) >= 0) {
82 | nextKeys.add(element);
83 | }
84 | });
85 | }
86 | }
87 | }
88 | List r = [];
89 | if (nextKeys.length > 0) {
90 | // 根据之前缓存的结果 keys 返回数据模型列表
91 |
92 | nextKeys.forEach((element) {
93 | r.add(pairsMap[element]!);
94 | });
95 | return r;
96 | }
97 |
98 | // 当没有在缓存中查到时候,进行源数据查找
99 |
100 | pairsMap.forEach((key, value) {
101 | if (key.indexOf(searchStr) >= 0) {
102 | nextKeys.add(key);
103 | r.add(value);
104 | }
105 | });
106 | if (searchTemp.length >= 20) {
107 | // 缓存最多保存 20 个,超过就要删除最小的那个
108 | String minListKey = "";
109 | int num = pairsMap.length;
110 | searchTemp.forEach((key, value) {
111 | if (value.length < num) {
112 | num = value.length;
113 | minListKey = key;
114 | }
115 | });
116 | searchTemp.remove(minListKey);
117 | }
118 | searchTemp[searchStr] = nextKeys;
119 | return r;
120 | }
121 |
122 | _updateSymbols(ExchangeSymbol symbol) {
123 | String baseUrl = APIManager.getApi(symbol, apiType.baseUrl)!;
124 | String apiPath = APIManager.getApi(symbol, apiType.symbols)!;
125 |
126 | Net.get("$baseUrl$apiPath").then((value) {
127 | dynamic obj = JsonDecoder().convert(value.toString());
128 | _analysisSourceSymbols(symbol, obj);
129 | });
130 | }
131 |
132 | _analysisSourceSymbols(ExchangeSymbol symbol, Map data) {
133 | switch (symbol) {
134 | case ExchangeSymbol.BSC:
135 | _analysisBSC(data);
136 | break;
137 | case ExchangeSymbol.HB:
138 | _analysisHB(data);
139 | break;
140 | case ExchangeSymbol.OK:
141 | _analysisOK(data);
142 | break;
143 | default:
144 | break;
145 | }
146 | }
147 |
148 | _analysisOK(Map data) {
149 | ExchangeSymbol symbol = ExchangeSymbol.OK;
150 | List l = data["data"];
151 | l.forEach((element) {
152 | if (element["state"] == "live") {
153 | String s =
154 | "${element["baseCcy"].toString().toLowerCase()}${element["quoteCcy"].toString().toLowerCase()}";
155 | Pair? p = pairsMap[s];
156 | if (p == null) {
157 | Pair pair = Pair();
158 | pair.exchangeSymbol = [symbol];
159 | pair.token0 = Token(element["baseCcy"], element["baseCcy"]);
160 | pair.token1 = Token(element["quoteCcy"], element["quoteCcy"]);
161 | pair.otherParm["instId"] = element["instId"].toString();
162 | pairsMap[s] = pair;
163 | } else {
164 | p.otherParm["instId"] = element["instId"].toString();
165 | p.exchangeSymbol.remove(symbol);
166 | p.exchangeSymbol.add(symbol);
167 | }
168 | }
169 | });
170 | }
171 |
172 | _analysisHB(Map data) {
173 | ExchangeSymbol symbol = ExchangeSymbol.HB;
174 | List l = data["data"];
175 | l.forEach((element) {
176 | if (element["state"] == "online") {
177 | String s = element["symbol"].toString().toLowerCase();
178 | Pair? p = pairsMap[s];
179 | if (p == null) {
180 | Pair pair = Pair();
181 | pair.exchangeSymbol = [symbol];
182 | pair.token0 =
183 | Token(element["base-currency"], element["base-currency"]);
184 | pair.token1 =
185 | Token(element["quote-currency"], element["quote-currency"]);
186 | pairsMap[s] = pair;
187 | } else {
188 | p.exchangeSymbol.remove(symbol);
189 | p.exchangeSymbol.add(symbol);
190 | }
191 | }
192 | });
193 | }
194 |
195 | _analysisBSC(Map data) {
196 | ExchangeSymbol symbol = ExchangeSymbol.BSC;
197 | List l = data["symbols"];
198 | l.forEach((element) {
199 | if (element["status"] == "TRADING") {
200 | String s = element["symbol"].toString().toLowerCase();
201 | Pair? p = pairsMap[s];
202 | if (p == null) {
203 | Pair pair = Pair();
204 | pair.exchangeSymbol = [symbol];
205 | pair.token0 = Token(element["baseAsset"], element["baseAsset"]);
206 | pair.token1 = Token(element["quoteAsset"], element["quoteAsset"]);
207 | pairsMap[s] = pair;
208 | } else {
209 | p.exchangeSymbol.remove(symbol);
210 | p.exchangeSymbol.add(symbol);
211 | }
212 | }
213 | });
214 | }
215 | }
216 |
--------------------------------------------------------------------------------
/stocks/lib/manager/theme_manager.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:provider/provider.dart';
3 | import 'dart:math';
4 |
5 | enum FontSizeType { xs, s, md, xmd, lg, xlg }
6 |
7 | enum FontColorType {
8 | content,
9 | title,
10 | subTitle,
11 | bright,
12 | highlight,
13 | dark,
14 | gray,
15 | error,
16 | warning
17 | }
18 |
19 | enum BGColorType {
20 | background,
21 | content,
22 | toast,
23 | normalBtn,
24 | highlight,
25 | bright,
26 | dark,
27 | gray,
28 | error,
29 | warning
30 | }
31 |
32 | enum ZDColorType {
33 | up, down, normal
34 | }
35 |
36 | enum FontFamilyType { content, title, subTitle, other }
37 |
38 | class GNThemeManager {
39 | static Map themeData = {
40 | "default": {
41 | 'FontSizeType': {
42 | 'xs': 10.0,
43 | 's': 12.0,
44 | 'md': 14.0,
45 | 'xmd': 18.0,
46 | 'lg': 24.0,
47 | 'xlg': 36.0
48 | },
49 | 'FontColorType': {
50 | 'content': 0xFF555555,
51 | 'title': 0xFF555555,
52 | 'subTitle': 0xFF868686,
53 | 'bright': 0xFF21BF73,
54 | 'dark': 0xFF1C262C,
55 | 'gray': 0xFF868686,
56 | 'highlight': 0xFFF5FDFA,
57 | 'error': 0xFFFD5E53,
58 | 'warning': 0xFFffc478,
59 | },
60 | 'BGColorType': {
61 | 'background': 0xFFFFFFFF,
62 | 'content': 0xFFFFFFFF,
63 | 'toast': 0xFFF5FDFA,
64 | 'normalBtn': 0xFFFFFFFF,
65 | 'bright': 0xFFB0EACD,
66 | 'dark': 0x00FFFFFF,
67 | 'gray': 0xFFF7FBFC,
68 | 'highlight': 0xFFF5FDFA,
69 | 'error': 0xFFF5FDFA,
70 | 'warning': 0xFFF5FDFA,
71 | },
72 | 'FontFamilyType': {
73 | 'content': '',
74 | 'title': '',
75 | 'subTitle': '',
76 | 'other': ''
77 | }
78 | },
79 | "dark": {
80 | 'FontSizeType': {
81 | 'xs': 10.0,
82 | 's': 12.0,
83 | 'md': 14.0,
84 | 'xmd': 18.0,
85 | 'lg': 24.0,
86 | 'xlg': 36.0
87 | },
88 | 'FontColorType': {
89 | 'content': 0xFFe7e7de,
90 | 'title': 0xFFe7e7de,
91 | 'subTitle': 0xFF769FCD,
92 | 'bright': 0xFF008891,
93 | 'dark': 0xFF1C262C,
94 | 'gray': 0xFFF7FBFC,
95 | 'highlight': 0xFF00587a,
96 | 'error': 0xFFFD5E53,
97 | 'warning': 0xFFffc478,
98 | },
99 | 'BGColorType': {
100 | 'background': 0xFF0f3057,
101 | 'content': 0xFF0f3057,
102 | 'toast': 0xFF00587a,
103 | 'normalBtn': 0xFFECB390,
104 | 'bright': 0xFFe7e7de,
105 | 'dark': 0xFF0f3057,
106 | 'gray': 0xFFF7FBFC,
107 | 'highlight': 0xFF00587a,
108 | 'error': 0xFF00587a,
109 | 'warning': 0xFF00587a,
110 | },
111 | 'FontFamilyType': {
112 | 'content': '',
113 | 'title': '',
114 | 'subTitle': '',
115 | 'other': ''
116 | }
117 | }
118 | };
119 |
120 | static bool isAuto = true;
121 | static Brightness systemStatus = Brightness.light;
122 | static Brightness lastSystemStatus = Brightness.light;
123 | static String nowTheme = 'default';
124 | static String lastTheme = 'default';
125 |
126 | static changeTheme(String themeName) {
127 | Map theme = themeData[themeName];
128 | // TODO: 扩充自定义皮肤
129 | if (theme != null && theme['name'] != nowTheme) {
130 | GNTheme().setThemeData(theme);
131 | }
132 | }
133 |
134 | static changeBackgroundAlpha(int alpha) {
135 | GNTheme().setBackgroundAlpha(alpha);
136 | }
137 |
138 | static autoChangeDarkOrLight(Brightness brightness, [BuildContext? context]) {
139 | // MediaQueryData.fromWindow(WidgetsBinding.instance.window).platformBrightness;
140 | Brightness nowSystemStatus = brightness;
141 | if (!isAuto || nowSystemStatus == systemStatus) return;
142 | String themeName = nowSystemStatus == Brightness.light ? 'default' : 'dark';
143 | print('自动切换皮肤 ${themeName}');
144 | changeTheme(themeName);
145 | lastSystemStatus = systemStatus;
146 | systemStatus = nowSystemStatus;
147 | }
148 |
149 | static GNThemeManager? _m;
150 | factory GNThemeManager([BuildContext? context]) {
151 | if (_m == null) {
152 | _m = GNThemeManager._internal();
153 | }
154 | if (context != null) {
155 | Brightness nowSystemStatus = MediaQuery.of(context).platformBrightness;
156 | nowTheme = nowSystemStatus == Brightness.light ? 'default' : 'dark';
157 | lastTheme = nowTheme;
158 | GNTheme().sourceThemeData = themeData[nowTheme];
159 | }
160 | return _m!;
161 | }
162 | GNThemeManager._internal();
163 | }
164 |
165 | class GNTheme with ChangeNotifier {
166 | static GNTheme? _m;
167 | List tagColors = [
168 | 0xFFffa41b,
169 | 0xFF000839,
170 | 0xFF005082,
171 | 0xFF00a8cc,
172 | 0xFFeb4559,
173 | 0xFFf78259,
174 | 0xFFaeefec,
175 | 0xFFf8eeee,
176 | 0xFFf4eeff,
177 | 0xFFdcd6f7,
178 | 0xFF21bf73,
179 | 0xFF4f3961,
180 | 0xFFf35588
181 | ];
182 | List markColors = [
183 | 0xFFffa41b,
184 | 0xFF000839,
185 | 0xFF005082,
186 | 0xFF00a8cc,
187 | 0xFFeb4559,
188 | 0xFFf78259,
189 | 0xFFaeefec,
190 | 0xFFf8eeee,
191 | 0xFFf4eeff,
192 | 0xFFdcd6f7,
193 | 0xFF21bf73,
194 | 0xFF4f3961,
195 | 0xFFf35588
196 | ];
197 |
198 | Map zdColor = {
199 | ZDColorType.up: Color(0xFF21BF73),
200 | ZDColorType.down: Color(0xFFFD5E53),
201 | ZDColorType.normal: Color(0xFFC9CCD5)
202 | };
203 |
204 | Map sourceThemeData = GNThemeManager.themeData["default"];
205 | // TODO: useless
206 | int backgroundAlpha = 0;
207 | factory GNTheme([BuildContext? context]) {
208 | if (_m == null) {
209 | _m = GNTheme._internal();
210 | }
211 | if (context == null) {
212 | return _m!;
213 | }
214 | return Provider.of(context);
215 | }
216 | GNTheme._internal();
217 |
218 | setThemeData(Map data) {
219 | this.sourceThemeData = data;
220 | notifyListeners();
221 | }
222 |
223 | setBackgroundAlpha(int alpha) {
224 | this.backgroundAlpha = alpha;
225 | notifyListeners();
226 | }
227 |
228 | Color getZDColor(ZDColorType type) {
229 | return zdColor[type]!;
230 | }
231 |
232 | Color getTagsColor() {
233 | int index = Random().nextInt(tagColors.length - 1);
234 | return Color(tagColors[index]);
235 | }
236 |
237 | String fontFamilyType(FontFamilyType type) {
238 | var sourceMap = sourceThemeData['FontFamilyType'];
239 | switch (type) {
240 | case FontFamilyType.content:
241 | return sourceMap['content'];
242 | case FontFamilyType.title:
243 | return sourceMap['title'];
244 | case FontFamilyType.subTitle:
245 | return sourceMap['subTitle'];
246 | case FontFamilyType.other:
247 | return sourceMap['other'];
248 | default:
249 | return sourceMap['content'];
250 | }
251 | }
252 |
253 | double fontSizeType(FontSizeType type) {
254 | var sourceMap = sourceThemeData['FontSizeType'];
255 | double num;
256 | switch (type) {
257 | case FontSizeType.xs:
258 | num = sourceMap['xs'];
259 | break;
260 | case FontSizeType.s:
261 | num = sourceMap['s'];
262 | break;
263 | case FontSizeType.md:
264 | num = sourceMap['md'];
265 | break;
266 | case FontSizeType.xmd:
267 | num = sourceMap['xmd'];
268 | break;
269 | case FontSizeType.lg:
270 | num = sourceMap['lg'];
271 | break;
272 | case FontSizeType.xlg:
273 | num = sourceMap['xlg'];
274 | break;
275 | default:
276 | num = sourceMap['md'];
277 | break;
278 | }
279 | return num;
280 | }
281 |
282 | Color fontColorType(FontColorType type) {
283 | var sourceMap = sourceThemeData['FontColorType'];
284 | var colorNum;
285 | switch (type) {
286 | case FontColorType.content:
287 | colorNum = sourceMap['content'];
288 | break;
289 | case FontColorType.title:
290 | colorNum = sourceMap['title'];
291 | break;
292 | case FontColorType.subTitle:
293 | colorNum = sourceMap['subTitle'];
294 | break;
295 | case FontColorType.bright:
296 | colorNum = sourceMap['bright'];
297 | break;
298 | case FontColorType.dark:
299 | colorNum = sourceMap['dark'];
300 | break;
301 | case FontColorType.gray:
302 | colorNum = sourceMap['gray'];
303 | break;
304 | case FontColorType.highlight:
305 | colorNum = sourceMap['highlight'];
306 | break;
307 | case FontColorType.error:
308 | colorNum = sourceMap['error'];
309 | break;
310 | case FontColorType.warning:
311 | colorNum = sourceMap['warning'];
312 | break;
313 | default:
314 | colorNum = sourceMap['content'];
315 | break;
316 | }
317 | return Color(colorNum);
318 | }
319 |
320 | Color bGColorType(BGColorType type) {
321 | var sourceMap = sourceThemeData['BGColorType'];
322 | var colorNum;
323 | switch (type) {
324 | case BGColorType.background:
325 | colorNum = sourceMap['background'];
326 | break;
327 | case BGColorType.content:
328 | colorNum = sourceMap['content'];
329 | break;
330 | case BGColorType.toast:
331 | colorNum = sourceMap['toast'];
332 | break;
333 | case BGColorType.normalBtn:
334 | colorNum = sourceMap['normalBtn'];
335 | break;
336 | case BGColorType.bright:
337 | colorNum = sourceMap['bright'];
338 | break;
339 | case BGColorType.dark:
340 | colorNum = sourceMap['dark'];
341 | break;
342 | case BGColorType.gray:
343 | colorNum = sourceMap['gray'];
344 | break;
345 | case BGColorType.highlight:
346 | colorNum = sourceMap['highlight'];
347 | break;
348 | case BGColorType.error:
349 | colorNum = sourceMap['error'];
350 | break;
351 | case BGColorType.warning:
352 | colorNum = sourceMap['warning'];
353 | break;
354 | default:
355 | colorNum = sourceMap['content'];
356 | break;
357 | }
358 | return Color(colorNum);
359 | }
360 | }
361 |
--------------------------------------------------------------------------------
/stocks/lib/manager/themes/dark.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "dark",
3 | "FontSizeType": {
4 | "xs": 10.0,
5 | "s": 12.0,
6 | "md": 14.0,
7 | "xmd": 18.0,
8 | "lg": 24.0,
9 | "xlg": 36.0
10 | },
11 | "FontColorType": {
12 | "content": "0xFF0F4C75",
13 | "title": "0xFF0F4C75",
14 | "subTitle": "0xFF769FCD",
15 | "bright": "0xFFF7FBFC",
16 | "dark": "0xFF1C262C",
17 | "gray": "0xFFF7FBFC",
18 | "highlight": "0xFFEE4640"
19 | },
20 | "BGColorType": {
21 | "background": "0xFFFFFFFF",
22 | "content": "0xFFF7FBFC",
23 | "toast": "0xFFBBE1FA",
24 | "normalBtn": "0xFFECB390",
25 | "bright": "0xFFEE4640",
26 | "dark": "0x00FFFFFF",
27 | "gray": "0xFFF7FBFC",
28 | "highlight": "0xFFEE4640"
29 | },
30 | "FontFamilyType": {
31 | "content": "",
32 | "title": "",
33 | "subTitle": "",
34 | "other": ""
35 | }
36 | }
--------------------------------------------------------------------------------
/stocks/lib/manager/themes/default.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "default",
3 | "FontSizeType": {
4 | "xs": 10.0,
5 | "s": 12.0,
6 | "md": 14.0,
7 | "xmd": 18.0,
8 | "lg": 24.0,
9 | "xlg": 36.0
10 | },
11 | "FontColorType": {
12 | "content": "0xFF0F4C75",
13 | "title": "0xFF0F4C75",
14 | "subTitle": "0xFF769FCD",
15 | "bright": "0xFFF7FBFC",
16 | "dark": "0xFF1C262C",
17 | "gray": "0xFFF7FBFC",
18 | "highlight": "0xFFEE4640"
19 | },
20 | "BGColorType": {
21 | "background": "0xFFFFFFFF",
22 | "content": "0xFFF7FBFC",
23 | "toast": "0xFFBBE1FA",
24 | "normalBtn": "0xFFECB390",
25 | "bright": "0xFFEE4640",
26 | "dark": "0x00FFFFFF",
27 | "gray": "0xFFF7FBFC",
28 | "highlight": "0xFFEE4640"
29 | },
30 | "FontFamilyType": {
31 | "content": "",
32 | "title": "",
33 | "subTitle": "",
34 | "other": ""
35 | }
36 | }
--------------------------------------------------------------------------------
/stocks/lib/models/dataModel.dart:
--------------------------------------------------------------------------------
1 | import 'package:stocks/manager/exchange_manager.dart';
2 |
3 | import 'tokenModel.dart';
4 |
5 | // {
6 | // "e": "24hrTicker", // 事件类型
7 | // "E": 123456789, // 事件时间
8 | // "s": "BNBBTC", // 交易对
9 | // "p": "0.0015", // 24小时价格变化
10 | // "P": "250.00", // 24小时价格变化(百分比)
11 | // "w": "0.0018", // 平均价格
12 | // "x": "0.0009", // 整整24小时之前,向前数的最后一次成交价格
13 | // "c": "0.0025", // 最新成交价格
14 | // "Q": "10", // 最新成交交易的成交量
15 | // "b": "0.0024", // 目前最高买单价
16 | // "B": "10", // 目前最高买单价的挂单量
17 | // "a": "0.0026", // 目前最低卖单价
18 | // "A": "100", // 目前最低卖单价的挂单量
19 | // "o": "0.0010", // 整整24小时前,向后数的第一次成交价格
20 | // "h": "0.0025", // 24小时内最高成交价
21 | // "l": "0.0010", // 24小时内最低成交价
22 | // "v": "10000", // 24小时内成交量
23 | // "q": "18", // 24小时内成交额
24 | // "O": 0, // 统计开始时间
25 | // "C": 86400000, // 统计结束时间
26 | // "F": 0, // 24小时内第一笔成交交易ID
27 | // "L": 18150, // 24小时内最后一笔成交交易ID
28 | // "n": 18151 // 24小时内成交数
29 | // }
30 | // {
31 | // "e": "24hrMiniTicker", // 事件类型
32 | // "E": 123456789, // 事件时间
33 | // "s": "BNBBTC", // 交易对
34 | // "c": "0.0025", // 最新成交价格
35 | // "o": "0.0010", // 24小时前开始第一笔成交价格
36 | // "h": "0.0025", // 24小时内最高成交价
37 | // "l": "0.0010", // 24小时内最低成交价
38 | // "v": "10000", // 成交量
39 | // "q": "18" // 成交额
40 | // }
41 |
42 | enum PairZDStatus { up, down, normal }
43 | class BaseHQData {
44 | int time = 0;
45 | ExchangeSymbol exchangeSymbol = ExchangeSymbol.BSC;
46 | String symbol = "";
47 | String nowPrice = "";
48 | String zdf = "";
49 | double zdfNoUnit = 0;
50 | String kpj = "";
51 | String spj = "";
52 | String maxPrice = "";
53 | String minPrice = "";
54 | String cjl = "";
55 | String cje = "";
56 | PairZDStatus zdStatus = PairZDStatus.normal;
57 | String getZDF() {
58 | double np = double.parse(nowPrice);
59 | double kpjTemp = double.parse(kpj);
60 | double zdf = ((np - kpjTemp) / kpjTemp) * 100;
61 | zdfNoUnit = zdf;
62 | return "${zdf.toStringAsFixed(2)}%";
63 | }
64 |
65 | @override
66 | String toString() {
67 | return "symbol:$symbol | nowPrice:$nowPrice | kpj:$kpj";
68 | }
69 | }
70 |
71 | class HQData extends BaseHQData {}
72 | // {
73 | // "e": "kline", // 事件类型
74 | // "E": 123456789, // 事件时间
75 | // "s": "BNBBTC", // 交易对
76 | // "k": {
77 | // "t": 123400000, // 这根K线的起始时间
78 | // "T": 123460000, // 这根K线的结束时间
79 | // "s": "BNBBTC", // 交易对
80 | // "i": "1m", // K线间隔
81 | // "f": 100, // 这根K线期间第一笔成交ID
82 | // "L": 200, // 这根K线期间末一笔成交ID
83 | // "o": "0.0010", // 这根K线期间第一笔成交价
84 | // "c": "0.0020", // 这根K线期间末一笔成交价
85 | // "h": "0.0025", // 这根K线期间最高成交价
86 | // "l": "0.0015", // 这根K线期间最低成交价
87 | // "v": "1000", // 这根K线期间成交量
88 | // "n": 100, // 这根K线期间成交笔数
89 | // "x": false, // 这根K线是否完结(是否已经开始下一根K线)
90 | // "q": "1.0000", // 这根K线期间成交额
91 | // "V": "500", // 主动买入的成交量
92 | // "Q": "0.500", // 主动买入的成交额
93 | // "B": "123456" // 忽略此参数
94 | // }
95 | // }
96 | class KLineData extends BaseHQData {}
97 |
--------------------------------------------------------------------------------
/stocks/lib/models/tokenModel.dart:
--------------------------------------------------------------------------------
1 | import 'package:stocks/manager/exchange_manager.dart';
2 | class Token {
3 | String? address = '--';
4 | String symbol = '--';
5 | String? name = '--';
6 | String shortName = '--';
7 | Token(this.symbol,this.shortName,[this.name, this.address]);
8 | }
9 |
10 | class TokenDesc extends Token {
11 | String? webUrl;
12 | String? desc;
13 |
14 | TokenDesc(String symbol, String shortName) : super(symbol, shortName);
15 | }
16 |
17 | class Currency extends Token {
18 | Currency(String symbol, String shortName) : super(symbol, shortName);
19 | }
20 | class CurrencyDesc extends TokenDesc {
21 | CurrencyDesc(String symbol, String shortName) : super(symbol, shortName);
22 | }
23 |
24 | class Pair {
25 | Token token0 = Token('Doge', 'Doge');
26 | Token token1 = Token('Bnb', 'Bnb');
27 | Map otherParm = {};
28 | List exchangeSymbol = [];
29 | String get symbol => '${this.token0.symbol}${this.token1.symbol}'.toLowerCase();
30 | @override
31 | String toString() {
32 | return this.symbol;
33 | }
34 | }
--------------------------------------------------------------------------------
/stocks/lib/nav/nav.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import '../manager/theme_manager.dart';
3 | import '../manager/responsive.dart';
4 |
5 | class Nav extends StatelessWidget with WidgetsBindingObserver {
6 | static Nav? _m;
7 | Widget? zeroPage;
8 | late BuildContext context;
9 | OverlayState? overlayState;
10 |
11 | Nav._internal();
12 |
13 | factory Nav([Widget? zeroPage]) {
14 | if (_m == null) {
15 | _m = Nav._internal();
16 | _m!.zeroPage = zeroPage;
17 | WidgetsBinding.instance!.addObserver(_m!);
18 | }
19 | return _m!;
20 | }
21 |
22 |
23 | setZeroPage(Widget zeroPage) {
24 | this.zeroPage = zeroPage;
25 | }
26 |
27 | push(Widget view) {
28 | return Navigator.push(
29 | context,
30 | MaterialPageRoute(builder: (context) => view),
31 | );
32 | }
33 |
34 | pushAndRemoveUntil(Widget view) {
35 | return Navigator.pushAndRemoveUntil(
36 | context,
37 | MaterialPageRoute(builder: (context) => view),
38 | (route) => route == null,
39 | );
40 | }
41 |
42 | pop({BuildContext? context, Object? obj}) {
43 | return Navigator.pop(context == null ? this.context : context, obj);
44 | }
45 |
46 | @override
47 | void didChangePlatformBrightness() {
48 | super.didChangePlatformBrightness();
49 | GNThemeManager.autoChangeDarkOrLight(WidgetsBinding.instance!.window.platformBrightness);
50 | }
51 |
52 | @override
53 | Widget build(BuildContext context) {
54 | this.context = context;
55 | final _overlayState = Overlay.of(context);
56 | this.overlayState = _overlayState;
57 | GNResponsive(context);
58 | GNThemeManager(context);
59 | return Navigator(
60 | initialRoute: 'zeroPage',
61 | onGenerateRoute: (RouteSettings settings) {
62 | WidgetBuilder builder;
63 | switch (settings.name) {
64 | case 'zeroPage':
65 | builder = (BuildContext context) => this.zeroPage!;
66 | break;
67 | default:
68 | throw Exception('Invalid route: ${settings.name}');
69 | }
70 | return MaterialPageRoute(builder: builder, settings: settings);
71 | });
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/stocks/lib/net/api_manager.dart:
--------------------------------------------------------------------------------
1 | import 'package:stocks/manager/exchange_manager.dart';
2 |
3 | enum apiType { kline, baseUrl, symbols }
4 |
5 | enum apiReqType { get, post, socket }
6 |
7 | const Map BSCAUTH = {
8 | "key": "z3unZp6qVrNEsyOxNoAOWgi0TqMmzgvcr72qM2rgklm62nFs8yAo9lCg9LpqXjWU",
9 | "secret": "zsqLdu7s0lNiJKh7BNcXo8OEH1SMrC4LpdYCZ0VWUfiQwValTERUy8xfRzuLyWdO"
10 | };
11 |
12 | class APIManager {
13 | Map>> apiMap = {
14 | ExchangeSymbol.BSC: {
15 | apiType.baseUrl: {
16 | apiReqType.socket: 'wss://stream.binance.com:9443/ws',
17 | apiReqType.get: 'https://api.binance.com'
18 | },
19 | apiType.kline: {apiReqType.socket: '', apiReqType.get: '/api/v3/klines'},
20 | apiType.symbols: {apiReqType.get: '/api/v3/exchangeInfo'}
21 | },
22 | ExchangeSymbol.HB: {
23 | apiType.baseUrl: {
24 | apiReqType.socket: 'wss://api-aws.huobi.pro/ws',
25 | apiReqType.get: 'https://api.huobi.pro'
26 | },
27 | apiType.symbols: {apiReqType.get: '/v1/common/symbols'},
28 | apiType.kline: {apiReqType.get: '/market/history/kline'}
29 | },
30 | ExchangeSymbol.OK: {
31 | apiType.baseUrl: {
32 | apiReqType.socket: 'wss://ws.okex.com:8443/ws/v5/public',
33 | apiReqType.get: 'https://aws.okex.com'
34 | },
35 | apiType.symbols: {apiReqType.get: '/api/v5/public/instruments?instType=SPOT'},
36 | apiType.kline: {apiReqType.get: '/api/v5/market/candles'}
37 | }
38 | };
39 |
40 | static APIManager? _instance;
41 |
42 | APIManager._();
43 |
44 | static APIManager instance() {
45 | if (_instance == null) {
46 | _instance = APIManager._();
47 | }
48 | return _instance!;
49 | }
50 |
51 | static String? getApi(ExchangeSymbol symbol, apiType type,
52 | {apiReqType? reqType = apiReqType.get}) {
53 | return APIManager.instance().apiMap[symbol]?[type]?[reqType];
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/stocks/lib/net/hq_net.dart:
--------------------------------------------------------------------------------
1 | import 'dart:convert';
2 | import 'package:stocks/components/chart/chart_models.dart';
3 | import 'package:stocks/manager/exchange_manager.dart';
4 | import 'package:stocks/models/tokenModel.dart';
5 | import 'package:stocks/net/http.dart';
6 | import 'package:stocks/net/api_manager.dart';
7 |
8 |
9 | enum HqIntervalType {
10 | m, h, d, w, M
11 | }
12 |
13 | class HqNet {
14 | static Future getAllHqData(ExchangeSymbol symbol, Pair piar, {HqIntervalType? intervalType = HqIntervalType.d, int? intervalNum = 1} ) {
15 | String? klineUrl = APIManager.getApi(symbol, apiType.kline);
16 | String? baseUrl = APIManager.getApi(symbol, apiType.baseUrl);
17 | return Net.get("$baseUrl$klineUrl",queryParameters: {
18 | "symbol": piar.symbol.toUpperCase(),
19 | "interval": "1d",
20 | // "limit": "00"
21 | }).then((value) {
22 | List obj = value.data;
23 | List r = [];
24 | // [
25 | // 1499040000000, // 开盘时间0
26 | // "0.01634790", // 开盘价1
27 | // "0.80000000", // 最高价2
28 | // "0.01575800", // 最低价3
29 | // "0.01577100", // 收盘价(当前K线未结束的即为最新价)4
30 | // "148976.11427815", // 成交量5
31 | // 1499644799999, // 收盘时间6
32 | // "2434.19055334", // 成交额7
33 | // 308, // 成交笔数8
34 | // "1756.87402397", // 主动买入成交量9
35 | // "28.46694368", // 主动买入成交额10
36 | // "17928899.62484339" // 请忽略该参数11
37 | // ]
38 | int index = 0;
39 | obj.forEach((element) {
40 | HqChartData d = HqChartData();
41 | d.time = element[0];
42 | d.kpj = element[1];
43 | d.spj = element[4];
44 | d.cjl = element[5];
45 | d.maxPrice = element[2];
46 | d.minPrice = element[3];
47 | d.exchangeSymbol = symbol;
48 | d.hqChartDataIndex = index;
49 | r.add(d);
50 | index ++;
51 | });
52 | return r;
53 | }).catchError((error){
54 | print(error.toString());
55 | return [];
56 | });
57 | }
58 | }
--------------------------------------------------------------------------------
/stocks/lib/net/http.dart:
--------------------------------------------------------------------------------
1 | import 'dart:io';
2 |
3 | import 'package:dio/adapter.dart';
4 | import 'package:dio/dio.dart';
5 | import 'package:flutter/foundation.dart';
6 | import 'package:stocks/net/net_adapter.dart';
7 |
8 | BaseOptions opt = BaseOptions(
9 | connectTimeout: 60 * 1000,
10 | receiveTimeout: 1000 * 60 * 60 * 24,
11 | responseType: ResponseType.json,
12 | headers: {"Content-Type": "application/json"});
13 |
14 | class Net {
15 | Dio dio = Dio(opt);
16 | static Net? _instance;
17 | Net._();
18 | static Net instance() {
19 | if (_instance == null) {
20 | _instance = Net._();
21 | if (http_proxy.length > 0 && https_proxy.length > 0) {
22 | if (!kIsWeb) {
23 | (_instance!.dio.httpClientAdapter as DefaultHttpClientAdapter)
24 | .onHttpClientCreate = (client) {
25 | client.findProxy = (uri) {
26 | return "PROXY $http_proxy";
27 | };
28 | };
29 | }
30 | }
31 | }
32 | return _instance!;
33 | }
34 |
35 | static Future get(String url,
36 | {Map? queryParameters, Options? options}) {
37 | return Net.instance()
38 | .dio
39 | .get(url, queryParameters: queryParameters, options: options);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/stocks/lib/pages/detail_view/detail_view.dart:
--------------------------------------------------------------------------------
1 | import 'dart:io';
2 | import 'package:flutter/material.dart';
3 | import 'package:stocks/components/text/text.dart';
4 | import 'package:stocks/manager/exchange_manager.dart';
5 | import 'package:stocks/manager/theme_manager.dart';
6 | import 'package:stocks/models/tokenModel.dart';
7 | import 'package:stocks/net/hq_net.dart';
8 | import 'package:stocks/components/chart/chart_view.dart';
9 | import 'package:stocks/components/chart/chart_models.dart';
10 |
11 | class DetailView extends StatefulWidget {
12 | Pair? pair;
13 | DetailView({Key? key, this.pair}) : super(key: key);
14 | @override
15 | _DetailViewState createState() => _DetailViewState();
16 | }
17 |
18 | class _DetailViewState extends State {
19 | List _chartData = [];
20 | late List _configs;
21 | @override
22 | void initState() {
23 | KlineChartConfig kConfig = KlineChartConfig();
24 | kConfig.isAutoWidth = true;
25 | ChartMAIndexConfig ma5 = ChartMAIndexConfig();
26 | ChartMAIndexConfig ma10 = ChartMAIndexConfig();
27 | ma10.ma = 10;
28 | ma10.lineColor = Colors.pinkAccent;
29 | ChartMAIndexConfig ma20 = ChartMAIndexConfig();
30 | ma20.ma = 20;
31 | ma20.lineColor = Colors.deepPurple;
32 | ChartMAIndexConfig ma60 = ChartMAIndexConfig();
33 | ma60.ma = 60;
34 | ma60.lineColor = Colors.lightBlue;
35 | kConfig.maIndexTypes = [ma5, ma10, ma20, ma60];
36 |
37 | ChartMAIndexConfig volMa5 = ChartMAIndexConfig();
38 | volMa5.maIndexType = ChartMAIndexType.CJL;
39 | ChartMAIndexConfig volMa10 = ChartMAIndexConfig();
40 | volMa10.maIndexType = ChartMAIndexType.CJL;
41 | volMa10.ma = 10;
42 | volMa10.lineColor = Colors.pinkAccent;
43 | VolChartConfig vConfig = VolChartConfig();
44 | vConfig.isAutoWidth = true;
45 | vConfig.maIndexTypes = [volMa5, volMa10];
46 |
47 | _configs = [kConfig, vConfig];
48 |
49 | if (widget.pair != null) {
50 | testData(widget.pair!);
51 | }
52 | super.initState();
53 | }
54 |
55 |
56 |
57 | @override
58 | dispose() {
59 | print(" detail dispose");
60 | // GNPagesAction().disposeAction(widget);
61 | super.dispose();
62 | }
63 |
64 | @override
65 | void didUpdateWidget(DetailView oldWidget) {
66 | super.didUpdateWidget(oldWidget);
67 | if (widget.pair != null) {
68 | testData(widget.pair!);
69 | }
70 | }
71 |
72 | testData(Pair pair) {
73 | HqNet.getAllHqData(ExchangeSymbol.BSC, pair).then((value) {
74 | // print(value);
75 | if (this != null && widget != null && context != null) {
76 | setState(() {
77 | _chartData = value;
78 | });
79 | }
80 | });
81 | // Net.get(APIManager.getApi(E, type))
82 | }
83 |
84 | @override
85 | Widget build(BuildContext context) {
86 | Color bg = Colors.white;
87 | if (Platform.isMacOS) {
88 | bg = Colors.transparent;
89 | }
90 | return Container(
91 | color: bg,
92 | constraints: BoxConstraints.expand(),
93 | child: SafeArea(
94 | child: Container(
95 | padding: EdgeInsets.only(top: 16),
96 | child: SingleChildScrollView(
97 |
98 | child: Column(
99 | mainAxisAlignment: MainAxisAlignment.start,
100 | crossAxisAlignment: CrossAxisAlignment.start,
101 | children: [
102 | Row(
103 | mainAxisAlignment: MainAxisAlignment.start,
104 | crossAxisAlignment: CrossAxisAlignment.center,
105 | children: [
106 | GNText(
107 | widget.pair != null ? widget.pair!.token0.symbol.toUpperCase() : '--',
108 | color: GNTheme().fontColorType(FontColorType.bright),
109 | fontSize: GNTheme().fontSizeType(FontSizeType.lg),
110 | ),
111 | GNText(
112 | widget.pair != null ? widget.pair!.token1.symbol.toUpperCase() : '--',
113 | color: GNTheme().fontColorType(FontColorType.gray),
114 | fontSize: GNTheme().fontSizeType(FontSizeType.md),
115 | ),
116 | ],
117 | ),
118 | Row(
119 | children: [
120 | Expanded(
121 | child: ChartView(
122 | datas: _chartData,
123 | configs: _configs,
124 | ))
125 | ],
126 | )
127 | ],
128 | ),)
129 | )),
130 | );
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/stocks/lib/pages/main_view/main_view.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:stocks/models/tokenModel.dart';
3 | import 'package:stocks/pages/menu_view/menu_view.dart';
4 | import 'package:stocks/pages/list_view/list_view.dart';
5 | import 'package:stocks/manager/symbols_manager.dart';
6 | import 'package:stocks/pages/detail_view/detail_view.dart';
7 | import 'package:stocks/pages/page_action.dart';
8 | import 'package:stocks/pages/test/test.dart';
9 | import '../../manager/responsive.dart';
10 | import '../../manager/method_channel_manger.dart';
11 | import '../../nav/nav.dart';
12 |
13 | class MainPage extends StatefulWidget {
14 | @override
15 | _MainPageState createState() => _MainPageState();
16 | }
17 |
18 | class _MainPageState extends State
19 | with TickerProviderStateMixin, GNResponsiveProtocol {
20 | late Widget _menu;
21 | late Widget _list;
22 | late Widget _detail;
23 | int _nowSel = 0;
24 | GNMainViewStatus _mainViewStatus = GNMainViewStatus.standard;
25 | GNMainViewSize? _nowSize;
26 | Pair? _detailPair;
27 | @override
28 | void initState() {
29 | GNResponsive.registerDelegate(this);
30 | _list = FListView();
31 | _menu = MenuView(_nowSel);
32 | loadData();
33 | SymbolsManager.instance();
34 | GNPagesAction()
35 | .registerAction(PageName.main, FuncName.clickStock, widget, clickStock);
36 | GNPagesAction()
37 | .registerAction(PageName.main, FuncName.clickMenu, widget, clickMenu);
38 | super.initState();
39 | }
40 |
41 | clickMenu(PageName name, FuncName funcName, {List? data}) {
42 | if (data != null && data.length > 0) {
43 | int nowSel = data[0];
44 | if (_nowSel != nowSel) {
45 | setState(() {
46 | _nowSel = nowSel;
47 | });
48 | }
49 | }
50 | }
51 |
52 | clickStock(PageName name, FuncName funcName, {List? data}) {
53 | if (data != null && data.length > 0) {
54 | Pair p = data[0];
55 | setState(() {
56 | _detailPair = p;
57 | // testData(p);
58 | });
59 | if (_nowSize != null && _nowSize == GNMainViewSize.small) {
60 | Nav().push(DetailView(pair: p));
61 | }
62 | }
63 | }
64 |
65 | loadData() async {
66 | // GNConfigManager manager = GNConfigManager();
67 | // await manager.loadConfig();
68 | // ConfigModel m = manager.model;
69 | // if (m.path.length > 0) {
70 | // // TODO: There is no implementation failure time
71 | // await GNFileManager().tryOpenLastPath();
72 | // } else {
73 | // GNAlert(
74 | // title: 'Tip',
75 | // content: 'You need select folder',
76 | // onPressedOK: (a) async {
77 | // GNMethodChannelModel model = await GNFileManager().openFilePath();
78 | // if (model.body['info'] == 'ok') {
79 | // a.close();
80 | // }
81 | // }).show();
82 | // // await _showMyDialog();
83 | // }
84 | }
85 |
86 | changeMainViewStatus(GNMainViewStatus status) {
87 | if (status != _mainViewStatus) {
88 | setState(() {
89 | _mainViewStatus = status;
90 | });
91 | }
92 | }
93 |
94 | @override
95 | Widget build(BuildContext context) {
96 | return GNResponsive.getResponsive((GNMainViewSize s) {
97 | _nowSize = s;
98 | return Row(children: [
99 | Visibility(
100 | visible: GNMainViewSize.big == s,
101 | child: _menu,
102 | ),
103 | Visibility(
104 | visible: _nowSel == 0,
105 | child: Expanded(
106 | child: Row(
107 | children: [
108 | Expanded(
109 | child: _list,
110 | flex: GNMainViewSize.big == s ? 1 : 2,
111 | ),
112 | Visibility(
113 | visible:
114 | GNMainViewSize.big == s || GNMainViewSize.middle == s,
115 | child: Expanded(
116 | child: DetailView(pair: _detailPair),
117 | flex: 2,
118 | ),
119 | )
120 | ],
121 | ),
122 | )),
123 | Visibility(visible: _nowSel == 1, child: Expanded(child: TestView()))
124 | ]);
125 | });
126 | // return Flex(
127 | // direction: Axis.horizontal,
128 | // children: [_menu, _list, Expanded(child: _detail)]);
129 | // return GNResponsive.getResponsive((GNMainViewSize s) {
130 | // bool isShowMenu = true;
131 | // bool isShowList = true;
132 | // bool isShowDetail = true;
133 | // switch (s) {
134 | // case GNMainViewSize.middle:
135 | // case GNMainViewSize.small:
136 | // isShowMenu = true;
137 | // isShowDetail = true;
138 | // isShowList = true;
139 | // break;
140 | // case GNMainViewSize.big:
141 | // default:
142 | // isShowMenu = true;
143 | // isShowList = true;
144 | // isShowDetail = true;
145 | // break;
146 | // }
147 | // if (_mainViewStatus == GNMainViewStatus.detail) {
148 | // isShowMenu = false;
149 | // isShowList = false;
150 | // }
151 | // return Flex(direction: Axis.horizontal, children: [
152 | // Visibility(
153 | // visible: isShowMenu,
154 | // child: _menu,
155 | // ),
156 | // s == GNMainViewSize.small
157 | // ? Expanded(
158 | // child: Visibility(
159 | // visible: isShowList,
160 | // child: _list,
161 | // ))
162 | // : Visibility(
163 | // visible: isShowList,
164 | // child: _list,
165 | // ),
166 | // s == GNMainViewSize.small
167 | // ? Visibility(
168 | // visible: isShowDetail,
169 | // child: _detail,
170 | // )
171 | // : Expanded(
172 | // child: Visibility(
173 | // visible: isShowDetail,
174 | // child: _detail,
175 | // ),
176 | // )
177 | // ]);
178 | // });
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/stocks/lib/pages/menu_view/menu_view.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:flutter/rendering.dart';
3 | import 'package:stocks/components/text/text.dart';
4 | import 'package:stocks/manager/theme_manager.dart';
5 | import 'package:stocks/pages/page_action.dart';
6 |
7 | class MenuView extends StatefulWidget {
8 | final int defaultSel;
9 | MenuView(this.defaultSel);
10 | @override
11 | _MenuViewState createState() => _MenuViewState();
12 | }
13 |
14 | class _MenuViewState extends State {
15 |
16 | @override
17 | Widget build(BuildContext context) {
18 | GNTheme theme = GNTheme(context);
19 | return Container(
20 | margin: EdgeInsets.only(top: 35, left: 8, right: 8),
21 | width: 50,
22 | color: Colors.transparent,
23 | child: Column(
24 | children: [
25 | IconButton(onPressed: (){
26 | GNPagesAction().callAction(PageName.main, FuncName.clickMenu, data: [0]);
27 | }, icon: Icon(Icons.list), color: GNTheme().fontColorType(FontColorType.bright),),
28 | IconButton(
29 | onPressed: () {
30 | GNPagesAction()
31 | .callAction(PageName.main, FuncName.clickMenu, data: [1]);
32 | },
33 | icon: Icon(Icons.male),
34 | color: GNTheme().fontColorType(FontColorType.bright),
35 | )
36 | ],
37 | ),
38 | );
39 | }
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/stocks/lib/pages/page_action.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import '../tools/GNLog.dart';
3 | enum PageName { main, menu, list, detail }
4 | enum FuncName { clickMenu, clickStock }
5 |
6 | typedef void PageAction(PageName name, FuncName funcName, {List? data});
7 |
8 | /// 用以同级 widget 之间调取方法 ,包含注册方法,调取方法,销毁方法
9 | class GNPagesAction {
10 | static GNPagesAction? _m;
11 | final Map>> actionMap = {};
12 |
13 | factory GNPagesAction() {
14 | if (_m == null) {
15 | _m = GNPagesAction._internal();
16 | }
17 | return _m!;
18 | }
19 |
20 | // call func
21 | callAction(PageName pageName, FuncName funcName, {List? data}) {
22 | if (actionMap[pageName] == null) {
23 | actionMap[pageName] = {};
24 | }
25 | Map? funcMap = actionMap[pageName]![funcName];
26 | if (funcMap != null) {
27 | funcMap.forEach((key, value) {
28 | if (value != null) {
29 | value(pageName, funcName, data: data);
30 | GNLog.log('$pageName=>$funcName:${data.toString()}');
31 | } else {
32 | GNLog.w('no func $pageName=>$funcName:${data.toString()}');
33 | }
34 | });
35 | }
36 | }
37 |
38 | // register func
39 | registerAction(
40 | PageName pageName, FuncName funcName, Widget widget, PageAction action) {
41 | if (actionMap[pageName] == null) {
42 | actionMap[pageName] = {};
43 | }
44 | if (actionMap[pageName]![funcName] == null) {
45 | actionMap[pageName]![funcName] = {};
46 | }
47 | if (actionMap[pageName]![funcName]![widget.toString()] == null) {
48 | actionMap[pageName]![funcName]![widget.toString()] = action;
49 | }
50 | }
51 |
52 | // dispose func 销毁,注册和销毁应该成对出现,销毁应该在调用者被销毁时调用此方法
53 | disposeAction(Widget widget) {
54 | actionMap.forEach((pageName, value) {
55 | value.forEach((funcName, value2) {
56 | value2.forEach((widgetName, action) {
57 | if (widgetName == widget.toString() && action != null) {
58 | actionMap[pageName]![funcName]![widgetName] = null;
59 | }
60 | });
61 | });
62 | });
63 | }
64 |
65 | GNPagesAction._internal();
66 | }
67 |
--------------------------------------------------------------------------------
/stocks/lib/pages/test/test.dart:
--------------------------------------------------------------------------------
1 | import 'dart:convert';
2 | import 'dart:math';
3 | import 'dart:ui';
4 |
5 | import 'package:flutter/gestures.dart';
6 | import 'package:flutter/material.dart';
7 | import 'package:flutter/services.dart';
8 |
9 | class PaintModel {
10 | Point sourcePoint = Point(0, 0);
11 | Point convertPoint = Point(0, 0);
12 | double perX = 0;
13 | double perY = 0;
14 |
15 | @override
16 | String toString() {
17 | return "$sourcePoint => $convertPoint";
18 | }
19 | }
20 |
21 | class PaintConfig {
22 | int get paintWidth {
23 | return width * pointSize;
24 | }
25 |
26 | int get paintHeight {
27 | return height * pointSize;
28 | }
29 |
30 | int width = 0;
31 | int height = 0;
32 | int pointSize = 5;
33 | double pro = 0;
34 | Color color = Colors.cyan;
35 | }
36 |
37 | class TestView extends StatefulWidget {
38 | const TestView({Key? key}) : super(key: key);
39 |
40 | @override
41 | _TestViewState createState() => _TestViewState();
42 | }
43 |
44 | class _TestViewState extends State {
45 | List _models = [];
46 | PaintConfig _config = PaintConfig();
47 |
48 | @override
49 | void initState() {
50 | rootBundle.loadString('lib/src/map.json').then((value) {
51 | List source = JsonDecoder().convert(value);
52 | List models = [];
53 | List xL = [];
54 | List yL = [];
55 |
56 | int unitL = 0;
57 | int unitLm = 1000;
58 | source.forEach((s) {
59 | PaintModel m = PaintModel();
60 | double x = s["x"];
61 | double y = s["y"];
62 | m.sourcePoint = Point(x, y);
63 | xL.add(x);
64 | yL.add(y);
65 |
66 | int t = max(x.toString().length, y.toString().length);
67 | int tm = min(x.toString().length, y.toString().length);
68 | unitL = t > unitL ? t : unitL;
69 | unitLm = unitLm < tm ? unitLm : tm;
70 | models.add(m);
71 | });
72 |
73 | double maxX = xL.reduce(max);
74 | double minX = xL.reduce(min);
75 |
76 | double rX = maxX - minX;
77 |
78 | double maxY = yL.reduce(max);
79 | double minY = yL.reduce(min);
80 |
81 | double rY = maxY - minY;
82 |
83 | int width = 0;
84 | int height = 0;
85 | if (rX.abs() < 1 && rY.abs() < 1) {
86 | int mag = pow(10, unitLm).toInt();
87 | print("$mag $unitLm $unitL");
88 | width = (rX * mag).toInt();
89 | height = (rY * mag).toInt();
90 | }
91 | // 人为干预尺寸比例
92 | height = (height * 0.5).toInt();
93 | models.forEach((m) {
94 | m.perX = (m.sourcePoint.x - minX) / rX;
95 | m.perY = (m.sourcePoint.y - minY) / rY;
96 | double x = m.perX * width;
97 | double y = m.perY * height;
98 | m.convertPoint = Point(x.toInt(), y.toInt());
99 | });
100 |
101 | // print(models);
102 |
103 | _config.width = width;
104 | _config.height = height;
105 | _config.pro = width / height;
106 | // print("$rY $rY $minX $minY $width $height");
107 | setState(() {
108 | _models = models;
109 | });
110 | });
111 | super.initState();
112 | }
113 |
114 | @override
115 | Widget build(BuildContext context) {
116 | return Center(
117 | child: CustomPaint(
118 | child: Container(),
119 | painter: Painter(_models, _config),
120 | ),
121 | );
122 | }
123 | }
124 |
125 | class Painter extends CustomPainter {
126 | List models = [];
127 | PaintConfig config = PaintConfig();
128 |
129 | Painter(this.models, this.config);
130 | @override
131 | void paint(Canvas canvas, Size size) {
132 | // print(size);
133 | Size size_ = Size(0, 0);
134 | if (size.width > size.height) {
135 | size_ = Size(size.width, size.width / config.pro);
136 | } else {
137 | size_ = Size(size.width, size.height / config.pro);
138 | }
139 |
140 | print("$size $size_ ${config.width} ${config.height}");
141 | double pointSize = config.pointSize.toDouble();
142 | if (models.length > 0) {
143 | Paint paint = Paint();
144 | paint.color = config.color;
145 | paint.strokeWidth = pointSize;
146 | paint.strokeCap = StrokeCap.round;
147 | List points = [];
148 | models.forEach((element) {
149 | // point
150 | points.add(Offset(element.perX * size_.width - pointSize, element.perY * size_.height - pointSize));
151 | });
152 | canvas.drawPoints(PointMode.points, points, paint);
153 | }
154 | }
155 |
156 | @override
157 | bool shouldRepaint(covariant CustomPainter oldDelegate) {
158 | // TODO: implement shouldRepaint
159 | return true;
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/stocks/lib/tools/GNLog.dart:
--------------------------------------------------------------------------------
1 | class GNLog {
2 | static void log(Object object) {
3 | DateTime time = DateTime.now();
4 | _log('GNLog: ${time.toString()} \n ${object} \n ======');
5 | }
6 |
7 | static void w(Object object) {
8 | DateTime time = DateTime.now();
9 | _log('**Warning! GNLog: ${time.toString()} \n ${object} \n ******');
10 | }
11 |
12 | static void e(Object object) {
13 | DateTime time = DateTime.now();
14 | _log('######ERROR! GNLog: ${time.toString()} \n ${object} \n ######');
15 | }
16 |
17 | static void _log(Object object) {
18 | print(object);
19 | }
20 | }
--------------------------------------------------------------------------------
/stocks/lib/tools/tools.dart:
--------------------------------------------------------------------------------
1 | import 'dart:async';
2 | class GNTools {
3 |
4 | Timer? timer;
5 | /// 函数防抖
6 | ///
7 | /// [func]: 要执行的方法
8 | /// [delay]: 要迟延的时长
9 | Function debounce( Function func, [int milliseconds = 2000]) {
10 |
11 | Duration delay = Duration(milliseconds: milliseconds);
12 | Function target = (value) {
13 | if (timer != null && timer!.isActive) {
14 | timer!.cancel();
15 | timer = null;
16 | }
17 | timer = Timer(delay, () {
18 | Function.apply(func, value);
19 | });
20 | };
21 | return target;
22 | }
23 |
24 | /// 函数节流
25 | ///
26 | /// [func]: 要执行的方法
27 | Function throttle(Function func, [int milliseconds = 0]) {
28 | bool enable = true;
29 | Function target = (value) {
30 | if (enable == true) {
31 | enable = false;
32 | Function.apply(func, value).then((_) {
33 | if (milliseconds <= 0) {
34 | enable = true;
35 | } else {
36 | Duration delay = Duration(milliseconds: milliseconds);
37 | Timer(delay, () {
38 | enable = true;
39 | });
40 | }
41 | });
42 | }
43 | };
44 | return target;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/stocks/lib/window/window.dart:
--------------------------------------------------------------------------------
1 | import 'dart:io';
2 |
3 | import 'package:flutter/material.dart';
4 | import 'dart:ui';
5 | import 'package:provider/provider.dart';
6 | import '../manager/localizations_manager.dart';
7 | import '../manager/theme_manager.dart';
8 | import '../nav/nav.dart';
9 | import '../pages/main_view/main_view.dart';
10 |
11 | class Window extends StatefulWidget {
12 | Window({Key? key}) : super(key: key);
13 | @override
14 | _Window createState() => _Window();
15 | }
16 |
17 | class _Window extends State {
18 | Widget? zeroPage;
19 | @override
20 | void initState() {
21 | // init managers
22 | super.initState();
23 | }
24 |
25 | @override
26 | Widget build(BuildContext context) {
27 | Color bg = Colors.white;
28 | if (Platform.isMacOS) {
29 | bg = Colors.transparent;
30 | }
31 | ThemeData themeData = ThemeData(
32 | textSelectionTheme: TextSelectionThemeData(
33 | selectionColor: GNTheme().fontColorType(FontColorType.highlight)),
34 | backgroundColor: bg,
35 | brightness: Brightness.light,
36 | buttonTheme: ButtonThemeData(
37 | minWidth: 0,
38 | height: 0,
39 | buttonColor: Colors.transparent,
40 | padding: EdgeInsets.all(0),
41 | shape: RoundedRectangleBorder(
42 | borderRadius: BorderRadius.circular(4))));
43 | ThemeData darkThemeData = ThemeData(
44 | textSelectionTheme: TextSelectionThemeData(
45 | selectionColor: GNTheme().fontColorType(FontColorType.highlight)),
46 | backgroundColor: bg,
47 | brightness: Brightness.dark,
48 | buttonTheme: ButtonThemeData(
49 | minWidth: 0,
50 | height: 0,
51 | buttonColor: Colors.transparent,
52 | padding: EdgeInsets.all(0),
53 | shape: RoundedRectangleBorder(
54 | borderRadius: BorderRadius.circular(4))));
55 |
56 | // nav.setZeroPage(Container(width: 300, height: 300, color: Colors.blue.withAlpha(0)));
57 | return ChangeNotifierProvider(
58 | create: (_) => GNTheme(),
59 | child: MaterialApp(
60 | // color: bg,
61 | theme: themeData,
62 | darkTheme: darkThemeData,
63 | title: 'Stocks',
64 | home: Scaffold(
65 | body: SafeArea(child: Nav(MainPage())),
66 | backgroundColor: bg,
67 | ),
68 | localizationsDelegates: GNLocalizations.localizationsDelegates,
69 | supportedLocales: GNLocalizations.supportedLocales,
70 | ),
71 | );
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/stocks/linux/.gitignore:
--------------------------------------------------------------------------------
1 | flutter/ephemeral
2 |
--------------------------------------------------------------------------------
/stocks/linux/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.10)
2 | project(runner LANGUAGES CXX)
3 |
4 | set(BINARY_NAME "stocks")
5 | set(APPLICATION_ID "com.example.stocks")
6 |
7 | cmake_policy(SET CMP0063 NEW)
8 |
9 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
10 |
11 | # Root filesystem for cross-building.
12 | if(FLUTTER_TARGET_PLATFORM_SYSROOT)
13 | set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT})
14 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
15 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
16 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
17 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
18 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
19 | endif()
20 |
21 | # Configure build options.
22 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
23 | set(CMAKE_BUILD_TYPE "Debug" CACHE
24 | STRING "Flutter build mode" FORCE)
25 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
26 | "Debug" "Profile" "Release")
27 | endif()
28 |
29 | # Compilation settings that should be applied to most targets.
30 | function(APPLY_STANDARD_SETTINGS TARGET)
31 | target_compile_features(${TARGET} PUBLIC cxx_std_14)
32 | target_compile_options(${TARGET} PRIVATE -Wall -Werror)
33 | target_compile_options(${TARGET} PRIVATE "$<$>:-O3>")
34 | target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>")
35 | endfunction()
36 |
37 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
38 |
39 | # Flutter library and tool build rules.
40 | add_subdirectory(${FLUTTER_MANAGED_DIR})
41 |
42 | # System-level dependencies.
43 | find_package(PkgConfig REQUIRED)
44 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
45 |
46 | add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
47 |
48 | # Application build
49 | add_executable(${BINARY_NAME}
50 | "main.cc"
51 | "my_application.cc"
52 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
53 | )
54 | apply_standard_settings(${BINARY_NAME})
55 | target_link_libraries(${BINARY_NAME} PRIVATE flutter)
56 | target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
57 | add_dependencies(${BINARY_NAME} flutter_assemble)
58 | # Only the install-generated bundle's copy of the executable will launch
59 | # correctly, since the resources must in the right relative locations. To avoid
60 | # people trying to run the unbundled copy, put it in a subdirectory instead of
61 | # the default top-level location.
62 | set_target_properties(${BINARY_NAME}
63 | PROPERTIES
64 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"
65 | )
66 |
67 | # Generated plugin build rules, which manage building the plugins and adding
68 | # them to the application.
69 | include(flutter/generated_plugins.cmake)
70 |
71 |
72 | # === Installation ===
73 | # By default, "installing" just makes a relocatable bundle in the build
74 | # directory.
75 | set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
76 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
77 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
78 | endif()
79 |
80 | # Start with a clean build bundle directory every time.
81 | install(CODE "
82 | file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\")
83 | " COMPONENT Runtime)
84 |
85 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
86 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
87 |
88 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
89 | COMPONENT Runtime)
90 |
91 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
92 | COMPONENT Runtime)
93 |
94 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
95 | COMPONENT Runtime)
96 |
97 | if(PLUGIN_BUNDLED_LIBRARIES)
98 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
99 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
100 | COMPONENT Runtime)
101 | endif()
102 |
103 | # Fully re-copy the assets directory on each build to avoid having stale files
104 | # from a previous install.
105 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
106 | install(CODE "
107 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
108 | " COMPONENT Runtime)
109 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
110 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
111 |
112 | # Install the AOT library on non-Debug builds only.
113 | if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
114 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
115 | COMPONENT Runtime)
116 | endif()
117 |
--------------------------------------------------------------------------------
/stocks/linux/flutter/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.10)
2 |
3 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
4 |
5 | # Configuration provided via flutter tool.
6 | include(${EPHEMERAL_DIR}/generated_config.cmake)
7 |
8 | # TODO: Move the rest of this into files in ephemeral. See
9 | # https://github.com/flutter/flutter/issues/57146.
10 |
11 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...),
12 | # which isn't available in 3.10.
13 | function(list_prepend LIST_NAME PREFIX)
14 | set(NEW_LIST "")
15 | foreach(element ${${LIST_NAME}})
16 | list(APPEND NEW_LIST "${PREFIX}${element}")
17 | endforeach(element)
18 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE)
19 | endfunction()
20 |
21 | # === Flutter Library ===
22 | # System-level dependencies.
23 | find_package(PkgConfig REQUIRED)
24 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
25 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
26 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0)
27 |
28 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so")
29 |
30 | # Published to parent scope for install step.
31 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
32 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
33 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
34 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE)
35 |
36 | list(APPEND FLUTTER_LIBRARY_HEADERS
37 | "fl_basic_message_channel.h"
38 | "fl_binary_codec.h"
39 | "fl_binary_messenger.h"
40 | "fl_dart_project.h"
41 | "fl_engine.h"
42 | "fl_json_message_codec.h"
43 | "fl_json_method_codec.h"
44 | "fl_message_codec.h"
45 | "fl_method_call.h"
46 | "fl_method_channel.h"
47 | "fl_method_codec.h"
48 | "fl_method_response.h"
49 | "fl_plugin_registrar.h"
50 | "fl_plugin_registry.h"
51 | "fl_standard_message_codec.h"
52 | "fl_standard_method_codec.h"
53 | "fl_string_codec.h"
54 | "fl_value.h"
55 | "fl_view.h"
56 | "flutter_linux.h"
57 | )
58 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/")
59 | add_library(flutter INTERFACE)
60 | target_include_directories(flutter INTERFACE
61 | "${EPHEMERAL_DIR}"
62 | )
63 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}")
64 | target_link_libraries(flutter INTERFACE
65 | PkgConfig::GTK
66 | PkgConfig::GLIB
67 | PkgConfig::GIO
68 | )
69 | add_dependencies(flutter flutter_assemble)
70 |
71 | # === Flutter tool backend ===
72 | # _phony_ is a non-existent file to force this command to run every time,
73 | # since currently there's no way to get a full input/output list from the
74 | # flutter tool.
75 | add_custom_command(
76 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
77 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_
78 | COMMAND ${CMAKE_COMMAND} -E env
79 | ${FLUTTER_TOOL_ENVIRONMENT}
80 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
81 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE}
82 | VERBATIM
83 | )
84 | add_custom_target(flutter_assemble DEPENDS
85 | "${FLUTTER_LIBRARY}"
86 | ${FLUTTER_LIBRARY_HEADERS}
87 | )
88 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/linux/flutter/generated_plugins.cmake:
--------------------------------------------------------------------------------
1 | #
2 | # Generated file, do not edit.
3 | #
4 |
5 | list(APPEND FLUTTER_PLUGIN_LIST
6 | )
7 |
8 | set(PLUGIN_BUNDLED_LIBRARIES)
9 |
10 | foreach(plugin ${FLUTTER_PLUGIN_LIST})
11 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin})
12 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
13 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $)
14 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
15 | endforeach(plugin)
16 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/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, "stocks");
44 | gtk_header_bar_set_show_close_button(header_bar, TRUE);
45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));
46 | }
47 | else {
48 | gtk_window_set_title(window, "stocks");
49 | }
50 |
51 | gtk_window_set_default_size(window, 1280, 720);
52 | gtk_widget_show(GTK_WIDGET(window));
53 |
54 | g_autoptr(FlDartProject) project = fl_dart_project_new();
55 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);
56 |
57 | FlView* view = fl_view_new(project);
58 | gtk_widget_show(GTK_WIDGET(view));
59 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
60 |
61 | fl_register_plugins(FL_PLUGIN_REGISTRY(view));
62 |
63 | gtk_widget_grab_focus(GTK_WIDGET(view));
64 | }
65 |
66 | // Implements GApplication::local_command_line.
67 | static gboolean my_application_local_command_line(GApplication* application, gchar ***arguments, int *exit_status) {
68 | MyApplication* self = MY_APPLICATION(application);
69 | // Strip out the first argument as it is the binary name.
70 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1);
71 |
72 | g_autoptr(GError) error = nullptr;
73 | if (!g_application_register(application, nullptr, &error)) {
74 | g_warning("Failed to register: %s", error->message);
75 | *exit_status = 1;
76 | return TRUE;
77 | }
78 |
79 | g_application_activate(application);
80 | *exit_status = 0;
81 |
82 | return TRUE;
83 | }
84 |
85 | // Implements GObject::dispose.
86 | static void my_application_dispose(GObject *object) {
87 | MyApplication* self = MY_APPLICATION(object);
88 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev);
89 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object);
90 | }
91 |
92 | static void my_application_class_init(MyApplicationClass* klass) {
93 | G_APPLICATION_CLASS(klass)->activate = my_application_activate;
94 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line;
95 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose;
96 | }
97 |
98 | static void my_application_init(MyApplication* self) {}
99 |
100 | MyApplication* my_application_new() {
101 | return MY_APPLICATION(g_object_new(my_application_get_type(),
102 | "application-id", APPLICATION_ID,
103 | "flags", G_APPLICATION_NON_UNIQUE,
104 | nullptr));
105 | }
106 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/macos/.gitignore:
--------------------------------------------------------------------------------
1 | # Flutter-related
2 | **/Flutter/ephemeral/
3 | **/Pods/
4 |
5 | # Xcode-related
6 | **/xcuserdata/
7 |
--------------------------------------------------------------------------------
/stocks/macos/Flutter/Flutter-Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include "ephemeral/Flutter-Generated.xcconfig"
2 |
--------------------------------------------------------------------------------
/stocks/macos/Flutter/Flutter-Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include "ephemeral/Flutter-Generated.xcconfig"
2 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/stocks/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 |
64 |
65 |
71 |
73 |
79 |
80 |
81 |
82 |
84 |
85 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/stocks/macos/Runner.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/stocks/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png
--------------------------------------------------------------------------------
/stocks/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png
--------------------------------------------------------------------------------
/stocks/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png
--------------------------------------------------------------------------------
/stocks/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png
--------------------------------------------------------------------------------
/stocks/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png
--------------------------------------------------------------------------------
/stocks/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png
--------------------------------------------------------------------------------
/stocks/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png
--------------------------------------------------------------------------------
/stocks/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 = stocks
9 |
10 | // The application's bundle identifier
11 | PRODUCT_BUNDLE_IDENTIFIER = com.example.stocks
12 |
13 | // The copyright displayed in application information
14 | PRODUCT_COPYRIGHT = Copyright © 2021 com.example. All rights reserved.
15 |
--------------------------------------------------------------------------------
/stocks/macos/Runner/Configs/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include "../../Flutter/Flutter-Debug.xcconfig"
2 | #include "Warnings.xcconfig"
3 |
--------------------------------------------------------------------------------
/stocks/macos/Runner/Configs/Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include "../../Flutter/Flutter-Release.xcconfig"
2 | #include "Warnings.xcconfig"
3 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/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 | com.apple.security.network.client
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/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 | self.minSize = NSSize.init(width: 320, height: 600)
11 |
12 | // 本地注册插件
13 | // self.registerGeneratedPlugins(registry: flutterViewController)
14 | RegisterGeneratedPlugins(registry: flutterViewController)
15 |
16 |
17 | /* Hiding the window titlebar */
18 | // self.titleVisibility = NSWindow.TitleVisibility.hidden;
19 | // self.titlebarAppearsTransparent = true;
20 | // self.isMovableByWindowBackground = true;
21 | // self.standardWindowButton(NSWindow.ButtonType.miniaturizeButton)?.isEnabled = false;
22 |
23 | /* Making the window transparent */
24 | self.isOpaque = false
25 | self.backgroundColor = .clear
26 |
27 | /* Adding a NSVisualEffectView to act as a translucent background */
28 | let contentView = contentViewController!.view;
29 | let superView = contentView.superview!;
30 |
31 | let blurView = NSVisualEffectView()
32 | blurView.frame = superView.bounds
33 | blurView.autoresizingMask = [.width, .height]
34 | blurView.blendingMode = NSVisualEffectView.BlendingMode.behindWindow
35 | blurView.state = NSVisualEffectView.State.active
36 |
37 | /* Pick the correct material for the task */
38 | if #available(OSX 10.14, *) {
39 | blurView.material = NSVisualEffectView.Material.underWindowBackground
40 | } else {
41 | blurView.material = NSVisualEffectView.Material.appearanceBased
42 | // Fallback on earlier versions
43 | }
44 |
45 | /* Replace the contentView and the background view */
46 | superView.replaceSubview(contentView, with: blurView)
47 | blurView.addSubview(contentView)
48 |
49 | super.awakeFromNib()
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/stocks/macos/Runner/Release.entitlements:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.app-sandbox
6 |
7 | com.apple.security.network.client
8 |
9 | com.apple.security.network.server
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/stocks/macos/Runner/stocksProfile.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.client
10 |
11 | com.apple.security.network.server
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/stocks/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: stocks
2 | description: A new Flutter project.
3 |
4 | # The following line prevents the package from being accidentally published to
5 | # pub.dev using `pub publish`. This is preferred for private packages.
6 | publish_to: 'none' # Remove this line if you wish to publish to pub.dev
7 |
8 | # The following defines the version and build number for your application.
9 | # A version number is three numbers separated by dots, like 1.2.43
10 | # followed by an optional build number separated by a +.
11 | # Both the version and the builder number may be overridden in flutter
12 | # build by specifying --build-name and --build-number, respectively.
13 | # In Android, build-name is used as versionName while build-number used as versionCode.
14 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning
15 | # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
16 | # Read more about iOS versioning at
17 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
18 | version: 1.0.0+1
19 |
20 | environment:
21 | sdk: ">=2.12.0 <3.0.0"
22 |
23 | dependencies:
24 | flutter:
25 | sdk: flutter
26 | provider:
27 | dio:
28 | web_socket_channel:
29 | flutter_staggered_grid_view:
30 | flutter_localizations:
31 | sdk: flutter
32 |
33 |
34 | # The following adds the Cupertino Icons font to your application.
35 | # Use with the CupertinoIcons class for iOS style icons.
36 | cupertino_icons: ^1.0.2
37 |
38 | dev_dependencies:
39 | flutter_test:
40 | sdk: flutter
41 |
42 | # For information on the generic Dart part of this file, see the
43 | # following page: https://dart.dev/tools/pub/pubspec
44 |
45 | # The following section is specific to Flutter.
46 | flutter:
47 |
48 | # The following line ensures that the Material Icons font is
49 | # included with your application, so that you can use the icons in
50 | # the material Icons class.
51 | uses-material-design: true
52 |
53 | # To add assets to your application, add an assets section, like this:
54 | assets:
55 | - lib/src/map.json
56 | # - images/a_dot_burr.jpeg
57 | # - images/a_dot_ham.jpeg
58 |
59 | # An image asset can refer to one or more resolution-specific "variants", see
60 | # https://flutter.dev/assets-and-images/#resolution-aware.
61 |
62 | # For details regarding adding assets from package dependencies, see
63 | # https://flutter.dev/assets-and-images/#from-packages
64 |
65 | # To add custom fonts to your application, add a fonts section here,
66 | # in this "flutter" section. Each entry in this list should have a
67 | # "family" key with the font family name, and a "fonts" key with a
68 | # list giving the asset and other descriptors for the font. For
69 | # example:
70 | # fonts:
71 | # - family: Schyler
72 | # fonts:
73 | # - asset: fonts/Schyler-Regular.ttf
74 | # - asset: fonts/Schyler-Italic.ttf
75 | # style: italic
76 | # - family: Trajan Pro
77 | # fonts:
78 | # - asset: fonts/TrajanPro.ttf
79 | # - asset: fonts/TrajanPro_Bold.ttf
80 | # weight: 700
81 | #
82 | # For details regarding fonts from package dependencies,
83 | # see https://flutter.dev/custom-fonts/#from-packages
84 |
--------------------------------------------------------------------------------
/stocks/test/widget_test.dart:
--------------------------------------------------------------------------------
1 | // This is a basic Flutter widget test.
2 | //
3 | // To perform an interaction with a widget in your test, use the WidgetTester
4 | // utility that Flutter provides. For example, you can send tap and scroll
5 | // gestures. You can also use WidgetTester to find child widgets in the widget
6 | // tree, read text, and verify that the values of widget properties are correct.
7 |
8 | import 'package:flutter/material.dart';
9 | import 'package:flutter_test/flutter_test.dart';
10 |
11 | import 'package:stocks/main.dart';
12 |
13 | void main() {
14 | testWidgets('Counter increments smoke test', (WidgetTester tester) async {
15 | // Build our app and trigger a frame.
16 | await tester.pumpWidget(MyApp());
17 |
18 | // Verify that our counter starts at 0.
19 | expect(find.text('0'), findsOneWidget);
20 | expect(find.text('1'), findsNothing);
21 |
22 | // Tap the '+' icon and trigger a frame.
23 | await tester.tap(find.byIcon(Icons.add));
24 | await tester.pump();
25 |
26 | // Verify that our counter has incremented.
27 | expect(find.text('0'), findsNothing);
28 | expect(find.text('1'), findsOneWidget);
29 | });
30 | }
31 |
--------------------------------------------------------------------------------
/stocks/web/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/web/favicon.png
--------------------------------------------------------------------------------
/stocks/web/icons/Icon-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/web/icons/Icon-192.png
--------------------------------------------------------------------------------
/stocks/web/icons/Icon-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/web/icons/Icon-512.png
--------------------------------------------------------------------------------
/stocks/web/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | stocks
27 |
28 |
29 |
30 |
33 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/stocks/web/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "stocks",
3 | "short_name": "stocks",
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 | }
24 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/windows/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.15)
2 | project(stocks LANGUAGES CXX)
3 |
4 | set(BINARY_NAME "stocks")
5 |
6 | cmake_policy(SET CMP0063 NEW)
7 |
8 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
9 |
10 | # Configure build options.
11 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
12 | if(IS_MULTICONFIG)
13 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
14 | CACHE STRING "" FORCE)
15 | else()
16 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
17 | set(CMAKE_BUILD_TYPE "Debug" CACHE
18 | STRING "Flutter build mode" FORCE)
19 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
20 | "Debug" "Profile" "Release")
21 | endif()
22 | endif()
23 |
24 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
25 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
26 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
27 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
28 |
29 | # Use Unicode for all projects.
30 | add_definitions(-DUNICODE -D_UNICODE)
31 |
32 | # Compilation settings that should be applied to most targets.
33 | function(APPLY_STANDARD_SETTINGS TARGET)
34 | target_compile_features(${TARGET} PUBLIC cxx_std_17)
35 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
36 | target_compile_options(${TARGET} PRIVATE /EHsc)
37 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
38 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>")
39 | endfunction()
40 |
41 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
42 |
43 | # Flutter library and tool build rules.
44 | add_subdirectory(${FLUTTER_MANAGED_DIR})
45 |
46 | # Application build
47 | add_subdirectory("runner")
48 |
49 | # Generated plugin build rules, which manage building the plugins and adding
50 | # them to the application.
51 | include(flutter/generated_plugins.cmake)
52 |
53 |
54 | # === Installation ===
55 | # Support files are copied into place next to the executable, so that it can
56 | # run in place. This is done instead of making a separate bundle (as on Linux)
57 | # so that building and running from within Visual Studio will work.
58 | set(BUILD_BUNDLE_DIR "$")
59 | # Make the "install" step default, as it's required to run.
60 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
61 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
62 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
63 | endif()
64 |
65 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
66 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}")
67 |
68 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
69 | COMPONENT Runtime)
70 |
71 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
72 | COMPONENT Runtime)
73 |
74 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
75 | COMPONENT Runtime)
76 |
77 | if(PLUGIN_BUNDLED_LIBRARIES)
78 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
79 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
80 | COMPONENT Runtime)
81 | endif()
82 |
83 | # Fully re-copy the assets directory on each build to avoid having stale files
84 | # from a previous install.
85 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
86 | install(CODE "
87 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
88 | " COMPONENT Runtime)
89 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
90 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
91 |
92 | # Install the AOT library on non-Debug builds only.
93 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
94 | CONFIGURATIONS Profile;Release
95 | COMPONENT Runtime)
96 |
--------------------------------------------------------------------------------
/stocks/windows/flutter/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.15)
2 |
3 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
4 |
5 | # Configuration provided via flutter tool.
6 | include(${EPHEMERAL_DIR}/generated_config.cmake)
7 |
8 | # TODO: Move the rest of this into files in ephemeral. See
9 | # https://github.com/flutter/flutter/issues/57146.
10 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")
11 |
12 | # === Flutter Library ===
13 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")
14 |
15 | # Published to parent scope for install step.
16 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
17 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
18 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
19 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE)
20 |
21 | list(APPEND FLUTTER_LIBRARY_HEADERS
22 | "flutter_export.h"
23 | "flutter_windows.h"
24 | "flutter_messenger.h"
25 | "flutter_plugin_registrar.h"
26 | "flutter_texture_registrar.h"
27 | )
28 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/")
29 | add_library(flutter INTERFACE)
30 | target_include_directories(flutter INTERFACE
31 | "${EPHEMERAL_DIR}"
32 | )
33 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib")
34 | add_dependencies(flutter flutter_assemble)
35 |
36 | # === Wrapper ===
37 | list(APPEND CPP_WRAPPER_SOURCES_CORE
38 | "core_implementations.cc"
39 | "standard_codec.cc"
40 | )
41 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/")
42 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN
43 | "plugin_registrar.cc"
44 | )
45 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/")
46 | list(APPEND CPP_WRAPPER_SOURCES_APP
47 | "flutter_engine.cc"
48 | "flutter_view_controller.cc"
49 | )
50 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/")
51 |
52 | # Wrapper sources needed for a plugin.
53 | add_library(flutter_wrapper_plugin STATIC
54 | ${CPP_WRAPPER_SOURCES_CORE}
55 | ${CPP_WRAPPER_SOURCES_PLUGIN}
56 | )
57 | apply_standard_settings(flutter_wrapper_plugin)
58 | set_target_properties(flutter_wrapper_plugin PROPERTIES
59 | POSITION_INDEPENDENT_CODE ON)
60 | set_target_properties(flutter_wrapper_plugin PROPERTIES
61 | CXX_VISIBILITY_PRESET hidden)
62 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter)
63 | target_include_directories(flutter_wrapper_plugin PUBLIC
64 | "${WRAPPER_ROOT}/include"
65 | )
66 | add_dependencies(flutter_wrapper_plugin flutter_assemble)
67 |
68 | # Wrapper sources needed for the runner.
69 | add_library(flutter_wrapper_app STATIC
70 | ${CPP_WRAPPER_SOURCES_CORE}
71 | ${CPP_WRAPPER_SOURCES_APP}
72 | )
73 | apply_standard_settings(flutter_wrapper_app)
74 | target_link_libraries(flutter_wrapper_app PUBLIC flutter)
75 | target_include_directories(flutter_wrapper_app PUBLIC
76 | "${WRAPPER_ROOT}/include"
77 | )
78 | add_dependencies(flutter_wrapper_app flutter_assemble)
79 |
80 | # === Flutter tool backend ===
81 | # _phony_ is a non-existent file to force this command to run every time,
82 | # since currently there's no way to get a full input/output list from the
83 | # flutter tool.
84 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_")
85 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE)
86 | add_custom_command(
87 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
88 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN}
89 | ${CPP_WRAPPER_SOURCES_APP}
90 | ${PHONY_OUTPUT}
91 | COMMAND ${CMAKE_COMMAND} -E env
92 | ${FLUTTER_TOOL_ENVIRONMENT}
93 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
94 | windows-x64 $
95 | VERBATIM
96 | )
97 | add_custom_target(flutter_assemble DEPENDS
98 | "${FLUTTER_LIBRARY}"
99 | ${FLUTTER_LIBRARY_HEADERS}
100 | ${CPP_WRAPPER_SOURCES_CORE}
101 | ${CPP_WRAPPER_SOURCES_PLUGIN}
102 | ${CPP_WRAPPER_SOURCES_APP}
103 | )
104 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/windows/flutter/generated_plugins.cmake:
--------------------------------------------------------------------------------
1 | #
2 | # Generated file, do not edit.
3 | #
4 |
5 | list(APPEND FLUTTER_PLUGIN_LIST
6 | )
7 |
8 | set(PLUGIN_BUNDLED_LIBRARIES)
9 |
10 | foreach(plugin ${FLUTTER_PLUGIN_LIST})
11 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin})
12 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
13 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $)
14 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
15 | endforeach(plugin)
16 |
--------------------------------------------------------------------------------
/stocks/windows/runner/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.15)
2 | project(runner LANGUAGES CXX)
3 |
4 | add_executable(${BINARY_NAME} WIN32
5 | "flutter_window.cpp"
6 | "main.cpp"
7 | "run_loop.cpp"
8 | "utils.cpp"
9 | "win32_window.cpp"
10 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
11 | "Runner.rc"
12 | "runner.exe.manifest"
13 | )
14 | apply_standard_settings(${BINARY_NAME})
15 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
16 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
17 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
18 | add_dependencies(${BINARY_NAME} flutter_assemble)
19 |
--------------------------------------------------------------------------------
/stocks/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", "A new Flutter project." "\0"
94 | VALUE "FileVersion", VERSION_AS_STRING "\0"
95 | VALUE "InternalName", "stocks" "\0"
96 | VALUE "LegalCopyright", "Copyright (C) 2021 com.example. All rights reserved." "\0"
97 | VALUE "OriginalFilename", "stocks.exe" "\0"
98 | VALUE "ProductName", "stocks" "\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 |
--------------------------------------------------------------------------------
/stocks/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(RunLoop* run_loop,
8 | const flutter::DartProject& project)
9 | : run_loop_(run_loop), project_(project) {}
10 |
11 | FlutterWindow::~FlutterWindow() {}
12 |
13 | bool FlutterWindow::OnCreate() {
14 | if (!Win32Window::OnCreate()) {
15 | return false;
16 | }
17 |
18 | RECT frame = GetClientArea();
19 |
20 | // The size here must match the window dimensions to avoid unnecessary surface
21 | // creation / destruction in the startup path.
22 | flutter_controller_ = std::make_unique(
23 | frame.right - frame.left, frame.bottom - frame.top, project_);
24 | // Ensure that basic setup of the controller was successful.
25 | if (!flutter_controller_->engine() || !flutter_controller_->view()) {
26 | return false;
27 | }
28 | RegisterPlugins(flutter_controller_->engine());
29 | run_loop_->RegisterFlutterInstance(flutter_controller_->engine());
30 | SetChildContent(flutter_controller_->view()->GetNativeWindow());
31 | return true;
32 | }
33 |
34 | void FlutterWindow::OnDestroy() {
35 | if (flutter_controller_) {
36 | run_loop_->UnregisterFlutterInstance(flutter_controller_->engine());
37 | flutter_controller_ = nullptr;
38 | }
39 |
40 | Win32Window::OnDestroy();
41 | }
42 |
43 | LRESULT
44 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
45 | WPARAM const wparam,
46 | LPARAM const lparam) noexcept {
47 | // Give Flutter, including plugins, an opportunity to handle window messages.
48 | if (flutter_controller_) {
49 | std::optional result =
50 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,
51 | lparam);
52 | if (result) {
53 | return *result;
54 | }
55 | }
56 |
57 | switch (message) {
58 | case WM_FONTCHANGE:
59 | flutter_controller_->engine()->ReloadSystemFonts();
60 | break;
61 | }
62 |
63 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam);
64 | }
65 |
--------------------------------------------------------------------------------
/stocks/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 "run_loop.h"
10 | #include "win32_window.h"
11 |
12 | // A window that does nothing but host a Flutter view.
13 | class FlutterWindow : public Win32Window {
14 | public:
15 | // Creates a new FlutterWindow driven by the |run_loop|, hosting a
16 | // Flutter view running |project|.
17 | explicit FlutterWindow(RunLoop* run_loop,
18 | const flutter::DartProject& project);
19 | virtual ~FlutterWindow();
20 |
21 | protected:
22 | // Win32Window:
23 | bool OnCreate() override;
24 | void OnDestroy() override;
25 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam,
26 | LPARAM const lparam) noexcept override;
27 |
28 | private:
29 | // The run loop driving events for this window.
30 | RunLoop* run_loop_;
31 |
32 | // The project to run.
33 | flutter::DartProject project_;
34 |
35 | // The Flutter instance hosted by this window.
36 | std::unique_ptr flutter_controller_;
37 | };
38 |
39 | #endif // RUNNER_FLUTTER_WINDOW_H_
40 |
--------------------------------------------------------------------------------
/stocks/windows/runner/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "flutter_window.h"
6 | #include "run_loop.h"
7 | #include "utils.h"
8 |
9 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
10 | _In_ wchar_t *command_line, _In_ int show_command) {
11 | // Attach to console when present (e.g., 'flutter run') or create a
12 | // new console when running with a debugger.
13 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
14 | CreateAndAttachConsole();
15 | }
16 |
17 | // Initialize COM, so that it is available for use in the library and/or
18 | // plugins.
19 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
20 |
21 | RunLoop run_loop;
22 |
23 | flutter::DartProject project(L"data");
24 |
25 | std::vector command_line_arguments =
26 | GetCommandLineArguments();
27 |
28 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
29 |
30 | FlutterWindow window(&run_loop, project);
31 | Win32Window::Point origin(10, 10);
32 | Win32Window::Size size(1280, 720);
33 | if (!window.CreateAndShow(L"stocks", origin, size)) {
34 | return EXIT_FAILURE;
35 | }
36 | window.SetQuitOnClose(true);
37 |
38 | run_loop.Run();
39 |
40 | ::CoUninitialize();
41 | return EXIT_SUCCESS;
42 | }
43 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/windows/runner/resources/app_icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlutterTrip/Flutter_Kline/af81cabb9dc5f915c93b440636acd9f7e259a8b2/stocks/windows/runner/resources/app_icon.ico
--------------------------------------------------------------------------------
/stocks/windows/runner/run_loop.cpp:
--------------------------------------------------------------------------------
1 | #include "run_loop.h"
2 |
3 | #include
4 |
5 | #include
6 |
7 | RunLoop::RunLoop() {}
8 |
9 | RunLoop::~RunLoop() {}
10 |
11 | void RunLoop::Run() {
12 | bool keep_running = true;
13 | TimePoint next_flutter_event_time = TimePoint::clock::now();
14 | while (keep_running) {
15 | std::chrono::nanoseconds wait_duration =
16 | std::max(std::chrono::nanoseconds(0),
17 | next_flutter_event_time - TimePoint::clock::now());
18 | ::MsgWaitForMultipleObjects(
19 | 0, nullptr, FALSE, static_cast(wait_duration.count() / 1000),
20 | QS_ALLINPUT);
21 | bool processed_events = false;
22 | MSG message;
23 | // All pending Windows messages must be processed; MsgWaitForMultipleObjects
24 | // won't return again for items left in the queue after PeekMessage.
25 | while (::PeekMessage(&message, nullptr, 0, 0, PM_REMOVE)) {
26 | processed_events = true;
27 | if (message.message == WM_QUIT) {
28 | keep_running = false;
29 | break;
30 | }
31 | ::TranslateMessage(&message);
32 | ::DispatchMessage(&message);
33 | // Allow Flutter to process messages each time a Windows message is
34 | // processed, to prevent starvation.
35 | next_flutter_event_time =
36 | std::min(next_flutter_event_time, ProcessFlutterMessages());
37 | }
38 | // If the PeekMessage loop didn't run, process Flutter messages.
39 | if (!processed_events) {
40 | next_flutter_event_time =
41 | std::min(next_flutter_event_time, ProcessFlutterMessages());
42 | }
43 | }
44 | }
45 |
46 | void RunLoop::RegisterFlutterInstance(
47 | flutter::FlutterEngine* flutter_instance) {
48 | flutter_instances_.insert(flutter_instance);
49 | }
50 |
51 | void RunLoop::UnregisterFlutterInstance(
52 | flutter::FlutterEngine* flutter_instance) {
53 | flutter_instances_.erase(flutter_instance);
54 | }
55 |
56 | RunLoop::TimePoint RunLoop::ProcessFlutterMessages() {
57 | TimePoint next_event_time = TimePoint::max();
58 | for (auto instance : flutter_instances_) {
59 | std::chrono::nanoseconds wait_duration = instance->ProcessMessages();
60 | if (wait_duration != std::chrono::nanoseconds::max()) {
61 | next_event_time =
62 | std::min(next_event_time, TimePoint::clock::now() + wait_duration);
63 | }
64 | }
65 | return next_event_time;
66 | }
67 |
--------------------------------------------------------------------------------
/stocks/windows/runner/run_loop.h:
--------------------------------------------------------------------------------
1 | #ifndef RUNNER_RUN_LOOP_H_
2 | #define RUNNER_RUN_LOOP_H_
3 |
4 | #include
5 |
6 | #include
7 | #include
8 |
9 | // A runloop that will service events for Flutter instances as well
10 | // as native messages.
11 | class RunLoop {
12 | public:
13 | RunLoop();
14 | ~RunLoop();
15 |
16 | // Prevent copying
17 | RunLoop(RunLoop const&) = delete;
18 | RunLoop& operator=(RunLoop const&) = delete;
19 |
20 | // Runs the run loop until the application quits.
21 | void Run();
22 |
23 | // Registers the given Flutter instance for event servicing.
24 | void RegisterFlutterInstance(
25 | flutter::FlutterEngine* flutter_instance);
26 |
27 | // Unregisters the given Flutter instance from event servicing.
28 | void UnregisterFlutterInstance(
29 | flutter::FlutterEngine* flutter_instance);
30 |
31 | private:
32 | using TimePoint = std::chrono::steady_clock::time_point;
33 |
34 | // Processes all currently pending messages for registered Flutter instances.
35 | TimePoint ProcessFlutterMessages();
36 |
37 | std::set flutter_instances_;
38 | };
39 |
40 | #endif // RUNNER_RUN_LOOP_H_
41 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/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 | if (target_length == 0) {
52 | return std::string();
53 | }
54 | std::string utf8_string;
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 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------
/stocks/windows/runner/win32_window.cpp:
--------------------------------------------------------------------------------
1 | #include "win32_window.h"
2 |
3 | #include
4 |
5 | #include "resource.h"
6 |
7 | namespace {
8 |
9 | constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW";
10 |
11 | // The number of Win32Window objects that currently exist.
12 | static int g_active_window_count = 0;
13 |
14 | using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd);
15 |
16 | // Scale helper to convert logical scaler values to physical using passed in
17 | // scale factor
18 | int Scale(int source, double scale_factor) {
19 | return static_cast(source * scale_factor);
20 | }
21 |
22 | // Dynamically loads the |EnableNonClientDpiScaling| from the User32 module.
23 | // This API is only needed for PerMonitor V1 awareness mode.
24 | void EnableFullDpiSupportIfAvailable(HWND hwnd) {
25 | HMODULE user32_module = LoadLibraryA("User32.dll");
26 | if (!user32_module) {
27 | return;
28 | }
29 | auto enable_non_client_dpi_scaling =
30 | reinterpret_cast(
31 | GetProcAddress(user32_module, "EnableNonClientDpiScaling"));
32 | if (enable_non_client_dpi_scaling != nullptr) {
33 | enable_non_client_dpi_scaling(hwnd);
34 | FreeLibrary(user32_module);
35 | }
36 | }
37 |
38 | } // namespace
39 |
40 | // Manages the Win32Window's window class registration.
41 | class WindowClassRegistrar {
42 | public:
43 | ~WindowClassRegistrar() = default;
44 |
45 | // Returns the singleton registar instance.
46 | static WindowClassRegistrar* GetInstance() {
47 | if (!instance_) {
48 | instance_ = new WindowClassRegistrar();
49 | }
50 | return instance_;
51 | }
52 |
53 | // Returns the name of the window class, registering the class if it hasn't
54 | // previously been registered.
55 | const wchar_t* GetWindowClass();
56 |
57 | // Unregisters the window class. Should only be called if there are no
58 | // instances of the window.
59 | void UnregisterWindowClass();
60 |
61 | private:
62 | WindowClassRegistrar() = default;
63 |
64 | static WindowClassRegistrar* instance_;
65 |
66 | bool class_registered_ = false;
67 | };
68 |
69 | WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr;
70 |
71 | const wchar_t* WindowClassRegistrar::GetWindowClass() {
72 | if (!class_registered_) {
73 | WNDCLASS window_class{};
74 | window_class.hCursor = LoadCursor(nullptr, IDC_ARROW);
75 | window_class.lpszClassName = kWindowClassName;
76 | window_class.style = CS_HREDRAW | CS_VREDRAW;
77 | window_class.cbClsExtra = 0;
78 | window_class.cbWndExtra = 0;
79 | window_class.hInstance = GetModuleHandle(nullptr);
80 | window_class.hIcon =
81 | LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON));
82 | window_class.hbrBackground = 0;
83 | window_class.lpszMenuName = nullptr;
84 | window_class.lpfnWndProc = Win32Window::WndProc;
85 | RegisterClass(&window_class);
86 | class_registered_ = true;
87 | }
88 | return kWindowClassName;
89 | }
90 |
91 | void WindowClassRegistrar::UnregisterWindowClass() {
92 | UnregisterClass(kWindowClassName, nullptr);
93 | class_registered_ = false;
94 | }
95 |
96 | Win32Window::Win32Window() {
97 | ++g_active_window_count;
98 | }
99 |
100 | Win32Window::~Win32Window() {
101 | --g_active_window_count;
102 | Destroy();
103 | }
104 |
105 | bool Win32Window::CreateAndShow(const std::wstring& title,
106 | const Point& origin,
107 | const Size& size) {
108 | Destroy();
109 |
110 | const wchar_t* window_class =
111 | WindowClassRegistrar::GetInstance()->GetWindowClass();
112 |
113 | const POINT target_point = {static_cast(origin.x),
114 | static_cast(origin.y)};
115 | HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST);
116 | UINT dpi = FlutterDesktopGetDpiForMonitor(monitor);
117 | double scale_factor = dpi / 96.0;
118 |
119 | HWND window = CreateWindow(
120 | window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE,
121 | Scale(origin.x, scale_factor), Scale(origin.y, scale_factor),
122 | Scale(size.width, scale_factor), Scale(size.height, scale_factor),
123 | nullptr, nullptr, GetModuleHandle(nullptr), this);
124 |
125 | if (!window) {
126 | return false;
127 | }
128 |
129 | return OnCreate();
130 | }
131 |
132 | // static
133 | LRESULT CALLBACK Win32Window::WndProc(HWND const window,
134 | UINT const message,
135 | WPARAM const wparam,
136 | LPARAM const lparam) noexcept {
137 | if (message == WM_NCCREATE) {
138 | auto window_struct = reinterpret_cast(lparam);
139 | SetWindowLongPtr(window, GWLP_USERDATA,
140 | reinterpret_cast(window_struct->lpCreateParams));
141 |
142 | auto that = static_cast(window_struct->lpCreateParams);
143 | EnableFullDpiSupportIfAvailable(window);
144 | that->window_handle_ = window;
145 | } else if (Win32Window* that = GetThisFromHandle(window)) {
146 | return that->MessageHandler(window, message, wparam, lparam);
147 | }
148 |
149 | return DefWindowProc(window, message, wparam, lparam);
150 | }
151 |
152 | LRESULT
153 | Win32Window::MessageHandler(HWND hwnd,
154 | UINT const message,
155 | WPARAM const wparam,
156 | LPARAM const lparam) noexcept {
157 | switch (message) {
158 | case WM_DESTROY:
159 | window_handle_ = nullptr;
160 | Destroy();
161 | if (quit_on_close_) {
162 | PostQuitMessage(0);
163 | }
164 | return 0;
165 |
166 | case WM_DPICHANGED: {
167 | auto newRectSize = reinterpret_cast(lparam);
168 | LONG newWidth = newRectSize->right - newRectSize->left;
169 | LONG newHeight = newRectSize->bottom - newRectSize->top;
170 |
171 | SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth,
172 | newHeight, SWP_NOZORDER | SWP_NOACTIVATE);
173 |
174 | return 0;
175 | }
176 | case WM_SIZE: {
177 | RECT rect = GetClientArea();
178 | if (child_content_ != nullptr) {
179 | // Size and position the child window.
180 | MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left,
181 | rect.bottom - rect.top, TRUE);
182 | }
183 | return 0;
184 | }
185 |
186 | case WM_ACTIVATE:
187 | if (child_content_ != nullptr) {
188 | SetFocus(child_content_);
189 | }
190 | return 0;
191 | }
192 |
193 | return DefWindowProc(window_handle_, message, wparam, lparam);
194 | }
195 |
196 | void Win32Window::Destroy() {
197 | OnDestroy();
198 |
199 | if (window_handle_) {
200 | DestroyWindow(window_handle_);
201 | window_handle_ = nullptr;
202 | }
203 | if (g_active_window_count == 0) {
204 | WindowClassRegistrar::GetInstance()->UnregisterWindowClass();
205 | }
206 | }
207 |
208 | Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept {
209 | return reinterpret_cast(
210 | GetWindowLongPtr(window, GWLP_USERDATA));
211 | }
212 |
213 | void Win32Window::SetChildContent(HWND content) {
214 | child_content_ = content;
215 | SetParent(content, window_handle_);
216 | RECT frame = GetClientArea();
217 |
218 | MoveWindow(content, frame.left, frame.top, frame.right - frame.left,
219 | frame.bottom - frame.top, true);
220 |
221 | SetFocus(child_content_);
222 | }
223 |
224 | RECT Win32Window::GetClientArea() {
225 | RECT frame;
226 | GetClientRect(window_handle_, &frame);
227 | return frame;
228 | }
229 |
230 | HWND Win32Window::GetHandle() {
231 | return window_handle_;
232 | }
233 |
234 | void Win32Window::SetQuitOnClose(bool quit_on_close) {
235 | quit_on_close_ = quit_on_close;
236 | }
237 |
238 | bool Win32Window::OnCreate() {
239 | // No-op; provided for subclasses.
240 | return true;
241 | }
242 |
243 | void Win32Window::OnDestroy() {
244 | // No-op; provided for subclasses.
245 | }
246 |
--------------------------------------------------------------------------------
/stocks/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 |
--------------------------------------------------------------------------------