├── .gitignore ├── .metadata ├── README.md ├── analysis_options.yaml ├── android ├── .gitignore ├── app │ ├── build.gradle │ └── src │ │ ├── debug │ │ └── AndroidManifest.xml │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── kotlin │ │ │ └── com │ │ │ │ └── variantconst │ │ │ │ └── marchkov_helper │ │ │ │ └── MainActivity.kt │ │ └── res │ │ │ ├── drawable-v21 │ │ │ └── launch_background.xml │ │ │ ├── drawable │ │ │ └── launch_background.xml │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── values-night │ │ │ └── styles.xml │ │ │ └── values │ │ │ └── styles.xml │ │ └── profile │ │ └── AndroidManifest.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ └── gradle-wrapper.properties └── settings.gradle ├── assets ├── auto_mode.svg ├── dark_mode.svg ├── icon │ └── app_icon.png └── light_mode.svg ├── devtools_options.yaml ├── ios ├── .gitignore ├── Flutter │ ├── AppFrameworkInfo.plist │ ├── Debug.xcconfig │ └── Release.xcconfig ├── Podfile ├── Podfile.lock ├── 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 └── RunnerTests │ └── RunnerTests.swift ├── l10n.yaml ├── lib ├── l10n │ └── app_zh.arb ├── main.dart ├── models │ ├── address.dart │ ├── bus_route.dart │ ├── bus_schedule.dart │ ├── reservation.dart │ ├── ride_info.dart │ ├── time_slot.dart │ └── user.dart ├── providers │ ├── auth_provider.dart │ ├── brightness_provider.dart │ ├── reservation_provider.dart │ ├── ride_history_provider.dart │ ├── theme_provider.dart │ └── visualization_settings_provider.dart ├── repositories │ ├── auth_repository.dart │ └── reservation_repository.dart ├── screens │ ├── login │ │ ├── close_button.dart │ │ ├── login_page.dart │ │ ├── password_field.dart │ │ ├── terms_checkbox.dart │ │ └── username_field.dart │ ├── main │ │ └── main_page.dart │ ├── reservation │ │ ├── bus_button.dart │ │ ├── bus_list.dart │ │ ├── bus_route_card.dart │ │ ├── bus_section.dart │ │ ├── reservation_calendar.dart │ │ └── reservation_page.dart │ ├── ride │ │ ├── ride_button.dart │ │ ├── ride_card.dart │ │ ├── ride_card_header.dart │ │ └── ride_page.dart │ ├── settings │ │ ├── about_page.dart │ │ ├── help_page.dart │ │ ├── ride_settings_page.dart │ │ ├── settings_page.dart │ │ └── theme_settings_page.dart │ └── visualization │ │ ├── check_in_time_histogram.dart │ │ ├── checked_in_reserved_pie_chart.dart │ │ ├── departure_time_bar_chart.dart │ │ ├── ride_calendar_card.dart │ │ ├── ride_heatmap.dart │ │ ├── visualization_page.dart │ │ └── yearly_summary │ │ ├── annual_summary_card.dart │ │ ├── random_percentage_widget.dart │ │ ├── stripe_painter.dart │ │ ├── summary_monthly_bar_chart.dart │ │ ├── summary_text_builder.dart │ │ └── summary_violation_pie_chart.dart ├── services │ ├── auth_service.dart │ ├── dau_service.dart │ ├── reservation_service.dart │ ├── ride_history_service.dart │ ├── user_service.dart │ └── version_service.dart ├── utils │ └── date_formatter.dart └── widgets │ └── error_dialog.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 ├── login_script.py ├── macos ├── .gitignore ├── Flutter │ ├── Flutter-Debug.xcconfig │ ├── Flutter-Release.xcconfig │ └── GeneratedPluginRegistrant.swift ├── Podfile ├── Podfile.lock ├── 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 └── RunnerTests │ └── RunnerTests.swift ├── pubspec.lock ├── pubspec.yaml ├── test └── widget_test.dart ├── web ├── favicon.png ├── icons │ ├── Icon-192.png │ ├── Icon-512.png │ ├── Icon-maskable-192.png │ └── Icon-maskable-512.png ├── index.html └── manifest.json └── windows ├── .gitignore ├── CMakeLists.txt ├── flutter ├── CMakeLists.txt ├── generated_plugin_registrant.cc ├── generated_plugin_registrant.h └── generated_plugins.cmake └── runner ├── CMakeLists.txt ├── Runner.rc ├── flutter_window.cpp ├── flutter_window.h ├── main.cpp ├── resource.h ├── resources └── app_icon.ico ├── runner.exe.manifest ├── utils.cpp ├── utils.h ├── win32_window.cpp └── win32_window.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .build/ 9 | .buildlog/ 10 | .history 11 | .svn/ 12 | .swiftpm/ 13 | migrate_working_dir/ 14 | 15 | # IntelliJ related 16 | *.iml 17 | *.ipr 18 | *.iws 19 | .idea/ 20 | 21 | # The .vscode folder contains launch configuration and tasks you configure in 22 | # VS Code which you may wish to be included in version control, so this line 23 | # is commented out by default. 24 | #.vscode/ 25 | 26 | # Flutter/Dart/Pub related 27 | **/doc/api/ 28 | **/ios/Flutter/.last_build_id 29 | .dart_tool/ 30 | .flutter-plugins 31 | .flutter-plugins-dependencies 32 | .pub-cache/ 33 | .pub/ 34 | /build/ 35 | 36 | # Symbolication related 37 | app.*.symbols 38 | 39 | # Obfuscation related 40 | app.*.map.json 41 | 42 | # Android Studio will place build artifacts here 43 | /android/app/debug 44 | /android/app/profile 45 | /android/app/release 46 | 47 | ios/build/ -------------------------------------------------------------------------------- /.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: "2663184aa79047d0a33a14a3b607954f8fdd8730" 8 | channel: "stable" 9 | 10 | project_type: app 11 | 12 | # Tracks metadata for the flutter migrate command 13 | migration: 14 | platforms: 15 | - platform: root 16 | create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730 17 | base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730 18 | - platform: ios 19 | create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730 20 | base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730 21 | 22 | # User provided section 23 | 24 | # List of Local paths (relative to this file) that should be 25 | # ignored by the migrate tool. 26 | # 27 | # Files that are not part of the templates will be ignored by default. 28 | unmanaged_files: 29 | - 'lib/main.dart' 30 | - 'ios/Runner.xcodeproj/project.pbxproj' 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Marchkov Helper 2 | 3 | 你的私有班车预约服务,出示乘车码从未如此优雅。请从[官网](https://shuttle.variantconst.com)获取最新 iOS 和 Android 应用。 4 | 5 | > Web, Android 和 iOS 的独立版本已停止维护,从 v2.0.0 开始采用 Flutter 统一跨平台体验。你依然可以通过 legacy 分支查看旧版代码。 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 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:flutter_lints/flutter.yaml 2 | 3 | linter: 4 | rules: 5 | prefer_const_constructors: false 6 | prefer_final_fields: false 7 | use_key_in_widget_constructors: false 8 | prefer_const_literals_to_create_immutables: false 9 | prefer_const_constructors_in_immutables: false 10 | avoid_print: false 11 | -------------------------------------------------------------------------------- /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/to/reference-keystore 11 | key.properties 12 | **/*.keystore 13 | **/*.jks 14 | -------------------------------------------------------------------------------- /android/app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id "com.android.application" 3 | id "kotlin-android" 4 | // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. 5 | id "dev.flutter.flutter-gradle-plugin" 6 | } 7 | 8 | android { 9 | namespace = "com.variantconst.marchkov_helper" 10 | compileSdk = flutter.compileSdkVersion 11 | ndkVersion = flutter.ndkVersion 12 | 13 | compileOptions { 14 | sourceCompatibility = JavaVersion.VERSION_1_8 15 | targetCompatibility = JavaVersion.VERSION_1_8 16 | } 17 | 18 | kotlinOptions { 19 | jvmTarget = JavaVersion.VERSION_1_8 20 | } 21 | 22 | defaultConfig { 23 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 24 | applicationId = "com.variantconst.marchkov_helper" 25 | // You can update the following values to match your application needs. 26 | // For more information, see: https://flutter.dev/to/review-gradle-config. 27 | minSdk = flutter.minSdkVersion 28 | targetSdk = flutter.targetSdkVersion 29 | versionCode = flutter.versionCode 30 | versionName = flutter.versionName 31 | } 32 | 33 | buildTypes { 34 | release { 35 | // TODO: Add your own signing config for the release build. 36 | // Signing with the debug keys for now, so `flutter run --release` works. 37 | signingConfig = signingConfigs.debug 38 | } 39 | } 40 | } 41 | 42 | flutter { 43 | source = "../.." 44 | } 45 | -------------------------------------------------------------------------------- /android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 7 | 8 | 12 | 21 | 25 | 29 | 30 | 31 | 32 | 33 | 34 | 36 | 39 | 40 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /android/app/src/main/kotlin/com/variantconst/marchkov_helper/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.variantconst.marchkov_helper 2 | 3 | import io.flutter.embedding.android.FlutterActivity 4 | 5 | class MainActivity: FlutterActivity() 6 | -------------------------------------------------------------------------------- /android/app/src/main/res/drawable-v21/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/values-night/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | allprojects { 2 | repositories { 3 | google() 4 | mavenCentral() 5 | } 6 | } 7 | 8 | rootProject.buildDir = "../build" 9 | subprojects { 10 | project.buildDir = "${rootProject.buildDir}/${project.name}" 11 | } 12 | subprojects { 13 | project.evaluationDependsOn(":app") 14 | } 15 | 16 | tasks.register("clean", Delete) { 17 | delete rootProject.buildDir 18 | } 19 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=2G -XX:+HeapDumpOnOutOfMemoryError 2 | android.useAndroidX=true 3 | android.enableJetifier=true 4 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip 6 | -------------------------------------------------------------------------------- /android/settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | def flutterSdkPath = { 3 | def properties = new Properties() 4 | file("local.properties").withInputStream { properties.load(it) } 5 | def flutterSdkPath = properties.getProperty("flutter.sdk") 6 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties" 7 | return flutterSdkPath 8 | }() 9 | 10 | includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") 11 | 12 | repositories { 13 | google() 14 | mavenCentral() 15 | gradlePluginPortal() 16 | } 17 | } 18 | 19 | plugins { 20 | id "dev.flutter.flutter-plugin-loader" version "1.0.0" 21 | id "com.android.application" version "8.1.0" apply false 22 | id "org.jetbrains.kotlin.android" version "1.8.22" apply false 23 | } 24 | 25 | include ":app" 26 | -------------------------------------------------------------------------------- /assets/auto_mode.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /assets/dark_mode.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /assets/icon/app_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/assets/icon/app_icon.png -------------------------------------------------------------------------------- /assets/light_mode.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /devtools_options.yaml: -------------------------------------------------------------------------------- 1 | description: This file stores settings for Dart & Flutter DevTools. 2 | documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states 3 | extensions: 4 | -------------------------------------------------------------------------------- /ios/.gitignore: -------------------------------------------------------------------------------- 1 | **/dgph 2 | *.mode1v3 3 | *.mode2v3 4 | *.moved-aside 5 | *.pbxuser 6 | *.perspectivev3 7 | **/*sync/ 8 | .sconsign.dblite 9 | .tags* 10 | **/.vagrant/ 11 | **/DerivedData/ 12 | Icon? 13 | **/Pods/ 14 | **/.symlinks/ 15 | profile 16 | xcuserdata 17 | **/.generated/ 18 | Flutter/App.framework 19 | Flutter/Flutter.framework 20 | Flutter/Flutter.podspec 21 | Flutter/Generated.xcconfig 22 | Flutter/ephemeral/ 23 | Flutter/app.flx 24 | Flutter/app.zip 25 | Flutter/flutter_assets/ 26 | Flutter/flutter_export_environment.sh 27 | ServiceDefinitions.json 28 | Runner/GeneratedPluginRegistrant.* 29 | 30 | # Exceptions to above rules. 31 | !default.mode1v3 32 | !default.mode2v3 33 | !default.pbxuser 34 | !default.perspectivev3 35 | -------------------------------------------------------------------------------- /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 | 12.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /ios/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment this line to define a global platform for your project 2 | platform :ios, '12.0' 3 | 4 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency. 5 | ENV['COCOAPODS_DISABLE_STATS'] = 'true' 6 | 7 | project 'Runner', { 8 | 'Debug' => :debug, 9 | 'Profile' => :release, 10 | 'Release' => :release, 11 | } 12 | 13 | def flutter_root 14 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) 15 | unless File.exist?(generated_xcode_build_settings_path) 16 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" 17 | end 18 | 19 | File.foreach(generated_xcode_build_settings_path) do |line| 20 | matches = line.match(/FLUTTER_ROOT\=(.*)/) 21 | return matches[1].strip if matches 22 | end 23 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" 24 | end 25 | 26 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) 27 | 28 | flutter_ios_podfile_setup 29 | 30 | target 'Runner' do 31 | use_frameworks! 32 | use_modular_headers! 33 | 34 | flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) 35 | target 'RunnerTests' do 36 | inherit! :search_paths 37 | end 38 | end 39 | 40 | post_install do |installer| 41 | installer.pods_project.targets.each do |target| 42 | flutter_additional_ios_build_settings(target) 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /ios/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - emoji_picker_flutter (0.0.1): 3 | - Flutter 4 | - Flutter (1.0.0) 5 | - geolocator_apple (1.2.0): 6 | - Flutter 7 | - package_info_plus (0.4.5): 8 | - Flutter 9 | - path_provider_foundation (0.0.1): 10 | - Flutter 11 | - FlutterMacOS 12 | - permission_handler_apple (9.3.0): 13 | - Flutter 14 | - screen_brightness_ios (0.1.0): 15 | - Flutter 16 | - share_plus (0.0.1): 17 | - Flutter 18 | - shared_preferences_foundation (0.0.1): 19 | - Flutter 20 | - FlutterMacOS 21 | - url_launcher_ios (0.0.1): 22 | - Flutter 23 | 24 | DEPENDENCIES: 25 | - emoji_picker_flutter (from `.symlinks/plugins/emoji_picker_flutter/ios`) 26 | - Flutter (from `Flutter`) 27 | - geolocator_apple (from `.symlinks/plugins/geolocator_apple/ios`) 28 | - package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) 29 | - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) 30 | - permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`) 31 | - screen_brightness_ios (from `.symlinks/plugins/screen_brightness_ios/ios`) 32 | - share_plus (from `.symlinks/plugins/share_plus/ios`) 33 | - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) 34 | - url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`) 35 | 36 | EXTERNAL SOURCES: 37 | emoji_picker_flutter: 38 | :path: ".symlinks/plugins/emoji_picker_flutter/ios" 39 | Flutter: 40 | :path: Flutter 41 | geolocator_apple: 42 | :path: ".symlinks/plugins/geolocator_apple/ios" 43 | package_info_plus: 44 | :path: ".symlinks/plugins/package_info_plus/ios" 45 | path_provider_foundation: 46 | :path: ".symlinks/plugins/path_provider_foundation/darwin" 47 | permission_handler_apple: 48 | :path: ".symlinks/plugins/permission_handler_apple/ios" 49 | screen_brightness_ios: 50 | :path: ".symlinks/plugins/screen_brightness_ios/ios" 51 | share_plus: 52 | :path: ".symlinks/plugins/share_plus/ios" 53 | shared_preferences_foundation: 54 | :path: ".symlinks/plugins/shared_preferences_foundation/darwin" 55 | url_launcher_ios: 56 | :path: ".symlinks/plugins/url_launcher_ios/ios" 57 | 58 | SPEC CHECKSUMS: 59 | emoji_picker_flutter: fe2e6151c5b548e975d546e6eeb567daf0962a58 60 | Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 61 | geolocator_apple: 9bcea1918ff7f0062d98345d238ae12718acfbc1 62 | package_info_plus: c0502532a26c7662a62a356cebe2692ec5fe4ec4 63 | path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46 64 | permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2 65 | screen_brightness_ios: 715ca807df953bf676d339f11464e438143ee625 66 | share_plus: c3fef564749587fc939ef86ffb283ceac0baf9f5 67 | shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78 68 | url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe 69 | 70 | PODFILE CHECKSUM: 7be2f5f74864d463a8ad433546ed1de7e0f29aef 71 | 72 | COCOAPODS: 1.15.2 73 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 43 | 49 | 50 | 51 | 52 | 53 | 63 | 65 | 71 | 72 | 73 | 74 | 80 | 82 | 88 | 89 | 90 | 91 | 93 | 94 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ios/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import Flutter 2 | import UIKit 3 | 4 | @main 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 | -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Icon-App-20x20@2x.png", 5 | "idiom" : "iphone", 6 | "scale" : "2x", 7 | "size" : "20x20" 8 | }, 9 | { 10 | "filename" : "Icon-App-20x20@3x.png", 11 | "idiom" : "iphone", 12 | "scale" : "3x", 13 | "size" : "20x20" 14 | }, 15 | { 16 | "filename" : "Icon-App-29x29@1x.png", 17 | "idiom" : "iphone", 18 | "scale" : "1x", 19 | "size" : "29x29" 20 | }, 21 | { 22 | "filename" : "Icon-App-29x29@2x.png", 23 | "idiom" : "iphone", 24 | "scale" : "2x", 25 | "size" : "29x29" 26 | }, 27 | { 28 | "filename" : "Icon-App-29x29@3x.png", 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "29x29" 32 | }, 33 | { 34 | "filename" : "Icon-App-40x40@2x.png", 35 | "idiom" : "iphone", 36 | "scale" : "2x", 37 | "size" : "40x40" 38 | }, 39 | { 40 | "filename" : "Icon-App-40x40@3x.png", 41 | "idiom" : "iphone", 42 | "scale" : "3x", 43 | "size" : "40x40" 44 | }, 45 | { 46 | "filename" : "Icon-App-60x60@2x.png", 47 | "idiom" : "iphone", 48 | "scale" : "2x", 49 | "size" : "60x60" 50 | }, 51 | { 52 | "filename" : "Icon-App-60x60@3x.png", 53 | "idiom" : "iphone", 54 | "scale" : "3x", 55 | "size" : "60x60" 56 | }, 57 | { 58 | "filename" : "Icon-App-20x20@1x.png", 59 | "idiom" : "ipad", 60 | "scale" : "1x", 61 | "size" : "20x20" 62 | }, 63 | { 64 | "filename" : "Icon-App-20x20@2x.png", 65 | "idiom" : "ipad", 66 | "scale" : "2x", 67 | "size" : "20x20" 68 | }, 69 | { 70 | "filename" : "Icon-App-29x29@1x.png", 71 | "idiom" : "ipad", 72 | "scale" : "1x", 73 | "size" : "29x29" 74 | }, 75 | { 76 | "filename" : "Icon-App-29x29@2x.png", 77 | "idiom" : "ipad", 78 | "scale" : "2x", 79 | "size" : "29x29" 80 | }, 81 | { 82 | "filename" : "Icon-App-40x40@1x.png", 83 | "idiom" : "ipad", 84 | "scale" : "1x", 85 | "size" : "40x40" 86 | }, 87 | { 88 | "filename" : "Icon-App-40x40@2x.png", 89 | "idiom" : "ipad", 90 | "scale" : "2x", 91 | "size" : "40x40" 92 | }, 93 | { 94 | "filename" : "Icon-App-76x76@1x.png", 95 | "idiom" : "ipad", 96 | "scale" : "1x", 97 | "size" : "76x76" 98 | }, 99 | { 100 | "filename" : "Icon-App-76x76@2x.png", 101 | "idiom" : "ipad", 102 | "scale" : "2x", 103 | "size" : "76x76" 104 | }, 105 | { 106 | "filename" : "Icon-App-83.5x83.5@2x.png", 107 | "idiom" : "ipad", 108 | "scale" : "2x", 109 | "size" : "83.5x83.5" 110 | }, 111 | { 112 | "filename" : "Icon-App-1024x1024@1x.png", 113 | "idiom" : "ios-marketing", 114 | "scale" : "1x", 115 | "size" : "1024x1024" 116 | } 117 | ], 118 | "info" : { 119 | "author" : "xcode", 120 | "version" : 1 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /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. -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /ios/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CADisableMinimumFrameDurationOnPhone 6 | 7 | CFBundleDevelopmentRegion 8 | $(DEVELOPMENT_LANGUAGE) 9 | CFBundleDisplayName 10 | MCK Helper 11 | CFBundleExecutable 12 | $(EXECUTABLE_NAME) 13 | CFBundleIconName 14 | AppIcon 15 | CFBundleIdentifier 16 | $(PRODUCT_BUNDLE_IDENTIFIER) 17 | CFBundleInfoDictionaryVersion 18 | 6.0 19 | CFBundleName 20 | marchkov_ios 21 | CFBundlePackageType 22 | APPL 23 | CFBundleShortVersionString 24 | $(FLUTTER_BUILD_NAME) 25 | CFBundleSignature 26 | ???? 27 | CFBundleVersion 28 | $(FLUTTER_BUILD_NUMBER) 29 | LSRequiresIPhoneOS 30 | 31 | NSCameraUsageDescription 32 | 需要访问您的相机以拍摄图片。 33 | NSLocationAlwaysAndWhenInUseUsageDescription 34 | 我们需要访问您的位置信息以提供准确的班车服务。 35 | NSLocationWhenInUseUsageDescription 36 | 我们需要访问您的位置信息以提供准确的班车服务。 37 | NSPhotoLibraryUsageDescription 38 | 需要访问您的相册以选择图片。 39 | UIApplicationSupportsIndirectInputEvents 40 | 41 | UILaunchStoryboardName 42 | LaunchScreen 43 | UIMainStoryboardFile 44 | Main 45 | UISupportedInterfaceOrientations 46 | 47 | UIInterfaceOrientationPortrait 48 | 49 | UISupportedInterfaceOrientations~ipad 50 | 51 | UIInterfaceOrientationLandscapeLeft 52 | UIInterfaceOrientationLandscapeRight 53 | UIInterfaceOrientationPortrait 54 | UIInterfaceOrientationPortraitUpsideDown 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /ios/RunnerTests/RunnerTests.swift: -------------------------------------------------------------------------------- 1 | import Flutter 2 | import UIKit 3 | import XCTest 4 | 5 | class RunnerTests: XCTestCase { 6 | 7 | func testExample() { 8 | // If you add code to the Runner application, consider adding tests here. 9 | // See https://developer.apple.com/documentation/xctest for more information about using XCTest. 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /l10n.yaml: -------------------------------------------------------------------------------- 1 | arb-dir: lib/l10n 2 | template-arb-file: app_zh.arb 3 | output-localization-file: app_localizations.dart 4 | -------------------------------------------------------------------------------- /lib/l10n/app_zh.arb: -------------------------------------------------------------------------------- 1 | { 2 | "appTitle": "校园出行", 3 | "@appTitle": { 4 | "description": "The title of the application" 5 | } 6 | } -------------------------------------------------------------------------------- /lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:provider/provider.dart'; 3 | import 'providers/auth_provider.dart'; 4 | import 'providers/reservation_provider.dart'; 5 | import 'providers/theme_provider.dart'; // 新增 6 | import 'providers/ride_history_provider.dart'; // 新增 7 | import 'providers/brightness_provider.dart'; 8 | import 'providers/visualization_settings_provider.dart'; 9 | import 'screens/login/login_page.dart'; 10 | import 'screens/main/main_page.dart'; 11 | import 'package:flutter/services.dart'; 12 | 13 | void main() { 14 | runApp( 15 | MultiProvider( 16 | providers: [ 17 | ChangeNotifierProvider(create: (_) => AuthProvider()), 18 | ChangeNotifierProvider(create: (_) => ThemeProvider()), 19 | ChangeNotifierProvider( 20 | create: (_) => BrightnessProvider()..initialize()), 21 | ChangeNotifierProxyProvider( 22 | create: (context) => ReservationProvider( 23 | Provider.of(context, listen: false), 24 | ), 25 | update: (context, auth, previous) => ReservationProvider(auth), 26 | ), 27 | ChangeNotifierProxyProvider( 28 | create: (context) => RideHistoryProvider( 29 | Provider.of(context, listen: false), 30 | ), 31 | update: (context, auth, previous) => RideHistoryProvider(auth), 32 | ), 33 | ChangeNotifierProvider( 34 | create: (_) => VisualizationSettingsProvider(), 35 | ), 36 | ], 37 | child: MyApp(), 38 | ), 39 | ); 40 | 41 | // 添加全局错误处理 42 | FlutterError.onError = (FlutterErrorDetails details) { 43 | FlutterError.presentError(details); 44 | debugPrint(details.toString()); 45 | }; 46 | } 47 | 48 | class MyApp extends StatelessWidget { 49 | @override 50 | Widget build(BuildContext context) { 51 | return Consumer( 52 | builder: (context, themeProvider, child) { 53 | final isDarkMode = themeProvider.themeMode == ThemeMode.dark; 54 | 55 | // 创建主题 56 | final lightTheme = ThemeData( 57 | colorScheme: ColorScheme.fromSeed( 58 | seedColor: themeProvider.selectedColor, 59 | brightness: Brightness.light, 60 | ), 61 | brightness: Brightness.light, 62 | useMaterial3: true, 63 | ); 64 | 65 | final darkTheme = ThemeData( 66 | colorScheme: ColorScheme.fromSeed( 67 | seedColor: themeProvider.selectedColor, 68 | brightness: Brightness.dark, 69 | ), 70 | brightness: Brightness.dark, 71 | useMaterial3: true, 72 | ); 73 | 74 | // 获取当前主题 75 | final currentTheme = isDarkMode ? darkTheme : lightTheme; 76 | 77 | // 使用当前主题的 scaffoldBackgroundColor 来设置系统导航栏颜色 78 | SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle( 79 | systemNavigationBarColor: currentTheme.scaffoldBackgroundColor, 80 | systemNavigationBarIconBrightness: 81 | isDarkMode ? Brightness.light : Brightness.dark, 82 | statusBarColor: Colors.transparent, 83 | statusBarIconBrightness: 84 | isDarkMode ? Brightness.light : Brightness.dark, 85 | )); 86 | 87 | return MaterialApp( 88 | title: 'Marchkov Helper', 89 | debugShowCheckedModeBanner: false, 90 | theme: lightTheme, 91 | darkTheme: darkTheme, 92 | themeMode: themeProvider.themeMode, 93 | home: AuthWrapper(), 94 | builder: (context, child) { 95 | return LifecycleWrapper(child: child!); 96 | }, 97 | ); 98 | }, 99 | ); 100 | } 101 | } 102 | 103 | class LifecycleWrapper extends StatefulWidget { 104 | final Widget child; 105 | 106 | const LifecycleWrapper({super.key, required this.child}); 107 | 108 | @override 109 | LifecycleWrapperState createState() => LifecycleWrapperState(); 110 | } 111 | 112 | class LifecycleWrapperState extends State 113 | with WidgetsBindingObserver { 114 | @override 115 | void initState() { 116 | super.initState(); 117 | WidgetsBinding.instance.addObserver(this); 118 | } 119 | 120 | @override 121 | void dispose() { 122 | WidgetsBinding.instance.removeObserver(this); 123 | super.dispose(); 124 | } 125 | 126 | @override 127 | void didChangeAppLifecycleState(AppLifecycleState state) { 128 | final brightnessProvider = 129 | Provider.of(context, listen: false); 130 | 131 | switch (state) { 132 | case AppLifecycleState.resumed: 133 | // 从后台恢复时,同步系统亮度 134 | brightnessProvider.syncWithSystemBrightness(); 135 | break; 136 | case AppLifecycleState.paused: 137 | case AppLifecycleState.detached: 138 | // 进入后台或关闭时,清理亮度设置 139 | brightnessProvider.cleanup(); 140 | break; 141 | default: 142 | break; 143 | } 144 | } 145 | 146 | @override 147 | Widget build(BuildContext context) => widget.child; 148 | } 149 | 150 | class AuthWrapper extends StatelessWidget { 151 | @override 152 | Widget build(BuildContext context) { 153 | final authProvider = Provider.of(context, listen: false); 154 | return FutureBuilder( 155 | future: authProvider.checkLoginState(), 156 | builder: (context, snapshot) { 157 | if (snapshot.connectionState == ConnectionState.waiting) { 158 | return Scaffold(body: Center(child: CircularProgressIndicator())); 159 | } 160 | final isLoggedIn = snapshot.data ?? false; 161 | return isLoggedIn ? MainPage() : LoginPage(); 162 | }, 163 | ); 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /lib/models/address.dart: -------------------------------------------------------------------------------- 1 | class Address { 2 | final String campusName; 3 | final String buildName; 4 | final String detailedAddress; 5 | 6 | Address({ 7 | required this.campusName, 8 | required this.buildName, 9 | required this.detailedAddress, 10 | }); 11 | 12 | factory Address.fromJson(Map json) { 13 | return Address( 14 | campusName: json['campus_name'] ?? '', 15 | buildName: json['build_name'] ?? '', 16 | detailedAddress: json['detailed_address'] ?? '', 17 | ); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/models/bus_route.dart: -------------------------------------------------------------------------------- 1 | class BusRoute { 2 | final int id; 3 | final String name; 4 | // 添加其他必要的字段 5 | 6 | BusRoute({ 7 | required this.id, 8 | required this.name, 9 | // 初始化其他字段 10 | }); 11 | } 12 | -------------------------------------------------------------------------------- /lib/models/bus_schedule.dart: -------------------------------------------------------------------------------- 1 | import 'bus_route.dart'; 2 | 3 | class BusSchedule { 4 | final BusRoute busRoute; 5 | final String date; 6 | final String time; 7 | final int margin; 8 | final int total; 9 | 10 | BusSchedule({ 11 | required this.busRoute, 12 | required this.date, 13 | required this.time, 14 | required this.margin, 15 | required this.total, 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /lib/models/reservation.dart: -------------------------------------------------------------------------------- 1 | class Reservation { 2 | final int id; 3 | final int hallAppointmentDataId; 4 | final String appointmentTime; 5 | final String resourceName; 6 | 7 | Reservation({ 8 | required this.id, 9 | required this.hallAppointmentDataId, 10 | required this.appointmentTime, 11 | required this.resourceName, 12 | }); 13 | 14 | factory Reservation.fromJson(Map json) { 15 | return Reservation( 16 | id: json['id'], 17 | hallAppointmentDataId: json['hall_appointment_data_id'], 18 | appointmentTime: json['appointment_tim'].trim(), 19 | resourceName: json['resource_name'], 20 | ); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lib/models/ride_info.dart: -------------------------------------------------------------------------------- 1 | class RideInfo { 2 | final int id; 3 | final String statusName; 4 | final String resourceName; 5 | final String appointmentTime; 6 | final String? appointmentSignTime; 7 | 8 | RideInfo({ 9 | required this.id, 10 | required this.statusName, 11 | required this.resourceName, 12 | required this.appointmentTime, 13 | this.appointmentSignTime, 14 | }); 15 | 16 | factory RideInfo.fromJson(Map json) { 17 | return RideInfo( 18 | id: json['id'] as int, 19 | statusName: json['status_name'] as String, 20 | resourceName: json['resource_name'] as String, 21 | appointmentTime: (json['appointment_tim'] as String).trim(), 22 | appointmentSignTime: json['appointment_sign_time'] != null 23 | ? (json['appointment_sign_time'] as String).trim() 24 | : null, 25 | ); 26 | } 27 | 28 | Map toJson() { 29 | return { 30 | 'id': id, 31 | 'status_name': statusName, 32 | 'resource_name': resourceName, 33 | 'appointment_tim': appointmentTime, 34 | 'appointment_sign_time': appointmentSignTime, 35 | }; 36 | } 37 | } 38 | 39 | class CachedRideHistory { 40 | final DateTime lastFetchDate; 41 | final List rides; 42 | 43 | CachedRideHistory({required this.lastFetchDate, required this.rides}); 44 | 45 | factory CachedRideHistory.fromJson(Map json) { 46 | return CachedRideHistory( 47 | lastFetchDate: DateTime.parse(json['lastFetchDate']), 48 | rides: (json['rides'] as List) 49 | .map((rideJson) => RideInfo.fromJson(rideJson)) 50 | .toList(), 51 | ); 52 | } 53 | 54 | Map toJson() { 55 | return { 56 | 'lastFetchDate': lastFetchDate.toIso8601String(), 57 | 'rides': rides.map((ride) => ride.toJson()).toList(), 58 | }; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /lib/models/time_slot.dart: -------------------------------------------------------------------------------- 1 | class TimeSlot { 2 | final int timeId; 3 | final int subId; 4 | final String abscissa; 5 | final String yaxis; 6 | final RowData row; 7 | final int isSub; 8 | final int lockModel; 9 | final String localTime; 10 | final String date; 11 | 12 | TimeSlot({ 13 | required this.timeId, 14 | required this.subId, 15 | required this.abscissa, 16 | required this.yaxis, 17 | required this.row, 18 | required this.isSub, 19 | required this.lockModel, 20 | required this.localTime, 21 | required this.date, 22 | }); 23 | 24 | factory TimeSlot.fromJson(Map json) { 25 | return TimeSlot( 26 | timeId: json['time_id'], 27 | subId: json['sub_id'], 28 | abscissa: json['abscissa'] ?? '', 29 | yaxis: json['yaxis'] ?? '', 30 | row: RowData.fromJson(json['row']), 31 | isSub: json['is_sub'], 32 | lockModel: json['lock_model'], 33 | localTime: json['local_time'] ?? '', 34 | date: json['date'] ?? '', 35 | ); 36 | } 37 | } 38 | 39 | class RowData { 40 | final int status; 41 | final int total; 42 | final int margin; 43 | final List info; 44 | final int price; 45 | final int isSub; 46 | final int closeTime; 47 | final List data; 48 | 49 | RowData({ 50 | required this.status, 51 | required this.total, 52 | required this.margin, 53 | required this.info, 54 | required this.price, 55 | required this.isSub, 56 | required this.closeTime, 57 | required this.data, 58 | }); 59 | 60 | factory RowData.fromJson(Map json) { 61 | return RowData( 62 | status: json['status'], 63 | total: json['total'], 64 | margin: json['margin'], 65 | info: json['info'] ?? [], 66 | price: json['price'], 67 | isSub: json['is_sub'], 68 | closeTime: json['close_time'], 69 | data: json['data'] ?? [], 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /lib/models/user.dart: -------------------------------------------------------------------------------- 1 | class User { 2 | final String username; 3 | final String token; 4 | 5 | User({required this.username, required this.token}); 6 | } 7 | -------------------------------------------------------------------------------- /lib/providers/auth_provider.dart: -------------------------------------------------------------------------------- 1 | // lib/providers/auth_provider.dart 2 | import 'package:flutter/material.dart'; 3 | import '../repositories/auth_repository.dart'; 4 | import '../models/user.dart'; 5 | import 'package:shared_preferences/shared_preferences.dart'; 6 | 7 | class AuthProvider with ChangeNotifier { 8 | final AuthRepository _authRepository = AuthRepository(); 9 | User? _user; 10 | String _loginResponse = ''; 11 | String _cookies = ''; // 保留这个属性,但我们会异步更新它 12 | 13 | // 添加新的属性来跟踪上次刷新时间 14 | static const String _lastRefreshKey = 'lastCookieRefreshDate'; 15 | 16 | bool get isLoggedIn => _user != null; 17 | String get username => _user?.username ?? ''; 18 | String get loginResponse => _loginResponse; 19 | String get cookies => _cookies; // 同步获取cookies 20 | String get password => _authRepository.password; 21 | 22 | Future login(String username, String password) async { 23 | await _authRepository.login(username, password); 24 | _user = User(username: username, token: ''); 25 | _loginResponse = _authRepository.loginResponse; 26 | _cookies = await _authRepository.cookies; // 异步获取cookies并更新 27 | // 确保打印完整的 cookie 字符串 28 | print('Full cookies: $_cookies'); 29 | await _saveLoginState(true); 30 | await _saveUsername(username); 31 | await _savePassword(password); 32 | notifyListeners(); 33 | } 34 | 35 | Future logout() async { 36 | await _authRepository.logout(); 37 | _user = null; 38 | _loginResponse = ''; 39 | _cookies = ''; 40 | await _saveLoginState(false); 41 | notifyListeners(); 42 | } 43 | 44 | Future loadUsername() async { 45 | await _authRepository.loadUsername(); 46 | final username = _authRepository.username; 47 | if (username.isNotEmpty) { 48 | _user = User(username: username, token: ''); 49 | notifyListeners(); 50 | } 51 | } 52 | 53 | Future checkLoginState() async { 54 | final prefs = await SharedPreferences.getInstance(); 55 | final isLoggedIn = prefs.getBool('isLoggedIn') ?? false; 56 | if (isLoggedIn) { 57 | await loadUsername(); 58 | _cookies = await _authRepository.cookies; // 异步获取cookies并更新 59 | } 60 | return isLoggedIn; 61 | } 62 | 63 | Future _saveLoginState(bool isLoggedIn) async { 64 | final prefs = await SharedPreferences.getInstance(); 65 | await prefs.setBool('isLoggedIn', isLoggedIn); 66 | } 67 | 68 | Future _saveUsername(String username) async { 69 | final prefs = await SharedPreferences.getInstance(); 70 | await prefs.setString('username', username); 71 | } 72 | 73 | Future _savePassword(String password) async { 74 | final prefs = await SharedPreferences.getInstance(); 75 | await prefs.setString('password', password); 76 | } 77 | 78 | // 添加一个方法来异步获取最新的cookies 79 | Future getLatestCookies() async { 80 | _cookies = await _authRepository.cookies; 81 | return _cookies; 82 | } 83 | 84 | // 新增:检查是否需要刷新 cookie 85 | Future _shouldRefreshCookie() async { 86 | final prefs = await SharedPreferences.getInstance(); 87 | final lastRefreshStr = prefs.getString(_lastRefreshKey); 88 | 89 | if (lastRefreshStr == null) return true; 90 | 91 | final lastRefresh = DateTime.parse(lastRefreshStr); 92 | final today = DateTime.now(); 93 | 94 | // 如果不是同一天,则需要刷新 95 | return lastRefresh.year != today.year || 96 | lastRefresh.month != today.month || 97 | lastRefresh.day != today.day; 98 | } 99 | 100 | // 新增:记录刷新时间 101 | Future _updateLastRefreshTime() async { 102 | final prefs = await SharedPreferences.getInstance(); 103 | await prefs.setString(_lastRefreshKey, DateTime.now().toIso8601String()); 104 | } 105 | 106 | // 新增:静默刷新 cookie 107 | Future silentlyRefreshCookie() async { 108 | try { 109 | // 检查是否需要刷新 110 | if (!await _shouldRefreshCookie()) { 111 | return true; 112 | } 113 | 114 | // 获取保存的凭据 115 | final prefs = await SharedPreferences.getInstance(); 116 | final savedUsername = prefs.getString('username'); 117 | final savedPassword = prefs.getString('password'); 118 | 119 | if (savedUsername == null || savedPassword == null) { 120 | return false; 121 | } 122 | 123 | // 尝试重新登录 124 | await login(savedUsername, savedPassword); 125 | await _updateLastRefreshTime(); 126 | return true; 127 | } catch (e) { 128 | print('静默刷新 cookie 失败: $e'); 129 | return false; 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /lib/providers/brightness_provider.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:shared_preferences/shared_preferences.dart'; 3 | import 'package:screen_brightness/screen_brightness.dart'; 4 | 5 | class BrightnessProvider with ChangeNotifier { 6 | bool _isFlashlightOn = false; 7 | double _originalBrightness = 0.0; 8 | final _screenBrightness = ScreenBrightness(); 9 | bool _isAutoMode = false; 10 | 11 | bool get isFlashlightOn => _isFlashlightOn; 12 | bool get isAutoMode => _isAutoMode; 13 | 14 | Future initialize() async { 15 | final prefs = await SharedPreferences.getInstance(); 16 | _isFlashlightOn = prefs.getBool('isFlashlightOn') ?? false; 17 | 18 | try { 19 | await syncWithSystemBrightness(); 20 | } catch (e) { 21 | debugPrint('Error initializing brightness: $e'); 22 | } 23 | } 24 | 25 | Future syncWithSystemBrightness() async { 26 | try { 27 | // 获取系统当前亮度 28 | _originalBrightness = await _screenBrightness.current; 29 | 30 | // 如果当前没有特殊模式启用,就使用系统亮度 31 | if (!_isFlashlightOn && !_isAutoMode) { 32 | await _screenBrightness.setScreenBrightness(_originalBrightness); 33 | } 34 | } catch (e) { 35 | debugPrint('Error syncing brightness: $e'); 36 | } 37 | } 38 | 39 | Future enableAutoMode() async { 40 | if (_isAutoMode) return; 41 | 42 | try { 43 | final prefs = await SharedPreferences.getInstance(); 44 | // 保存当前亮度 45 | _originalBrightness = await _screenBrightness.current; 46 | 47 | // 获取设置的亮度值 48 | final dayBrightness = prefs.getDouble('dayBrightness') ?? 75.0; 49 | final nightBrightness = prefs.getDouble('nightBrightness') ?? 50.0; 50 | 51 | // 判断当前是白天还是夜晚 52 | final hour = DateTime.now().hour; 53 | final isDaytime = hour >= 6 && hour < 18; 54 | 55 | // 设置对应的亮度 56 | final targetBrightness = 57 | (isDaytime ? dayBrightness : nightBrightness) / 100; 58 | await _screenBrightness.setScreenBrightness(targetBrightness); 59 | 60 | _isAutoMode = true; 61 | notifyListeners(); 62 | } catch (e) { 63 | debugPrint('Error enabling auto mode: $e'); 64 | } 65 | } 66 | 67 | Future disableAutoMode() async { 68 | if (!_isAutoMode) return; 69 | 70 | try { 71 | await _screenBrightness.setScreenBrightness(_originalBrightness); 72 | _isAutoMode = false; 73 | notifyListeners(); 74 | } catch (e) { 75 | debugPrint('Error disabling auto mode: $e'); 76 | } 77 | } 78 | 79 | Future toggleFlashlight({bool? force}) async { 80 | final prefs = await SharedPreferences.getInstance(); 81 | final newState = force ?? !_isFlashlightOn; 82 | 83 | if (newState == _isFlashlightOn) return; 84 | 85 | try { 86 | if (newState) { 87 | // 保存当前亮度 88 | _originalBrightness = await _screenBrightness.current; 89 | 90 | // 获取设置的亮度值 91 | final dayBrightness = prefs.getDouble('dayBrightness') ?? 75.0; 92 | final nightBrightness = prefs.getDouble('nightBrightness') ?? 50.0; 93 | 94 | // 判断当前是白天还是夜晚 95 | final hour = DateTime.now().hour; 96 | final isDaytime = hour >= 6 && hour < 18; 97 | 98 | // 设置对应的亮度 99 | final targetBrightness = 100 | (isDaytime ? dayBrightness : nightBrightness) / 100; 101 | await _screenBrightness.setScreenBrightness(targetBrightness); 102 | } else { 103 | // 恢复原始亮度 104 | await _screenBrightness.setScreenBrightness(_originalBrightness); 105 | } 106 | 107 | _isFlashlightOn = newState; 108 | await prefs.setBool('isFlashlightOn', newState); 109 | notifyListeners(); 110 | } catch (e) { 111 | debugPrint('Error toggling brightness: $e'); 112 | } 113 | } 114 | 115 | // 在应用退出或暂停时调用 116 | Future cleanup() async { 117 | if (_isFlashlightOn) { 118 | await toggleFlashlight(force: false); 119 | } else if (_isAutoMode) { 120 | await disableAutoMode(); 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /lib/providers/reservation_provider.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/foundation.dart'; 2 | import '../models/bus_route.dart'; 3 | import '../repositories/reservation_repository.dart'; 4 | import '../providers/auth_provider.dart'; 5 | import '../utils/date_formatter.dart'; 6 | import '../models/reservation.dart'; 7 | 8 | class ReservationProvider with ChangeNotifier { 9 | final ReservationRepository _reservationRepository; 10 | // ignore: unused_field 11 | final AuthProvider _authProvider; 12 | List _busRoutes = []; 13 | bool _isLoading = false; 14 | String? _error; 15 | bool _isLoadingReservations = false; 16 | bool _isLoadingQRCode = false; 17 | 18 | List _currentReservations = []; 19 | String? _qrCode; // 保存二维码 20 | 21 | ReservationProvider(this._authProvider) 22 | : _reservationRepository = ReservationRepository(_authProvider); 23 | 24 | List get busRoutes => _busRoutes; 25 | bool get isLoading => _isLoading; 26 | String? get error => _error; 27 | bool get isLoadingReservations => _isLoadingReservations; 28 | bool get isLoadingQRCode => _isLoadingQRCode; 29 | 30 | List get currentReservations => _currentReservations; 31 | String? get qrCode => _qrCode; 32 | 33 | Future loadBusRoutes() async { 34 | _isLoading = true; 35 | _error = null; 36 | notifyListeners(); 37 | 38 | try { 39 | final now = DateTime.now(); 40 | final futures = List.generate(7, (index) { 41 | final date = now.add(Duration(days: index)); 42 | return _reservationRepository.getBusRoutes( 43 | 1, DateFormatter.format(date)); 44 | }); 45 | 46 | final results = await Future.wait(futures); 47 | _busRoutes = results.expand((element) => element).toList(); 48 | _isLoading = false; 49 | notifyListeners(); 50 | } catch (e) { 51 | _error = e.toString(); 52 | _isLoading = false; 53 | notifyListeners(); 54 | } 55 | } 56 | 57 | // 获取当前预约列表 58 | Future loadCurrentReservations() async { 59 | _isLoadingReservations = true; 60 | _error = null; 61 | notifyListeners(); 62 | 63 | try { 64 | final reservations = await _reservationRepository.fetchMyReservations(); 65 | _currentReservations = 66 | reservations.map((r) => Reservation.fromJson(r)).toList(); 67 | _isLoadingReservations = false; 68 | notifyListeners(); 69 | } catch (e) { 70 | _error = e.toString(); 71 | _isLoadingReservations = false; 72 | notifyListeners(); 73 | } 74 | } 75 | 76 | // 获取二维码 77 | Future fetchQRCode(String id, String hallAppointmentDataId) async { 78 | _isLoadingQRCode = true; 79 | _error = null; 80 | notifyListeners(); 81 | 82 | try { 83 | _qrCode = await _reservationRepository.getReservationQRCode( 84 | id, hallAppointmentDataId); 85 | _isLoadingQRCode = false; 86 | notifyListeners(); 87 | } catch (e) { 88 | print('获取二维码时出错: $e'); 89 | _error = e.toString(); 90 | _isLoadingQRCode = false; 91 | notifyListeners(); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /lib/providers/ride_history_provider.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import '../models/ride_info.dart'; 3 | import '../services/ride_history_service.dart'; 4 | import '../providers/auth_provider.dart'; 5 | 6 | class RideHistoryProvider with ChangeNotifier { 7 | final RideHistoryService _rideHistoryService; 8 | 9 | List _rides = []; 10 | bool _isLoading = false; 11 | String? _error; 12 | bool _isInitialized = false; 13 | 14 | RideHistoryProvider(AuthProvider authProvider) 15 | : _rideHistoryService = RideHistoryService(authProvider); 16 | 17 | List get rides => _rides; 18 | bool get isLoading => _isLoading; 19 | String? get error => _error; 20 | bool get isInitialized => _isInitialized; 21 | 22 | Future loadRideHistory() async { 23 | if (_isLoading) return; 24 | 25 | _isLoading = true; 26 | _error = null; 27 | notifyListeners(); 28 | 29 | try { 30 | _rides = await _rideHistoryService.getRideHistory(); 31 | _isInitialized = true; 32 | } catch (e) { 33 | _error = e.toString(); 34 | } finally { 35 | _isLoading = false; 36 | notifyListeners(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /lib/providers/theme_provider.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter/services.dart'; 3 | import 'package:shared_preferences/shared_preferences.dart'; 4 | 5 | class ThemeProvider with ChangeNotifier { 6 | ThemeMode _themeMode = ThemeMode.light; 7 | Color _selectedColor = Colors.blue; 8 | 9 | ThemeMode get themeMode => _themeMode; 10 | Color get selectedColor => _selectedColor; 11 | 12 | ThemeProvider() { 13 | _loadThemeMode(); 14 | _loadSelectedColor(); 15 | } 16 | 17 | void _updateSystemUIOverlay(BuildContext context) { 18 | final isDark = _themeMode == ThemeMode.dark || 19 | (_themeMode == ThemeMode.system && 20 | MediaQuery.platformBrightnessOf(context) == Brightness.dark); 21 | 22 | final theme = ThemeData( 23 | colorScheme: ColorScheme.fromSeed( 24 | seedColor: _selectedColor, 25 | brightness: isDark ? Brightness.dark : Brightness.light, 26 | ), 27 | brightness: isDark ? Brightness.dark : Brightness.light, 28 | useMaterial3: true, 29 | ); 30 | 31 | SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle( 32 | systemNavigationBarColor: theme.scaffoldBackgroundColor, 33 | systemNavigationBarIconBrightness: 34 | isDark ? Brightness.light : Brightness.dark, 35 | statusBarColor: Colors.transparent, 36 | statusBarIconBrightness: isDark ? Brightness.light : Brightness.dark, 37 | )); 38 | } 39 | 40 | void _loadThemeMode() async { 41 | SharedPreferences prefs = await SharedPreferences.getInstance(); 42 | String? themeModeString = prefs.getString('themeMode'); 43 | if (themeModeString != null) { 44 | _themeMode = 45 | ThemeMode.values.firstWhere((e) => e.toString() == themeModeString); 46 | notifyListeners(); 47 | } 48 | } 49 | 50 | Future _loadSelectedColor() async { 51 | final prefs = await SharedPreferences.getInstance(); 52 | final colorValue = prefs.getInt('selectedColor'); 53 | if (colorValue == null) { 54 | _selectedColor = Colors.blue; 55 | } else { 56 | _selectedColor = Color(colorValue); 57 | } 58 | notifyListeners(); 59 | } 60 | 61 | Future setThemeMode(ThemeMode mode, [BuildContext? context]) async { 62 | _themeMode = mode; 63 | notifyListeners(); 64 | 65 | // 先保存设置 66 | final prefs = await SharedPreferences.getInstance(); 67 | await prefs.setString('themeMode', mode.toString()); 68 | 69 | // 如果提供了 context 并且它仍然有效,则更新系统UI 70 | if (context != null) { 71 | WidgetsBinding.instance.addPostFrameCallback((_) { 72 | _updateSystemUIOverlay(context); 73 | }); 74 | } 75 | } 76 | 77 | Future setSelectedColor(Color color, [BuildContext? context]) async { 78 | _selectedColor = color; 79 | notifyListeners(); 80 | 81 | // 保存颜色的完整 value 82 | final prefs = await SharedPreferences.getInstance(); 83 | // ignore: deprecated_member_use 84 | await prefs.setInt('selectedColor', color.value); 85 | 86 | // 如果提供了 context 并且它仍然有效,则更新系统UI 87 | if (context != null) { 88 | WidgetsBinding.instance.addPostFrameCallback((_) { 89 | _updateSystemUIOverlay(context); 90 | }); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /lib/providers/visualization_settings_provider.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:shared_preferences/shared_preferences.dart'; 3 | 4 | enum TimeRange { threeMonths, sixMonths, oneYear, all } 5 | 6 | class VisualizationSettingsProvider with ChangeNotifier { 7 | TimeRange _selectedTimeRange = TimeRange.all; 8 | static const String _timeRangeKey = 'selected_time_range'; 9 | 10 | TimeRange get selectedTimeRange => _selectedTimeRange; 11 | 12 | VisualizationSettingsProvider() { 13 | _loadSettings(); 14 | } 15 | 16 | Future _loadSettings() async { 17 | final prefs = await SharedPreferences.getInstance(); 18 | final savedRange = prefs.getString(_timeRangeKey); 19 | if (savedRange != null) { 20 | _selectedTimeRange = TimeRange.values.firstWhere( 21 | (e) => e.toString() == savedRange, 22 | orElse: () => TimeRange.all, 23 | ); 24 | notifyListeners(); 25 | } 26 | } 27 | 28 | Future setTimeRange(TimeRange range) async { 29 | if (_selectedTimeRange != range) { 30 | _selectedTimeRange = range; 31 | final prefs = await SharedPreferences.getInstance(); 32 | await prefs.setString(_timeRangeKey, range.toString()); 33 | notifyListeners(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lib/repositories/auth_repository.dart: -------------------------------------------------------------------------------- 1 | // lib/repositories/auth_repository.dart 2 | import '../services/auth_service.dart'; 3 | 4 | class AuthRepository { 5 | final AuthService _authService = AuthService(); 6 | 7 | Future login(String username, String password) { 8 | return _authService.login(username, password); 9 | } 10 | 11 | Future logout() { 12 | return _authService.logout(); 13 | } 14 | 15 | Future loadUsername() { 16 | return _authService.loadUsername(); 17 | } 18 | 19 | String get loginResponse => _authService.loginResponse; 20 | 21 | // 修改这里,返回 Future 22 | Future get cookies => _authService.cookies; 23 | 24 | String get password => _authService.password; 25 | String get username => _authService.username; 26 | 27 | Future loadCredentials() { 28 | return _authService.loadCredentials(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/repositories/reservation_repository.dart: -------------------------------------------------------------------------------- 1 | import '../models/bus_route.dart'; 2 | import '../services/reservation_service.dart'; 3 | import '../providers/auth_provider.dart'; 4 | 5 | class ReservationRepository { 6 | final ReservationService _reservationService; 7 | 8 | ReservationRepository(AuthProvider authProvider) 9 | : _reservationService = ReservationService(authProvider); 10 | 11 | Future> getBusRoutes(int hallId, String time) { 12 | return _reservationService.fetchBusRoutes(hallId, time); 13 | } 14 | 15 | Future> fetchMyReservations() { 16 | return _reservationService.fetchMyReservations(); 17 | } 18 | 19 | Future getReservationQRCode( 20 | String id, String hallAppointmentDataId) async { 21 | try { 22 | return await _reservationService.getReservationQRCode( 23 | id, hallAppointmentDataId); 24 | } catch (e) { 25 | print('获取二维码时出错: $e'); 26 | rethrow; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/screens/login/close_button.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class CloseButtonWidget extends StatelessWidget { 4 | @override 5 | Widget build(BuildContext context) { 6 | return Align( 7 | alignment: Alignment.topRight, 8 | child: IconButton( 9 | icon: Icon( 10 | Icons.close, 11 | color: Theme.of(context).colorScheme.onSurface, 12 | ), 13 | onPressed: () { 14 | // 关闭操作,例如返回上一页 15 | Navigator.of(context).pop(); 16 | }, 17 | ), 18 | ); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/screens/login/password_field.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class PasswordField extends StatefulWidget { 4 | final FormFieldSetter onSaved; 5 | final FormFieldValidator validator; 6 | 7 | PasswordField({required this.onSaved, required this.validator}); 8 | 9 | @override 10 | PasswordFieldState createState() => PasswordFieldState(); // 修改这里 11 | } 12 | 13 | class PasswordFieldState extends State { 14 | // 修改这里 15 | bool _obscureText = true; 16 | 17 | @override 18 | Widget build(BuildContext context) { 19 | final theme = Theme.of(context); 20 | 21 | return TextFormField( 22 | decoration: InputDecoration( 23 | labelText: '密码', 24 | hintText: '请输入您的密码', 25 | labelStyle: TextStyle(color: theme.colorScheme.primary), 26 | hintStyle: TextStyle(color: theme.hintColor), 27 | enabledBorder: OutlineInputBorder( 28 | borderRadius: BorderRadius.circular(12), 29 | borderSide: BorderSide(color: theme.colorScheme.outline), 30 | ), 31 | focusedBorder: OutlineInputBorder( 32 | borderRadius: BorderRadius.circular(12), 33 | borderSide: BorderSide(color: theme.colorScheme.primary, width: 2), 34 | ), 35 | errorBorder: OutlineInputBorder( 36 | borderRadius: BorderRadius.circular(12), 37 | borderSide: BorderSide(color: theme.colorScheme.error), 38 | ), 39 | focusedErrorBorder: OutlineInputBorder( 40 | borderRadius: BorderRadius.circular(12), 41 | borderSide: BorderSide(color: theme.colorScheme.error, width: 2), 42 | ), 43 | prefixIcon: Icon( 44 | Icons.lock, 45 | color: theme.colorScheme.primary, 46 | ), 47 | suffixIcon: IconButton( 48 | icon: Icon( 49 | _obscureText ? Icons.visibility : Icons.visibility_off, 50 | color: theme.colorScheme.primary, 51 | ), 52 | onPressed: () { 53 | setState(() { 54 | _obscureText = !_obscureText; 55 | }); 56 | }, 57 | ), 58 | filled: true, 59 | fillColor: theme.colorScheme.surfaceContainerHighest, // 修改这里 60 | ), 61 | style: theme.textTheme.bodyLarge, 62 | obscureText: _obscureText, 63 | onSaved: widget.onSaved, 64 | validator: widget.validator, 65 | ); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /lib/screens/login/terms_checkbox.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class TermsCheckbox extends StatelessWidget { 4 | final bool agreeToTerms; 5 | final ValueChanged onChanged; 6 | 7 | TermsCheckbox({required this.agreeToTerms, required this.onChanged}); 8 | 9 | @override 10 | Widget build(BuildContext context) { 11 | return Row( 12 | children: [ 13 | Checkbox( 14 | value: agreeToTerms, 15 | onChanged: onChanged, 16 | activeColor: Theme.of(context).colorScheme.primary, 17 | ), 18 | Expanded( 19 | child: Column( 20 | crossAxisAlignment: CrossAxisAlignment.start, 21 | children: [ 22 | Text( 23 | '我同意服务条款', 24 | style: Theme.of(context).textTheme.bodyLarge?.copyWith( 25 | color: Theme.of(context).colorScheme.onSurface, 26 | ), 27 | ), 28 | Text( 29 | '继续即表示您同意我们的隐私政策和服务条款', 30 | style: Theme.of(context).textTheme.labelSmall?.copyWith( 31 | color: Theme.of(context) 32 | .colorScheme 33 | .onSurface 34 | .withAlpha((0.6 * 255).toInt()), 35 | ), 36 | ), 37 | ], 38 | ), 39 | ), 40 | ], 41 | ); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /lib/screens/login/username_field.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class UsernameField extends StatelessWidget { 4 | final FormFieldSetter onSaved; 5 | final FormFieldValidator validator; 6 | 7 | UsernameField({required this.onSaved, required this.validator}); 8 | 9 | @override 10 | Widget build(BuildContext context) { 11 | final theme = Theme.of(context); 12 | 13 | return TextFormField( 14 | decoration: InputDecoration( 15 | labelText: '学号/职工号/手机号', 16 | hintText: '请输入您的账号', 17 | labelStyle: TextStyle(color: theme.colorScheme.primary), 18 | hintStyle: TextStyle(color: theme.hintColor), 19 | enabledBorder: OutlineInputBorder( 20 | borderRadius: BorderRadius.circular(12), 21 | borderSide: BorderSide(color: theme.colorScheme.outline), 22 | ), 23 | focusedBorder: OutlineInputBorder( 24 | borderRadius: BorderRadius.circular(12), 25 | borderSide: BorderSide(color: theme.colorScheme.primary, width: 2), 26 | ), 27 | errorBorder: OutlineInputBorder( 28 | borderRadius: BorderRadius.circular(12), 29 | borderSide: BorderSide(color: theme.colorScheme.error), 30 | ), 31 | focusedErrorBorder: OutlineInputBorder( 32 | borderRadius: BorderRadius.circular(12), 33 | borderSide: BorderSide(color: theme.colorScheme.error, width: 2), 34 | ), 35 | prefixIcon: Icon( 36 | Icons.person, 37 | color: theme.colorScheme.primary, 38 | ), 39 | filled: true, 40 | fillColor: theme.colorScheme.surfaceContainerHighest, // 修改这里 41 | ), 42 | style: theme.textTheme.bodyLarge, 43 | keyboardType: TextInputType.text, 44 | textInputAction: TextInputAction.next, 45 | onSaved: onSaved, 46 | validator: validator, 47 | ); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lib/screens/reservation/bus_list.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'bus_section.dart'; 3 | 4 | class BusList extends StatelessWidget { 5 | final List filteredBusList; 6 | final Function(Map) onBusCardTap; 7 | final Function(Map) showBusDetails; 8 | final Map reservedBuses; 9 | final Map buttonCooldowns; 10 | final bool isRefreshing; 11 | 12 | const BusList({ 13 | super.key, 14 | required this.filteredBusList, 15 | required this.onBusCardTap, 16 | required this.showBusDetails, 17 | required this.reservedBuses, 18 | required this.buttonCooldowns, 19 | this.isRefreshing = false, 20 | }); 21 | 22 | @override 23 | Widget build(BuildContext context) { 24 | final theme = Theme.of(context); 25 | 26 | return Stack( 27 | children: [ 28 | ListView( 29 | padding: EdgeInsets.only(top: 0), 30 | children: [ 31 | BusSection( 32 | title: '去燕园', 33 | buses: _getBusesByDirection('去燕园'), 34 | onBusCardTap: onBusCardTap, 35 | showBusDetails: showBusDetails, 36 | reservedBuses: reservedBuses, 37 | buttonCooldowns: buttonCooldowns, 38 | ), 39 | SizedBox(height: 24), 40 | BusSection( 41 | title: '去昌平', 42 | buses: _getBusesByDirection('去昌平'), 43 | onBusCardTap: onBusCardTap, 44 | showBusDetails: showBusDetails, 45 | reservedBuses: reservedBuses, 46 | buttonCooldowns: buttonCooldowns, 47 | ), 48 | SizedBox(height: 24), 49 | BusSection( 50 | title: '新燕园校区→200号校区', 51 | buses: _getBusesByDirection('新燕园校区→200号校区'), 52 | onBusCardTap: onBusCardTap, 53 | showBusDetails: showBusDetails, 54 | reservedBuses: reservedBuses, 55 | buttonCooldowns: buttonCooldowns, 56 | ), 57 | SizedBox(height: 24), 58 | BusSection( 59 | title: '200号校区→新燕园校区', 60 | buses: _getBusesByDirection('200号校区→新燕园校区'), 61 | onBusCardTap: onBusCardTap, 62 | showBusDetails: showBusDetails, 63 | reservedBuses: reservedBuses, 64 | buttonCooldowns: buttonCooldowns, 65 | ), 66 | ], 67 | ), 68 | Positioned( 69 | top: 12, 70 | left: 16, 71 | right: 16, 72 | child: AnimatedSwitcher( 73 | duration: Duration(milliseconds: 300), 74 | child: isRefreshing 75 | ? Container( 76 | height: 2, 77 | decoration: BoxDecoration( 78 | borderRadius: BorderRadius.circular(1), 79 | gradient: LinearGradient( 80 | begin: Alignment.centerLeft, 81 | end: Alignment.centerRight, 82 | colors: [ 83 | theme.colorScheme.primary 84 | .withAlpha((0 * 255).toInt()), 85 | theme.colorScheme.primary 86 | .withAlpha((0.5 * 255).toInt()), 87 | theme.colorScheme.primary 88 | .withAlpha((1 * 255).toInt()), 89 | theme.colorScheme.primary 90 | .withAlpha((0.5 * 255).toInt()), 91 | theme.colorScheme.primary 92 | .withAlpha((0 * 255).toInt()), 93 | ], 94 | stops: [0.0, 0.25, 0.5, 0.75, 1.0], 95 | ), 96 | ), 97 | child: ClipRRect( 98 | borderRadius: BorderRadius.circular(1), 99 | child: LinearProgressIndicator( 100 | backgroundColor: Colors.transparent, 101 | valueColor: AlwaysStoppedAnimation( 102 | theme.colorScheme.primary 103 | .withAlpha((0.3 * 255).toInt()), 104 | ), 105 | minHeight: 2, 106 | ), 107 | ), 108 | ) 109 | : SizedBox(height: 2), 110 | ), 111 | ), 112 | ], 113 | ); 114 | } 115 | 116 | List _getBusesByDirection(String direction) { 117 | // 定义去昌平方向的路线(即:燕园校区在前,新燕园校区在后) 118 | final routesToChangping = { 119 | "燕园校区→新燕园校区", 120 | "燕园校区→新燕园校区→200号校区", 121 | "燕园校区→肖家河→西二旗→新燕园校区→200号校区", 122 | }; 123 | 124 | // 定义去燕园方向的路线(即:新燕园校区在前,燕园校区在后) 125 | final routesToYanyuan = { 126 | "新燕园校区→燕园校区", 127 | "200号校区→新燕园校区→燕园校区", 128 | "200号校区→新燕园校区→西二旗→肖家河→燕园校区", 129 | }; 130 | 131 | // 新燕园校区→200号校区 132 | final routesTo200 = { 133 | "新燕园校区→200号校区", 134 | }; 135 | 136 | // 200号校区→新燕园校区 137 | final routesLeave200 = { 138 | "200号校区→新燕园校区", 139 | }; 140 | 141 | return filteredBusList.where((bus) { 142 | final routeName = bus['route_name'] ?? ''; 143 | if (direction == '去昌平') { 144 | return routesToChangping.contains(routeName); 145 | } else if (direction == '去燕园') { 146 | return routesToYanyuan.contains(routeName); 147 | } else if (direction == '新燕园校区→200号校区') { 148 | return routesTo200.contains(routeName); 149 | } else if (direction == '200号校区→新燕园校区') { 150 | return routesLeave200.contains(routeName); 151 | } 152 | return false; 153 | }).toList(); 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /lib/screens/reservation/bus_section.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'bus_button.dart'; 3 | 4 | class BusSection extends StatelessWidget { 5 | final String title; 6 | final List buses; 7 | final Function(Map) onBusCardTap; 8 | final Function(Map) showBusDetails; 9 | final Map reservedBuses; 10 | final Map buttonCooldowns; 11 | 12 | const BusSection({ 13 | super.key, 14 | required this.title, 15 | required this.buses, 16 | required this.onBusCardTap, 17 | required this.showBusDetails, 18 | required this.reservedBuses, 19 | required this.buttonCooldowns, 20 | }); 21 | 22 | @override 23 | Widget build(BuildContext context) { 24 | final theme = Theme.of(context); 25 | buses.sort((a, b) => a['yaxis'].compareTo(b['yaxis'])); 26 | 27 | return Column( 28 | crossAxisAlignment: CrossAxisAlignment.start, 29 | children: [ 30 | Padding( 31 | padding: const EdgeInsets.fromLTRB(24, 24, 24, 16), 32 | child: Row( 33 | children: [ 34 | Container( 35 | width: 4, 36 | height: 24, 37 | decoration: BoxDecoration( 38 | color: theme.colorScheme.primary, 39 | borderRadius: BorderRadius.circular(2), 40 | ), 41 | ), 42 | const SizedBox(width: 12), 43 | Text( 44 | title, 45 | style: theme.textTheme.titleLarge?.copyWith( 46 | fontWeight: FontWeight.w600, 47 | fontSize: title.length > 4 ? 16 : 20, 48 | color: theme.colorScheme.onSurface, 49 | letterSpacing: 0.5, 50 | ), 51 | ), 52 | ], 53 | ), 54 | ), 55 | Padding( 56 | padding: const EdgeInsets.symmetric(horizontal: 16.0), 57 | child: _buildBusButtons(context), 58 | ), 59 | ], 60 | ); 61 | } 62 | 63 | Widget _buildBusButtons(BuildContext context) { 64 | final theme = Theme.of(context); 65 | List morningButtons = []; 66 | List afternoonButtons = []; 67 | List eveningButtons = []; 68 | 69 | for (var busData in buses) { 70 | String time = busData['yaxis'] ?? ''; 71 | DateTime busTime = DateTime.parse('${busData['abscissa']} $time'); 72 | 73 | Widget button = BusButton( 74 | busData: busData, 75 | onBusCardTap: onBusCardTap, 76 | showBusDetails: showBusDetails, 77 | reservedBuses: reservedBuses, 78 | buttonCooldowns: buttonCooldowns, 79 | ); 80 | 81 | if (busTime.hour < 12) { 82 | morningButtons.add(button); 83 | } else if (busTime.hour < 18) { 84 | afternoonButtons.add(button); 85 | } else { 86 | eveningButtons.add(button); 87 | } 88 | } 89 | 90 | if (morningButtons.isEmpty && 91 | afternoonButtons.isEmpty && 92 | eveningButtons.isEmpty) { 93 | return Center( 94 | child: Padding( 95 | padding: const EdgeInsets.symmetric(vertical: 24), 96 | child: Row( 97 | mainAxisSize: MainAxisSize.min, 98 | children: [ 99 | Icon( 100 | Icons.info_outline, 101 | size: 20, 102 | color: theme.colorScheme.onSurfaceVariant, 103 | ), 104 | const SizedBox(width: 8), 105 | Text( 106 | '当日该班次已无车可坐', 107 | style: theme.textTheme.bodyMedium?.copyWith( 108 | color: theme.colorScheme.onSurfaceVariant, 109 | letterSpacing: 0.5, 110 | ), 111 | ), 112 | ], 113 | ), 114 | ), 115 | ); 116 | } 117 | 118 | return Column( 119 | children: [ 120 | if (morningButtons.isNotEmpty) ...[ 121 | _buildTimeSection(context, '上午', morningButtons), 122 | const SizedBox(height: 16), 123 | ], 124 | if (afternoonButtons.isNotEmpty) ...[ 125 | _buildTimeSection(context, '下午', afternoonButtons), 126 | const SizedBox(height: 16), 127 | ], 128 | if (eveningButtons.isNotEmpty) 129 | _buildTimeSection(context, '晚上', eveningButtons), 130 | ], 131 | ); 132 | } 133 | 134 | Widget _buildTimeSection( 135 | BuildContext context, String timeLabel, List buttons) { 136 | final theme = Theme.of(context); 137 | return Column( 138 | crossAxisAlignment: CrossAxisAlignment.start, 139 | children: [ 140 | Padding( 141 | padding: const EdgeInsets.only(left: 8, bottom: 8), 142 | child: Text( 143 | timeLabel, 144 | style: theme.textTheme.titleSmall?.copyWith( 145 | color: theme.colorScheme.onSurfaceVariant, 146 | fontWeight: FontWeight.w500, 147 | ), 148 | ), 149 | ), 150 | Row( 151 | mainAxisAlignment: MainAxisAlignment.spaceEvenly, 152 | children: buttons, 153 | ), 154 | ], 155 | ); 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /lib/screens/ride/ride_button.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter/services.dart'; 3 | 4 | class RideButton extends StatelessWidget { 5 | final bool isReservation; 6 | final bool isToggleLoading; 7 | final VoidCallback onPressed; 8 | final Color buttonColor; 9 | final Color textColor; 10 | 11 | const RideButton({ 12 | super.key, 13 | required this.isReservation, 14 | required this.isToggleLoading, 15 | required this.onPressed, 16 | required this.buttonColor, 17 | required this.textColor, 18 | }); 19 | 20 | @override 21 | Widget build(BuildContext context) { 22 | return SizedBox( 23 | width: 240, 24 | height: 56, 25 | child: ElevatedButton( 26 | onPressed: isToggleLoading 27 | ? null 28 | : () { 29 | HapticFeedback.lightImpact(); 30 | onPressed(); 31 | }, 32 | style: ElevatedButton.styleFrom( 33 | backgroundColor: isToggleLoading ? Colors.grey.shade200 : buttonColor, 34 | foregroundColor: isToggleLoading ? Colors.grey : textColor, 35 | elevation: 0, 36 | padding: EdgeInsets.zero, 37 | shape: 38 | RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)), 39 | ), 40 | child: isToggleLoading 41 | ? Center( 42 | child: SizedBox( 43 | width: 24, 44 | height: 24, 45 | child: CircularProgressIndicator( 46 | strokeWidth: 2, 47 | valueColor: AlwaysStoppedAnimation(textColor), 48 | ), 49 | ), 50 | ) 51 | : Text( 52 | isReservation ? '取消预约' : '预约', 53 | style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600), 54 | ), 55 | ), 56 | ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /lib/screens/ride/ride_card_header.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class RideCardHeader extends StatelessWidget { 4 | final bool isNoBusAvailable; 5 | final String codeType; 6 | 7 | const RideCardHeader({ 8 | super.key, 9 | required this.isNoBusAvailable, 10 | required this.codeType, 11 | }); 12 | 13 | @override 14 | Widget build(BuildContext context) { 15 | Color startColor; 16 | Color endColor; 17 | Color textColor; 18 | String headerText; 19 | 20 | final theme = Theme.of(context); 21 | final isDarkMode = theme.brightness == Brightness.dark; 22 | 23 | if (isNoBusAvailable) { 24 | startColor = isDarkMode ? Colors.grey[800]! : Colors.grey[200]!; 25 | endColor = isDarkMode ? Colors.grey[900]! : Colors.grey[100]!; 26 | textColor = isDarkMode ? Colors.grey[300]! : Colors.grey[700]!; 27 | headerText = '无车可坐'; 28 | } else { 29 | if (codeType == '乘车码') { 30 | startColor = theme.colorScheme.primary.withAlpha((0.2 * 255).toInt()); 31 | endColor = theme.colorScheme.primary.withAlpha((0.05 * 255).toInt()); 32 | textColor = theme.colorScheme.primary; 33 | headerText = '乘车码'; 34 | } else if (codeType == '临时码') { 35 | startColor = theme.colorScheme.secondary.withAlpha((0.2 * 255).toInt()); 36 | endColor = theme.colorScheme.secondary.withAlpha((0.05 * 255).toInt()); 37 | textColor = theme.colorScheme.secondary; 38 | headerText = '临时码'; 39 | } else { 40 | startColor = theme.colorScheme.tertiary.withAlpha((0.2 * 255).toInt()); 41 | endColor = theme.colorScheme.tertiary.withAlpha((0.05 * 255).toInt()); 42 | textColor = theme.colorScheme.tertiary; 43 | headerText = '待预约'; 44 | } 45 | } 46 | 47 | return Container( 48 | padding: EdgeInsets.symmetric(vertical: 12), 49 | decoration: BoxDecoration( 50 | gradient: LinearGradient( 51 | colors: [startColor, endColor], 52 | begin: Alignment.topCenter, 53 | end: Alignment.bottomCenter, 54 | ), 55 | borderRadius: BorderRadius.vertical(top: Radius.circular(20)), 56 | ), 57 | child: Center( 58 | child: Text( 59 | headerText, 60 | style: TextStyle( 61 | fontSize: 18, 62 | fontWeight: FontWeight.w600, 63 | color: textColor, 64 | ), 65 | ), 66 | ), 67 | ); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /lib/screens/visualization/yearly_summary/random_percentage_widget.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | import 'package:flutter/material.dart'; 3 | import 'stripe_painter.dart'; 4 | 5 | class RandomPercentageWidget extends StatefulWidget { 6 | final GlobalKey? randomKey; 7 | 8 | const RandomPercentageWidget({ 9 | super.key, 10 | this.randomKey, 11 | }); 12 | 13 | @override 14 | State createState() => RandomPercentageWidgetState(); 15 | } 16 | 17 | class RandomPercentageWidgetState extends State { 18 | int? randomPercentage; 19 | 20 | void generateRandomPercentage() { 21 | setState(() { 22 | randomPercentage = 50 + Random().nextInt(51); 23 | }); 24 | } 25 | 26 | @override 27 | Widget build(BuildContext context) { 28 | final theme = Theme.of(context); 29 | return MouseRegion( 30 | cursor: SystemMouseCursors.click, 31 | child: GestureDetector( 32 | onTap: () { 33 | generateRandomPercentage(); 34 | }, 35 | child: SizedBox( 36 | height: 60, 37 | child: AnimatedSwitcher( 38 | duration: Duration(milliseconds: 200), 39 | child: randomPercentage == null 40 | ? SizedBox( 41 | key: ValueKey('initial'), 42 | width: 65, 43 | child: ClipRRect( 44 | borderRadius: BorderRadius.circular(6), 45 | child: Stack( 46 | alignment: Alignment.center, 47 | children: [ 48 | Positioned.fill( 49 | child: CustomPaint( 50 | painter: StripePainter( 51 | color: theme.colorScheme.primary 52 | .withAlpha((0.2 * 255).toInt()), 53 | stripeWidth: 4, 54 | gapWidth: 4, 55 | ), 56 | ), 57 | ), 58 | Text( 59 | 'randint\n(50,100)', 60 | textAlign: TextAlign.center, 61 | style: TextStyle( 62 | fontSize: 13, 63 | color: theme.colorScheme.onSurfaceVariant, 64 | fontFamily: 'monospace', 65 | fontWeight: FontWeight.w500, 66 | height: 1, 67 | ), 68 | ), 69 | ], 70 | ), 71 | ), 72 | ) 73 | : SizedBox( 74 | width: 65, 75 | child: Text( 76 | key: ValueKey('percentage'), 77 | '$randomPercentage%', 78 | textAlign: TextAlign.center, 79 | style: TextStyle( 80 | fontSize: 20, 81 | color: theme.colorScheme.primary, 82 | fontWeight: FontWeight.bold, 83 | height: 1, 84 | ), 85 | ), 86 | ), 87 | ), 88 | ), 89 | ), 90 | ); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /lib/screens/visualization/yearly_summary/stripe_painter.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class StripePainter extends CustomPainter { 4 | final Color color; 5 | final double stripeWidth; 6 | final double gapWidth; 7 | 8 | StripePainter({ 9 | required this.color, 10 | required this.stripeWidth, 11 | required this.gapWidth, 12 | }); 13 | 14 | @override 15 | void paint(Canvas canvas, Size size) { 16 | final paint = Paint() 17 | ..color = color 18 | ..strokeWidth = stripeWidth 19 | ..strokeCap = StrokeCap.round; 20 | 21 | final spacing = stripeWidth + gapWidth; 22 | final count = (size.width + size.height) ~/ spacing; 23 | 24 | for (var i = -count; i < count * 2; i++) { 25 | final x = i * spacing - size.height; 26 | canvas.drawLine( 27 | Offset(x, size.height), 28 | Offset(x + size.height, 0), 29 | paint, 30 | ); 31 | } 32 | } 33 | 34 | @override 35 | bool shouldRepaint(StripePainter oldDelegate) => 36 | color != oldDelegate.color || 37 | stripeWidth != oldDelegate.stripeWidth || 38 | gapWidth != oldDelegate.gapWidth; 39 | } 40 | -------------------------------------------------------------------------------- /lib/screens/visualization/yearly_summary/summary_monthly_bar_chart.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class SummaryMonthlyBarChart extends StatelessWidget { 4 | final Map monthlyRides; 5 | final int maxCount; 6 | 7 | const SummaryMonthlyBarChart({ 8 | required this.monthlyRides, 9 | required this.maxCount, 10 | }); 11 | 12 | String _getMonthAbbr(int month) { 13 | const monthAbbrs = [ 14 | 'JAN', 15 | 'FEB', 16 | 'MAR', 17 | 'APR', 18 | 'MAY', 19 | 'JUN', 20 | 'JUL', 21 | 'AUG', 22 | 'SEP', 23 | 'OCT', 24 | 'NOV', 25 | 'DEC' 26 | ]; 27 | return monthAbbrs[month - 1]; 28 | } 29 | 30 | @override 31 | Widget build(BuildContext context) { 32 | final theme = Theme.of(context); 33 | final primaryColor = theme.colorScheme.primary; 34 | 35 | return Container( 36 | height: 240.0, 37 | padding: EdgeInsets.fromLTRB(8, 12, 16, 8), 38 | child: GridView.builder( 39 | physics: NeverScrollableScrollPhysics(), 40 | gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( 41 | crossAxisCount: 4, 42 | childAspectRatio: 1.2, 43 | crossAxisSpacing: 8, 44 | mainAxisSpacing: 8, 45 | ), 46 | itemCount: 12, 47 | itemBuilder: (context, index) { 48 | final month = index + 1; 49 | final count = monthlyRides[month] ?? 0; 50 | final opacity = maxCount > 0 ? (count / maxCount) * 0.8 + 0.1 : 0.1; 51 | 52 | return Container( 53 | decoration: BoxDecoration( 54 | color: primaryColor.withAlpha((opacity * 255).toInt()), 55 | borderRadius: BorderRadius.circular(8), 56 | ), 57 | child: Stack( 58 | children: [ 59 | // 数字和月份缩写居中布局 60 | Center( 61 | child: Column( 62 | mainAxisSize: MainAxisSize.min, 63 | children: [ 64 | Text( 65 | count.toString(), 66 | style: TextStyle( 67 | color: theme.colorScheme.onSurfaceVariant, 68 | fontSize: 24, 69 | fontWeight: FontWeight.w600, 70 | height: 1, 71 | ), 72 | ), 73 | SizedBox(height: 1), // 极小的间距 74 | Text( 75 | _getMonthAbbr(month), 76 | style: TextStyle( 77 | color: theme.colorScheme.onSurfaceVariant, 78 | fontSize: 8, // 更小的字号 79 | fontWeight: FontWeight.w500, 80 | letterSpacing: 0.5, 81 | height: 1, 82 | ), 83 | ), 84 | ], 85 | ), 86 | ), 87 | ], 88 | ), 89 | ); 90 | }, 91 | ), 92 | ); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /lib/screens/visualization/yearly_summary/summary_text_builder.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'random_percentage_widget.dart'; 3 | 4 | class SummaryTextBuilder { 5 | static Widget buildStoryText( 6 | BuildContext context, 7 | String text, { 8 | bool highlight = false, 9 | double? fontSize, 10 | TextAlign? textAlign, 11 | GlobalKey? randomKey, 12 | }) { 13 | final theme = Theme.of(context); 14 | return Padding( 15 | padding: EdgeInsets.symmetric(vertical: 12), 16 | child: RichText( 17 | textAlign: textAlign ?? TextAlign.left, 18 | text: TextSpan( 19 | style: TextStyle( 20 | fontSize: fontSize ?? (highlight ? 20 : 16), 21 | height: 1.6, 22 | fontWeight: highlight ? FontWeight.bold : FontWeight.normal, 23 | color: theme.colorScheme.onSurface, 24 | ), 25 | children: text 26 | .split('**') 27 | .asMap() 28 | .map((index, segment) { 29 | if (segment == '???%') { 30 | return MapEntry( 31 | index, 32 | WidgetSpan( 33 | alignment: PlaceholderAlignment.middle, 34 | child: RandomPercentageWidget( 35 | key: randomKey, 36 | randomKey: randomKey, 37 | ), 38 | ), 39 | ); 40 | } 41 | return MapEntry( 42 | index, 43 | TextSpan( 44 | text: segment, 45 | style: TextStyle( 46 | fontSize: index % 2 == 1 47 | ? (fontSize ?? 24) 48 | : (fontSize ?? (highlight ? 20 : 16)), 49 | color: index % 2 == 1 50 | ? theme.colorScheme.primary 51 | : theme.colorScheme.onSurface, 52 | fontWeight: index % 2 == 1 53 | ? FontWeight.bold 54 | : (highlight ? FontWeight.bold : FontWeight.normal), 55 | height: 1.6, 56 | ), 57 | ), 58 | ); 59 | }) 60 | .values 61 | .toList(), 62 | ), 63 | ), 64 | ); 65 | } 66 | 67 | static String getMorningBusComment(String busTime, int count) { 68 | int hour = int.parse(busTime.split(':')[0]); 69 | 70 | if (hour < 7) { 71 | return '早上你最常选择的是 **$busTime** 的早班车,是个起得特别早的早起鸟呢,继续保持这个好习惯吧!'; 72 | } else if (hour < 9) { 73 | return '早上你最常选择的是 **$busTime** 的班车,作息很规律呢,继续保持健康的生活节奏吧!'; 74 | } else { 75 | return '早上你最常选择的是 **$busTime** 的班车,看来你很享受睡到自然醒呢,这是在提前适应大厂作息吗?😉'; 76 | } 77 | } 78 | 79 | static String getNightBusComment(String busTime, int count) { 80 | int hour = int.parse(busTime.split(':')[0]); 81 | 82 | if (hour < 21) { 83 | return '晚上你最常选择的是 **$busTime** 的班车,看来你很注重工作与生活的平衡呢!'; 84 | } else { 85 | return '晚上你最常选择的是 **$busTime** 的班车,是个努力的夜猫子呢,要记得注意休息哦!'; 86 | } 87 | } 88 | 89 | static String getViolationComment(int violationCount, double violationRate) { 90 | String baseText = 91 | '其中有 **$violationCount** 次未能按时签到,违约率为 **${violationRate.toStringAsFixed(1)}%**'; 92 | 93 | if (violationRate == 0) { 94 | return '$baseText,你太靠谱了,从不爽约!'; 95 | } else if (violationRate <= 5) { 96 | return '$baseText,偶尔也会有意外发生,但你的守时表现依然很棒!'; 97 | } else if (violationRate <= 15) { 98 | return '$baseText,还需要继续努力,相信明年一定会更好!'; 99 | } else { 100 | return '$baseText,这个违约率有点高哦,建议提前5分钟到达候车点~'; 101 | } 102 | } 103 | 104 | static String getShareText( 105 | Map summary, int randomPercentage) { 106 | return '我在${summary['year']}年共预约了${summary['totalRides']}次班车,超越了$randomPercentage%的马池口🐮🐴,年度关键词是"${summary['keyword']}"!来自 Marchkov Helper'; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /lib/screens/visualization/yearly_summary/summary_violation_pie_chart.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:fl_chart/fl_chart.dart'; 3 | 4 | class SummaryViolationPieChart extends StatelessWidget { 5 | final int totalRides; 6 | final int violationCount; 7 | 8 | const SummaryViolationPieChart({ 9 | required this.totalRides, 10 | required this.violationCount, 11 | }); 12 | 13 | @override 14 | Widget build(BuildContext context) { 15 | final theme = Theme.of(context); 16 | final checkedInCount = totalRides - violationCount; 17 | final violationRate = 18 | (violationCount / totalRides * 100).toStringAsFixed(1); 19 | final checkedInRate = 20 | ((checkedInCount) / totalRides * 100).toStringAsFixed(1); 21 | 22 | return SizedBox( 23 | height: 150, 24 | child: Row( 25 | children: [ 26 | Expanded( 27 | child: PieChart( 28 | PieChartData( 29 | sectionsSpace: 0, 30 | centerSpaceRadius: 30, 31 | sections: [ 32 | PieChartSectionData( 33 | color: theme.colorScheme.primary, 34 | value: checkedInCount.toDouble(), 35 | title: '', 36 | radius: 25, 37 | ), 38 | PieChartSectionData( 39 | color: theme.colorScheme.secondary, 40 | value: violationCount.toDouble(), 41 | title: '', 42 | radius: 25, 43 | ), 44 | ], 45 | ), 46 | ), 47 | ), 48 | SizedBox(width: 16), 49 | Column( 50 | mainAxisAlignment: MainAxisAlignment.center, 51 | crossAxisAlignment: CrossAxisAlignment.start, 52 | children: [ 53 | _buildLegendItem( 54 | context, 55 | color: theme.colorScheme.primary, 56 | label: '准时签到', 57 | rate: '$checkedInRate%', 58 | ), 59 | SizedBox(height: 8), 60 | _buildLegendItem( 61 | context, 62 | color: theme.colorScheme.secondary, 63 | label: '未能签到', 64 | rate: '$violationRate%', 65 | ), 66 | ], 67 | ), 68 | SizedBox(width: 16), 69 | ], 70 | ), 71 | ); 72 | } 73 | 74 | Widget _buildLegendItem( 75 | BuildContext context, { 76 | required Color color, 77 | required String label, 78 | required String rate, 79 | }) { 80 | final theme = Theme.of(context); 81 | return Row( 82 | mainAxisSize: MainAxisSize.min, 83 | children: [ 84 | Container( 85 | width: 12, 86 | height: 12, 87 | decoration: BoxDecoration( 88 | color: color, 89 | shape: BoxShape.circle, 90 | ), 91 | ), 92 | SizedBox(width: 8), 93 | Column( 94 | crossAxisAlignment: CrossAxisAlignment.start, 95 | children: [ 96 | Text( 97 | label, 98 | style: TextStyle( 99 | fontSize: 12, 100 | color: theme.colorScheme.onSurfaceVariant, 101 | ), 102 | ), 103 | Text( 104 | rate, 105 | style: TextStyle( 106 | fontSize: 14, 107 | fontWeight: FontWeight.bold, 108 | color: color, 109 | ), 110 | ), 111 | ], 112 | ), 113 | ], 114 | ); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /lib/services/dau_service.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | import 'dart:convert'; 3 | import 'package:crypto/crypto.dart'; 4 | import 'package:http/http.dart' as http; 5 | import 'package:shared_preferences/shared_preferences.dart'; 6 | import '../providers/auth_provider.dart'; 7 | import 'version_service.dart'; 8 | 9 | class DauService { 10 | final AuthProvider _authProvider; 11 | final VersionService _versionService; 12 | 13 | DauService(this._authProvider, this._versionService); 14 | 15 | Future sendDailyActive() async { 16 | final prefs = await SharedPreferences.getInstance(); 17 | final today = DateTime.now(); 18 | final todayString = '${today.year}-${today.month}-${today.day}'; 19 | 20 | final lastSentDate = prefs.getString('lastDauSentDate'); 21 | 22 | if (lastSentDate == todayString) { 23 | // 已经发送过今天的 DAU 24 | return; 25 | } 26 | 27 | final studentId = _authProvider.username; // 假设 username 是 studentId 28 | final hash = sha256.convert(utf8.encode(studentId)).toString(); 29 | 30 | final version = await _versionService.getCurrentVersion(); 31 | 32 | // 检测设备是否为苹果设备 33 | final isApple = Platform.isIOS || Platform.isMacOS; 34 | 35 | final url = 36 | 'https://cf-marchkov-stats.variantconst.com/?hash=$hash&version=$version&isApple=${isApple ? 1 : 0}'; 37 | 38 | try { 39 | final response = await http.get(Uri.parse(url)); 40 | if (response.statusCode == 200) { 41 | // 发送成功,记录今天的日期 42 | await prefs.setString('lastDauSentDate', todayString); 43 | print('发送 DAU 请求成功,发送内容为: $url'); 44 | } else { 45 | print('发送 DAU 请求失败,状态码: ${response.statusCode}'); 46 | } 47 | } catch (e) { 48 | print('发送 DAU 请求出错: $e'); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /lib/services/ride_history_service.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'package:http/http.dart' as http; 3 | import 'package:intl/intl.dart'; 4 | import 'package:shared_preferences/shared_preferences.dart'; 5 | import '../models/ride_info.dart'; 6 | import '../providers/auth_provider.dart'; 7 | 8 | class RideHistoryService { 9 | final AuthProvider _authProvider; 10 | 11 | RideHistoryService(this._authProvider); 12 | 13 | Future> getRideHistory() async { 14 | // 检查用户是否已登录 15 | if (!_authProvider.isLoggedIn) { 16 | throw Exception('未找到用户凭证'); 17 | } 18 | 19 | // 获取缓存的预约历史 20 | final cachedHistory = await _getCachedRideHistory(); 21 | final lastFetchDate = 22 | cachedHistory?.lastFetchDate ?? DateTime.fromMillisecondsSinceEpoch(0); 23 | final cachedRides = cachedHistory?.rides ?? []; 24 | 25 | // 计算需要获取的日期范围,使用北京时间 26 | final dateFormat = DateFormat('yyyy-MM-dd'); 27 | final today = DateTime.now(); 28 | final startDate = lastFetchDate.subtract(Duration(days: 1)); 29 | final endDate = today; 30 | 31 | // 构建URL,只请求 status=4 和 status=5 的信息 32 | final dateStringStart = dateFormat.format(startDate); 33 | final dateStringEnd = dateFormat.format(endDate); 34 | final urlStrings = [ 35 | 'https://wproc.pku.edu.cn/site/reservation/my-list-time?p=1&page_size=0&status=4&sort_time=true&sort=desc&date_sta=$dateStringStart&date_end=$dateStringEnd', 36 | 'https://wproc.pku.edu.cn/site/reservation/my-list-time?p=1&page_size=0&status=5&sort_time=true&sort=desc&date_sta=$dateStringStart&date_end=$dateStringEnd', 37 | ]; 38 | 39 | // 发起请求获取新的预约历史 40 | List allNewRides = []; 41 | for (String url in urlStrings) { 42 | final rides = await _fetchRideHistory(url); 43 | allNewRides.addAll(rides); 44 | } 45 | 46 | // 合并新旧数据 47 | final mergedRides = _mergeRides(cachedRides, allNewRides, lastFetchDate); 48 | 49 | // 更新缓存 50 | await _updateCachedRideHistory(mergedRides, today); 51 | 52 | return mergedRides; 53 | } 54 | 55 | Future> _fetchRideHistory(String url) async { 56 | final response = await http.get( 57 | Uri.parse(url), 58 | headers: { 59 | 'Cookie': _authProvider.cookies, 60 | }, 61 | ); 62 | 63 | if (response.statusCode == 200) { 64 | final data = json.decode(response.body); 65 | if (data['e'] == 0) { 66 | List rideData = data['d']['data']; 67 | return rideData.map((ride) { 68 | return RideInfo.fromJson(ride); 69 | }).toList(); 70 | } else { 71 | throw Exception(data['m']); 72 | } 73 | } else { 74 | throw Exception('请求失败, 状态码: ${response.statusCode}'); 75 | } 76 | } 77 | 78 | Future _getCachedRideHistory() async { 79 | final prefs = await SharedPreferences.getInstance(); 80 | final data = prefs.getString('cachedRideHistory'); 81 | if (data != null) { 82 | return CachedRideHistory.fromJson(json.decode(data)); 83 | } 84 | return null; 85 | } 86 | 87 | Future _updateCachedRideHistory( 88 | List rides, DateTime lastFetchDate) async { 89 | final cachedHistory = 90 | CachedRideHistory(lastFetchDate: lastFetchDate, rides: rides); 91 | final prefs = await SharedPreferences.getInstance(); 92 | await prefs.setString( 93 | 'cachedRideHistory', json.encode(cachedHistory.toJson())); 94 | } 95 | 96 | List _mergeRides(List cachedRides, 97 | List newRides, DateTime lastFetchDate) { 98 | // 使用字符串比较避免日期解析错误 99 | final lastFetchTimeString = 100 | DateFormat('yyyy-MM-dd HH:mm:ss').format(lastFetchDate); 101 | 102 | // 过滤掉缓存中在 lastFetchDate 之后的记录 103 | final filteredCachedRides = cachedRides.where((ride) { 104 | return ride.appointmentTime.compareTo(lastFetchTimeString) < 0; 105 | }).toList(); 106 | 107 | // 创建一个 Map 以便合并 108 | final Map mergedRidesMap = { 109 | for (var ride in filteredCachedRides) ride.id: ride 110 | }; 111 | 112 | for (var newRide in newRides) { 113 | mergedRidesMap[newRide.id] = newRide; 114 | } 115 | 116 | // 将 Map 转换为 List 并按预约时间降序排序 117 | final mergedRides = mergedRidesMap.values.toList(); 118 | mergedRides.sort((a, b) => b.appointmentTime.compareTo(a.appointmentTime)); 119 | 120 | return mergedRides; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /lib/services/user_service.dart: -------------------------------------------------------------------------------- 1 | import 'package:http/http.dart' as http; 2 | import 'dart:convert'; 3 | import 'package:shared_preferences/shared_preferences.dart'; 4 | import '../providers/auth_provider.dart'; 5 | 6 | class UserService { 7 | final AuthProvider authProvider; 8 | 9 | UserService(this.authProvider); 10 | 11 | Future> fetchUserInfo() async { 12 | final prefs = await SharedPreferences.getInstance(); 13 | final name = prefs.getString('name'); 14 | final studentId = prefs.getString('studentId'); 15 | final college = prefs.getString('college'); 16 | 17 | if (name != null && studentId != null && college != null) { 18 | return { 19 | 'name': name, 20 | 'studentId': studentId, 21 | 'college': college, 22 | }; 23 | } 24 | 25 | // 如果本地没有数据,则从网络获取 26 | final cookies = await authProvider.getLatestCookies(); 27 | final response = await http.get( 28 | Uri.parse( 29 | 'https://wproc.pku.edu.cn/site/reservation/get-sign-qrcode?type=1&resource_id=7&text=22:00'), 30 | headers: { 31 | 'Cookie': cookies, 32 | }, 33 | ); 34 | 35 | if (response.statusCode == 200) { 36 | final data = json.decode(response.body); 37 | if (data['e'] == 0) { 38 | final userInfo = data['d']['name'].split('\r\n'); 39 | // 显式指定 result 的类型 40 | final Map result = { 41 | 'name': userInfo[0], 42 | 'studentId': userInfo[1], 43 | 'college': userInfo[2], 44 | }; 45 | 46 | // 保存到本地 47 | await prefs.setString('name', result['name']!); 48 | await prefs.setString('studentId', result['studentId']!); 49 | await prefs.setString('college', result['college']!); 50 | 51 | return result; 52 | } 53 | } 54 | throw Exception('获取用户信息失败'); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /lib/services/version_service.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | import 'package:package_info_plus/package_info_plus.dart'; 3 | import 'package:http/http.dart' as http; 4 | 5 | class VersionService { 6 | Future getCurrentVersion() async { 7 | PackageInfo packageInfo = await PackageInfo.fromPlatform(); 8 | return packageInfo.version; 9 | } 10 | 11 | Future getLatestVersion() async { 12 | try { 13 | final response = await http 14 | .get(Uri.parse('https://shuttle.variantconst.com/api/version')); 15 | if (response.statusCode == 200) { 16 | return response.body.trim(); 17 | } else { 18 | return null; 19 | } 20 | } catch (e) { 21 | return null; 22 | } 23 | } 24 | 25 | Future getUpdateURL() async { 26 | try { 27 | if (Platform.isIOS) { 28 | final response = await http 29 | .get(Uri.parse('https://shuttle.variantconst.com/api/ios_url')); 30 | if (response.statusCode == 200) { 31 | return response.body.trim(); 32 | } else { 33 | throw Exception('无法获取 iOS 更新链接'); 34 | } 35 | } else if (Platform.isAndroid) { 36 | final response = await http 37 | .get(Uri.parse('https://shuttle.variantconst.com/api/android_url')); 38 | if (response.statusCode == 200) { 39 | return response.body.trim(); 40 | } else { 41 | throw Exception('无法获取 Android 更新链接'); 42 | } 43 | } else { 44 | return 'https://shuttle.variantconst.com'; 45 | } 46 | } catch (e) { 47 | return null; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /lib/utils/date_formatter.dart: -------------------------------------------------------------------------------- 1 | // lib/utils/date_formatter.dart 2 | class DateFormatter { 3 | static String format(DateTime date) { 4 | // 实现日期格式化逻辑 5 | return "${date.year}-${date.month}-${date.day} ${date.hour}:${date.minute}"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /lib/widgets/error_dialog.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | void showErrorDialog(BuildContext context, String message) { 4 | showDialog( 5 | context: context, 6 | builder: (BuildContext context) { 7 | return AlertDialog( 8 | backgroundColor: Theme.of(context).colorScheme.surface, 9 | title: Text( 10 | '错误', 11 | style: TextStyle(color: Theme.of(context).colorScheme.onSurface), 12 | ), 13 | content: Text( 14 | message, 15 | style: TextStyle(color: Theme.of(context).colorScheme.onSurface), 16 | ), 17 | actions: [ 18 | TextButton( 19 | child: Text( 20 | '确定', 21 | style: TextStyle(color: Theme.of(context).colorScheme.primary), 22 | ), 23 | onPressed: () { 24 | Navigator.of(context).pop(); 25 | }, 26 | ), 27 | ], 28 | ); 29 | }, 30 | ); 31 | } 32 | -------------------------------------------------------------------------------- /linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project-level configuration. 2 | cmake_minimum_required(VERSION 3.10) 3 | project(runner LANGUAGES CXX) 4 | 5 | # The name of the executable created for the application. Change this to change 6 | # the on-disk name of your application. 7 | set(BINARY_NAME "marchkov_helper") 8 | # The unique GTK application identifier for this application. See: 9 | # https://wiki.gnome.org/HowDoI/ChooseApplicationID 10 | set(APPLICATION_ID "com.variantconst.marchkov_helper") 11 | 12 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 13 | # versions of CMake. 14 | cmake_policy(SET CMP0063 NEW) 15 | 16 | # Load bundled libraries from the lib/ directory relative to the binary. 17 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") 18 | 19 | # Root filesystem for cross-building. 20 | if(FLUTTER_TARGET_PLATFORM_SYSROOT) 21 | set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) 22 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) 23 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 24 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 25 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 26 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 27 | endif() 28 | 29 | # Define build configuration options. 30 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 31 | set(CMAKE_BUILD_TYPE "Debug" CACHE 32 | STRING "Flutter build mode" FORCE) 33 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 34 | "Debug" "Profile" "Release") 35 | endif() 36 | 37 | # Compilation settings that should be applied to most targets. 38 | # 39 | # Be cautious about adding new options here, as plugins use this function by 40 | # default. In most cases, you should add new options to specific targets instead 41 | # of modifying this function. 42 | function(APPLY_STANDARD_SETTINGS TARGET) 43 | target_compile_features(${TARGET} PUBLIC cxx_std_14) 44 | target_compile_options(${TARGET} PRIVATE -Wall -Werror) 45 | target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") 46 | target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") 47 | endfunction() 48 | 49 | # Flutter library and tool build rules. 50 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 51 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 52 | 53 | # System-level dependencies. 54 | find_package(PkgConfig REQUIRED) 55 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 56 | 57 | add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") 58 | 59 | # Define the application target. To change its name, change BINARY_NAME above, 60 | # not the value here, or `flutter run` will no longer work. 61 | # 62 | # Any new source files that you add to the application should be added here. 63 | add_executable(${BINARY_NAME} 64 | "main.cc" 65 | "my_application.cc" 66 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 67 | ) 68 | 69 | # Apply the standard set of build settings. This can be removed for applications 70 | # that need different build settings. 71 | apply_standard_settings(${BINARY_NAME}) 72 | 73 | # Add dependency libraries. Add any application-specific dependencies here. 74 | target_link_libraries(${BINARY_NAME} PRIVATE flutter) 75 | target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) 76 | 77 | # Run the Flutter tool portions of the build. This must not be removed. 78 | add_dependencies(${BINARY_NAME} flutter_assemble) 79 | 80 | # Only the install-generated bundle's copy of the executable will launch 81 | # correctly, since the resources must in the right relative locations. To avoid 82 | # people trying to run the unbundled copy, put it in a subdirectory instead of 83 | # the default top-level location. 84 | set_target_properties(${BINARY_NAME} 85 | PROPERTIES 86 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" 87 | ) 88 | 89 | 90 | # Generated plugin build rules, which manage building the plugins and adding 91 | # them to the application. 92 | include(flutter/generated_plugins.cmake) 93 | 94 | 95 | # === Installation === 96 | # By default, "installing" just makes a relocatable bundle in the build 97 | # directory. 98 | set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") 99 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 100 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 101 | endif() 102 | 103 | # Start with a clean build bundle directory every time. 104 | install(CODE " 105 | file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") 106 | " COMPONENT Runtime) 107 | 108 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 109 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") 110 | 111 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 112 | COMPONENT Runtime) 113 | 114 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 115 | COMPONENT Runtime) 116 | 117 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 118 | COMPONENT Runtime) 119 | 120 | foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) 121 | install(FILES "${bundled_library}" 122 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 123 | COMPONENT Runtime) 124 | endforeach(bundled_library) 125 | 126 | # Copy the native assets provided by the build.dart from all packages. 127 | set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") 128 | install(DIRECTORY "${NATIVE_ASSETS_DIR}" 129 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 130 | COMPONENT Runtime) 131 | 132 | # Fully re-copy the assets directory on each build to avoid having stale files 133 | # from a previous install. 134 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 135 | install(CODE " 136 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 137 | " COMPONENT Runtime) 138 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 139 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 140 | 141 | # Install the AOT library on non-Debug builds only. 142 | if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") 143 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 144 | COMPONENT Runtime) 145 | endif() 146 | -------------------------------------------------------------------------------- /linux/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.10) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | 12 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...), 13 | # which isn't available in 3.10. 14 | function(list_prepend LIST_NAME PREFIX) 15 | set(NEW_LIST "") 16 | foreach(element ${${LIST_NAME}}) 17 | list(APPEND NEW_LIST "${PREFIX}${element}") 18 | endforeach(element) 19 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) 20 | endfunction() 21 | 22 | # === Flutter Library === 23 | # System-level dependencies. 24 | find_package(PkgConfig REQUIRED) 25 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 26 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) 27 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) 28 | 29 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") 30 | 31 | # Published to parent scope for install step. 32 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 33 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 34 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 35 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) 36 | 37 | list(APPEND FLUTTER_LIBRARY_HEADERS 38 | "fl_basic_message_channel.h" 39 | "fl_binary_codec.h" 40 | "fl_binary_messenger.h" 41 | "fl_dart_project.h" 42 | "fl_engine.h" 43 | "fl_json_message_codec.h" 44 | "fl_json_method_codec.h" 45 | "fl_message_codec.h" 46 | "fl_method_call.h" 47 | "fl_method_channel.h" 48 | "fl_method_codec.h" 49 | "fl_method_response.h" 50 | "fl_plugin_registrar.h" 51 | "fl_plugin_registry.h" 52 | "fl_standard_message_codec.h" 53 | "fl_standard_method_codec.h" 54 | "fl_string_codec.h" 55 | "fl_value.h" 56 | "fl_view.h" 57 | "flutter_linux.h" 58 | ) 59 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") 60 | add_library(flutter INTERFACE) 61 | target_include_directories(flutter INTERFACE 62 | "${EPHEMERAL_DIR}" 63 | ) 64 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") 65 | target_link_libraries(flutter INTERFACE 66 | PkgConfig::GTK 67 | PkgConfig::GLIB 68 | PkgConfig::GIO 69 | ) 70 | add_dependencies(flutter flutter_assemble) 71 | 72 | # === Flutter tool backend === 73 | # _phony_ is a non-existent file to force this command to run every time, 74 | # since currently there's no way to get a full input/output list from the 75 | # flutter tool. 76 | add_custom_command( 77 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 78 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_ 79 | COMMAND ${CMAKE_COMMAND} -E env 80 | ${FLUTTER_TOOL_ENVIRONMENT} 81 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" 82 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} 83 | VERBATIM 84 | ) 85 | add_custom_target(flutter_assemble DEPENDS 86 | "${FLUTTER_LIBRARY}" 87 | ${FLUTTER_LIBRARY_HEADERS} 88 | ) 89 | -------------------------------------------------------------------------------- /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 | #include 10 | #include 11 | 12 | void fl_register_plugins(FlPluginRegistry* registry) { 13 | g_autoptr(FlPluginRegistrar) emoji_picker_flutter_registrar = 14 | fl_plugin_registry_get_registrar_for_plugin(registry, "EmojiPickerFlutterPlugin"); 15 | emoji_picker_flutter_plugin_register_with_registrar(emoji_picker_flutter_registrar); 16 | g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar = 17 | fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin"); 18 | url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar); 19 | } 20 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /linux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | emoji_picker_flutter 7 | url_launcher_linux 8 | ) 9 | 10 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 11 | ) 12 | 13 | set(PLUGIN_BUNDLED_LIBRARIES) 14 | 15 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 16 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) 17 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 18 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 19 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 20 | endforeach(plugin) 21 | 22 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 23 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) 24 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 25 | endforeach(ffi_plugin) 26 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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, "marchkov_helper"); 44 | gtk_header_bar_set_show_close_button(header_bar, TRUE); 45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); 46 | } else { 47 | gtk_window_set_title(window, "marchkov_helper"); 48 | } 49 | 50 | gtk_window_set_default_size(window, 1280, 720); 51 | gtk_widget_show(GTK_WIDGET(window)); 52 | 53 | g_autoptr(FlDartProject) project = fl_dart_project_new(); 54 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments); 55 | 56 | FlView* view = fl_view_new(project); 57 | gtk_widget_show(GTK_WIDGET(view)); 58 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); 59 | 60 | fl_register_plugins(FL_PLUGIN_REGISTRY(view)); 61 | 62 | gtk_widget_grab_focus(GTK_WIDGET(view)); 63 | } 64 | 65 | // Implements GApplication::local_command_line. 66 | static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) { 67 | MyApplication* self = MY_APPLICATION(application); 68 | // Strip out the first argument as it is the binary name. 69 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); 70 | 71 | g_autoptr(GError) error = nullptr; 72 | if (!g_application_register(application, nullptr, &error)) { 73 | g_warning("Failed to register: %s", error->message); 74 | *exit_status = 1; 75 | return TRUE; 76 | } 77 | 78 | g_application_activate(application); 79 | *exit_status = 0; 80 | 81 | return TRUE; 82 | } 83 | 84 | // Implements GApplication::startup. 85 | static void my_application_startup(GApplication* application) { 86 | //MyApplication* self = MY_APPLICATION(object); 87 | 88 | // Perform any actions required at application startup. 89 | 90 | G_APPLICATION_CLASS(my_application_parent_class)->startup(application); 91 | } 92 | 93 | // Implements GApplication::shutdown. 94 | static void my_application_shutdown(GApplication* application) { 95 | //MyApplication* self = MY_APPLICATION(object); 96 | 97 | // Perform any actions required at application shutdown. 98 | 99 | G_APPLICATION_CLASS(my_application_parent_class)->shutdown(application); 100 | } 101 | 102 | // Implements GObject::dispose. 103 | static void my_application_dispose(GObject* object) { 104 | MyApplication* self = MY_APPLICATION(object); 105 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); 106 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object); 107 | } 108 | 109 | static void my_application_class_init(MyApplicationClass* klass) { 110 | G_APPLICATION_CLASS(klass)->activate = my_application_activate; 111 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line; 112 | G_APPLICATION_CLASS(klass)->startup = my_application_startup; 113 | G_APPLICATION_CLASS(klass)->shutdown = my_application_shutdown; 114 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose; 115 | } 116 | 117 | static void my_application_init(MyApplication* self) {} 118 | 119 | MyApplication* my_application_new() { 120 | return MY_APPLICATION(g_object_new(my_application_get_type(), 121 | "application-id", APPLICATION_ID, 122 | "flags", G_APPLICATION_NON_UNIQUE, 123 | nullptr)); 124 | } 125 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /login_script.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import os 3 | import json 4 | import pickle 5 | import time 6 | from flutter_secure_storage import FlutterSecureStorage 7 | 8 | COOKIES_FILE = "cookies.pkl" 9 | CREDENTIALS_KEY = "user_credentials" 10 | storage = FlutterSecureStorage() 11 | 12 | def load_cookies(): 13 | if os.path.exists(COOKIES_FILE): 14 | with open(COOKIES_FILE, "rb") as f: 15 | return pickle.load(f) 16 | return None 17 | 18 | def save_cookies(cookies): 19 | with open(COOKIES_FILE, "wb") as f: 20 | pickle.dump(cookies, f) 21 | 22 | async def save_credentials(username, password): 23 | credentials = json.dumps({"username": username, "password": password}) 24 | await storage.write(key=CREDENTIALS_KEY, value=credentials) 25 | 26 | async def load_credentials(): 27 | credentials = await storage.read(key=CREDENTIALS_KEY) 28 | if credentials: 29 | return json.loads(credentials) 30 | return None 31 | 32 | async def clear_credentials(): 33 | await storage.delete(key=CREDENTIALS_KEY) 34 | 35 | async def login(): 36 | s = requests.Session() 37 | s.headers.update(headers) 38 | 39 | cookies = load_cookies() 40 | if cookies: 41 | s.cookies.update(cookies) 42 | if check_login_status(s): 43 | print("使用已保存的 cookies 登录成功") 44 | print("Cookies:", s.cookies.get_dict()) 45 | return s 46 | 47 | print("使用用户名密码登录") 48 | credentials = await load_credentials() 49 | if credentials: 50 | username = credentials["username"] 51 | password = credentials["password"] 52 | else: 53 | username = os.environ["PKU_USERNAME"] 54 | password = os.environ["PKU_PASSWORD"] 55 | 56 | print(f"尝试使用用户名 {username} 登录") 57 | 58 | r = s.get("https://wproc.pku.edu.cn/api/login/main") 59 | print("获取登录页面响应:", r.status_code) 60 | 61 | r = s.post( 62 | "https://iaaa.pku.edu.cn/iaaa/oauthlogin.do", 63 | data={ 64 | "appid": "wproc", 65 | "userName": username, 66 | "password": password, 67 | "redirUrl": "https://wproc.pku.edu.cn/site/login/cas-login?redirect_url=https://wproc.pku.edu.cn/v2/reserve/", 68 | }, 69 | ) 70 | 71 | print("登录请求响应:", r.text) 72 | token = json.loads(r.text)["token"] 73 | print("登录成功,token是", token) 74 | 75 | r = s.get( 76 | f"https://wproc.pku.edu.cn/site/login/cas-login?redirect_url=https://wproc.pku.edu.cn/v2/reserve/&_rand={time.time()}&token={token}" 77 | ) 78 | print("获取登录重定向响应:", r.status_code) 79 | 80 | save_cookies(s.cookies) 81 | await save_credentials(username, password) 82 | print("新的 cookies 已保存") 83 | print("Cookies:", s.cookies.get_dict()) 84 | return s 85 | 86 | async def logout(): 87 | await clear_credentials() 88 | if os.path.exists(COOKIES_FILE): 89 | os.remove(COOKIES_FILE) 90 | print("已清除用户凭据和 cookies") 91 | 92 | def check_login_status(session): 93 | try: 94 | r = session.get("https://wproc.pku.edu.cn/v2/reserve/", allow_redirects=False) 95 | return r.status_code == 200 96 | except: 97 | return False 98 | 99 | def fetch_data(session, date): 100 | r = session.get( 101 | f"https://wproc.pku.edu.cn/site/reservation/list-page?hall_id=1&time={date}&p=1&page_size=0" 102 | ) 103 | resources = json.loads(r.text)["d"]["list"] 104 | return resources 105 | 106 | # 使用示例 107 | session = login() 108 | date = "2024-09-21" 109 | resources = fetch_data(session, date) 110 | print(resources) -------------------------------------------------------------------------------- /macos/.gitignore: -------------------------------------------------------------------------------- 1 | # Flutter-related 2 | **/Flutter/ephemeral/ 3 | **/Pods/ 4 | 5 | # Xcode-related 6 | **/dgph 7 | **/xcuserdata/ 8 | -------------------------------------------------------------------------------- /macos/Flutter/Flutter-Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" 2 | #include "ephemeral/Flutter-Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /macos/Flutter/Flutter-Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" 2 | #include "ephemeral/Flutter-Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /macos/Flutter/GeneratedPluginRegistrant.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | import FlutterMacOS 6 | import Foundation 7 | 8 | import emoji_picker_flutter 9 | import geolocator_apple 10 | import package_info_plus 11 | import path_provider_foundation 12 | import screen_brightness_macos 13 | import share_plus 14 | import shared_preferences_foundation 15 | import url_launcher_macos 16 | 17 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { 18 | EmojiPickerFlutterPlugin.register(with: registry.registrar(forPlugin: "EmojiPickerFlutterPlugin")) 19 | GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin")) 20 | FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin")) 21 | PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) 22 | ScreenBrightnessMacosPlugin.register(with: registry.registrar(forPlugin: "ScreenBrightnessMacosPlugin")) 23 | SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin")) 24 | SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) 25 | UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) 26 | } 27 | -------------------------------------------------------------------------------- /macos/Podfile: -------------------------------------------------------------------------------- 1 | platform :osx, '10.14' 2 | 3 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency. 4 | ENV['COCOAPODS_DISABLE_STATS'] = 'true' 5 | 6 | project 'Runner', { 7 | 'Debug' => :debug, 8 | 'Profile' => :release, 9 | 'Release' => :release, 10 | } 11 | 12 | def flutter_root 13 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__) 14 | unless File.exist?(generated_xcode_build_settings_path) 15 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first" 16 | end 17 | 18 | File.foreach(generated_xcode_build_settings_path) do |line| 19 | matches = line.match(/FLUTTER_ROOT\=(.*)/) 20 | return matches[1].strip if matches 21 | end 22 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\"" 23 | end 24 | 25 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) 26 | 27 | flutter_macos_podfile_setup 28 | 29 | target 'Runner' do 30 | use_frameworks! 31 | use_modular_headers! 32 | 33 | flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__)) 34 | target 'RunnerTests' do 35 | inherit! :search_paths 36 | end 37 | end 38 | 39 | post_install do |installer| 40 | installer.pods_project.targets.each do |target| 41 | flutter_additional_macos_build_settings(target) 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /macos/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - emoji_picker_flutter (0.0.1): 3 | - FlutterMacOS 4 | - FlutterMacOS (1.0.0) 5 | - geolocator_apple (1.2.0): 6 | - FlutterMacOS 7 | - package_info_plus (0.0.1): 8 | - FlutterMacOS 9 | - path_provider_foundation (0.0.1): 10 | - Flutter 11 | - FlutterMacOS 12 | - screen_brightness_macos (0.1.0): 13 | - FlutterMacOS 14 | - share_plus (0.0.1): 15 | - FlutterMacOS 16 | - shared_preferences_foundation (0.0.1): 17 | - Flutter 18 | - FlutterMacOS 19 | - url_launcher_macos (0.0.1): 20 | - FlutterMacOS 21 | 22 | DEPENDENCIES: 23 | - emoji_picker_flutter (from `Flutter/ephemeral/.symlinks/plugins/emoji_picker_flutter/macos`) 24 | - FlutterMacOS (from `Flutter/ephemeral`) 25 | - geolocator_apple (from `Flutter/ephemeral/.symlinks/plugins/geolocator_apple/macos`) 26 | - package_info_plus (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos`) 27 | - path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`) 28 | - screen_brightness_macos (from `Flutter/ephemeral/.symlinks/plugins/screen_brightness_macos/macos`) 29 | - share_plus (from `Flutter/ephemeral/.symlinks/plugins/share_plus/macos`) 30 | - shared_preferences_foundation (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin`) 31 | - url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`) 32 | 33 | EXTERNAL SOURCES: 34 | emoji_picker_flutter: 35 | :path: Flutter/ephemeral/.symlinks/plugins/emoji_picker_flutter/macos 36 | FlutterMacOS: 37 | :path: Flutter/ephemeral 38 | geolocator_apple: 39 | :path: Flutter/ephemeral/.symlinks/plugins/geolocator_apple/macos 40 | package_info_plus: 41 | :path: Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos 42 | path_provider_foundation: 43 | :path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin 44 | screen_brightness_macos: 45 | :path: Flutter/ephemeral/.symlinks/plugins/screen_brightness_macos/macos 46 | share_plus: 47 | :path: Flutter/ephemeral/.symlinks/plugins/share_plus/macos 48 | shared_preferences_foundation: 49 | :path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin 50 | url_launcher_macos: 51 | :path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos 52 | 53 | SPEC CHECKSUMS: 54 | emoji_picker_flutter: 533634326b1c5de9a181ba14b9758e6dfe967a20 55 | FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24 56 | geolocator_apple: 72a78ae3f3e4ec0db62117bd93e34523f5011d58 57 | package_info_plus: 12f1c5c2cfe8727ca46cbd0b26677728972d9a5b 58 | path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46 59 | screen_brightness_macos: 2d6d3af2165592d9a55ffcd95b7550970e41ebda 60 | share_plus: 76dd39142738f7a68dd57b05093b5e8193f220f7 61 | shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78 62 | url_launcher_macos: c82c93949963e55b228a30115bd219499a6fe404 63 | 64 | PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367 65 | 66 | COCOAPODS: 1.15.2 67 | -------------------------------------------------------------------------------- /macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 43 | 49 | 50 | 51 | 52 | 53 | 63 | 65 | 71 | 72 | 73 | 74 | 80 | 82 | 88 | 89 | 90 | 91 | 93 | 94 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /macos/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /macos/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | @main 5 | class AppDelegate: FlutterAppDelegate { 6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { 7 | return true 8 | } 9 | 10 | override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { 11 | return true 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png -------------------------------------------------------------------------------- /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 = marchkov_helper 9 | 10 | // The application's bundle identifier 11 | PRODUCT_BUNDLE_IDENTIFIER = com.variantconst.marchkov_helper 12 | 13 | // The copyright displayed in application information 14 | PRODUCT_COPYRIGHT = Copyright © 2024 com.variantconst. All rights reserved. 15 | -------------------------------------------------------------------------------- /macos/Runner/Configs/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Debug.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /macos/Runner/Configs/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Release.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /macos/Runner/DebugProfile.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.cs.allow-jit 8 | 9 | com.apple.security.network.server 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /macos/Runner/MainFlutterWindow.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | class MainFlutterWindow: NSWindow { 5 | override func awakeFromNib() { 6 | let flutterViewController = FlutterViewController() 7 | let windowFrame = self.frame 8 | self.contentViewController = flutterViewController 9 | self.setFrame(windowFrame, display: true) 10 | 11 | RegisterGeneratedPlugins(registry: flutterViewController) 12 | 13 | super.awakeFromNib() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /macos/Runner/Release.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /macos/RunnerTests/RunnerTests.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | import XCTest 4 | 5 | class RunnerTests: XCTestCase { 6 | 7 | func testExample() { 8 | // If you add code to the Runner application, consider adding tests here. 9 | // See https://developer.apple.com/documentation/xctest for more information about using XCTest. 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: marchkov_helper 2 | description: "MarchKov Helper" 3 | # The following line prevents the package from being accidentally published to 4 | # pub.dev using `flutter pub publish`. This is preferred for private packages. 5 | publish_to: "none" # Remove this line if you wish to publish to pub.dev 6 | 7 | # The following defines the version and build number for your application. 8 | # A version number is three numbers separated by dots, like 1.2.43 9 | # followed by an optional build number separated by a +. 10 | # Both the version and the builder number may be overridden in flutter 11 | # build by specifying --build-name and --build-number, respectively. 12 | # In Android, build-name is used as versionName while build-number used as versionCode. 13 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning 14 | # In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. 15 | # Read more about iOS versioning at 16 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html 17 | # In Windows, build-name is used as the major, minor, and patch parts 18 | # of the product and file versions while build-number is used as the build suffix. 19 | version: 2.3.5+1 20 | 21 | environment: 22 | sdk: ">=2.17.0 <3.0.0" 23 | 24 | # Dependencies specify other packages that your package needs in order to work. 25 | # To automatically upgrade your package dependencies to the latest versions 26 | # consider running `flutter pub upgrade --major-versions`. Alternatively, 27 | # dependencies can be manually updated by changing the version numbers below to 28 | # the latest version available on pub.dev. To see which dependencies have newer 29 | # versions available, run `flutter pub outdated`. 30 | dependencies: 31 | flutter: 32 | sdk: flutter 33 | table_calendar: ^3.0.0 34 | cupertino_icons: ^1.0.8 35 | provider: ^6.0.0 36 | http: ^1.2.2 37 | permission_handler: ^11.3.1 38 | geolocator: ^13.0.1 39 | shared_preferences: ^2.2.0 40 | cookie_jar: ^4.0.8 41 | path_provider: ^2.1.2 42 | intl: ^0.19.0 # 添加这一行 43 | flutter_localizations: 44 | sdk: flutter 45 | material_design_icons_flutter: ^7.0.7296 46 | qr_flutter: ^4.1.0 47 | flutter_svg: ^2.0.10+1 48 | path: ^1.8.2 49 | # 修改 fl_chart 依赖,从 GitHub 获取最新代码 50 | fl_chart: ^0.69.0 51 | url_launcher: ^6.1.5 # 新增 52 | package_info_plus: ^8.0.2 # 用于获取应用程序信息 53 | emoji_picker_flutter: ^3.1.0 54 | crypto: ^3.0.3 55 | screen_brightness: ^0.2.2 56 | screenshot: ^2.1.0+1 57 | share_plus: ^7.2.1 58 | 59 | dev_dependencies: 60 | flutter_test: 61 | sdk: flutter 62 | mockito: ^5.0.0 63 | build_runner: ^2.1.0 # 添加这行 64 | flutter_lints: ^4.0.0 65 | flutter_launcher_icons: ^0.13.1 66 | 67 | flutter_launcher_icons: 68 | android: true 69 | ios: true 70 | image_path: "assets/icon/app_icon.png" 71 | remove_alpha_ios: true # 移除 iOS 图标的 alpha 通道 72 | ios_content_mode: scaleAspectFit # 设置 iOS 图标的内容模式 73 | 74 | # For information on the generic Dart part of this file, see the 75 | # following page: https://dart.dev/tools/pub/pubspec 76 | 77 | # The following section is specific to Flutter packages. 78 | flutter: 79 | # The following line ensures that the Material Icons font is 80 | # included with your application, so that you can use the icons in 81 | # the material Icons class. 82 | uses-material-design: true 83 | 84 | # To add assets to your application, add an assets section, like this: 85 | # assets: 86 | # - images/a_dot_burr.jpeg 87 | # - images/a_dot_ham.jpeg 88 | 89 | # An image asset can refer to one or more resolution-specific "variants", see 90 | # https://flutter.dev/to/resolution-aware-images 91 | 92 | # For details regarding adding assets from package dependencies, see 93 | # https://flutter.dev/to/asset-from-package 94 | 95 | # To add custom fonts to your application, add a fonts section here, 96 | # in this "flutter" section. Each entry in this list should have a 97 | # "family" key with the font family name, and a "fonts" key with a 98 | # list giving the asset and other descriptors for the font. For 99 | # example: 100 | # fonts: 101 | # - family: Schyler 102 | # fonts: 103 | # - asset: fonts/Schyler-Regular.ttf 104 | # - asset: fonts/Schyler-Italic.ttf 105 | # style: italic 106 | # - family: Trajan Pro 107 | # fonts: 108 | # - asset: fonts/TrajanPro.ttf 109 | # - asset: fonts/TrajanPro_Bold.ttf 110 | # weight: 700 111 | # 112 | # For details regarding fonts from package dependencies, 113 | # see https://flutter.dev/to/font-from-package 114 | 115 | # 注释掉或删除以下字体配置 116 | # fonts: 117 | # - family: Work Sans 118 | # fonts: 119 | # - asset: fonts/WorkSans-Regular.ttf 120 | # - asset: fonts/WorkSans-Medium.ttf 121 | # weight: 500 122 | # - asset: fonts/WorkSans-Bold.ttf 123 | # weight: 700 124 | # - asset: fonts/WorkSans-Black.ttf 125 | # weight: 900 126 | # - family: Noto Sans 127 | # fonts: 128 | # - asset: fonts/NotoSans-Regular.ttf 129 | # - asset: fonts/NotoSans-Medium.ttf 130 | # weight: 500 131 | # - asset: fonts/NotoSans-Bold.ttf 132 | # weight: 700 133 | # - asset: fonts/NotoSans-Black.ttf 134 | # weight: 900 135 | 136 | generate: true 137 | 138 | assets: 139 | - assets/light_mode.svg 140 | - assets/dark_mode.svg 141 | - assets/auto_mode.svg 142 | - assets/icon/app_icon.png 143 | -------------------------------------------------------------------------------- /test/widget_test.dart: -------------------------------------------------------------------------------- 1 | // This is a basic Flutter widget test. 2 | // 3 | // To perform an interaction with a widget in your test, use the WidgetTester 4 | // utility in the flutter_test package. For example, you can send tap and scroll 5 | // gestures. You can also use WidgetTester to find child widgets in the widget 6 | // tree, read text, and verify that the values of widget properties are correct. 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:flutter_test/flutter_test.dart'; 10 | 11 | import 'package:marchkov_helper/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 | -------------------------------------------------------------------------------- /web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/web/favicon.png -------------------------------------------------------------------------------- /web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/web/icons/Icon-192.png -------------------------------------------------------------------------------- /web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/web/icons/Icon-512.png -------------------------------------------------------------------------------- /web/icons/Icon-maskable-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/web/icons/Icon-maskable-192.png -------------------------------------------------------------------------------- /web/icons/Icon-maskable-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/web/icons/Icon-maskable-512.png -------------------------------------------------------------------------------- /web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | marchkov_helper 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "MCK Helper", 3 | "short_name": "MCK Helper", 4 | "start_url": ".", 5 | "display": "standalone", 6 | "background_color": "#0175C2", 7 | "theme_color": "#0175C2", 8 | "description": "A new Flutter project.", 9 | "orientation": "portrait-primary", 10 | "prefer_related_applications": false, 11 | "icons": [ 12 | { 13 | "src": "icons/Icon-192.png", 14 | "sizes": "192x192", 15 | "type": "image/png" 16 | }, 17 | { 18 | "src": "icons/Icon-512.png", 19 | "sizes": "512x512", 20 | "type": "image/png" 21 | }, 22 | { 23 | "src": "icons/Icon-maskable-192.png", 24 | "sizes": "192x192", 25 | "type": "image/png", 26 | "purpose": "maskable" 27 | }, 28 | { 29 | "src": "icons/Icon-maskable-512.png", 30 | "sizes": "512x512", 31 | "type": "image/png", 32 | "purpose": "maskable" 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project-level configuration. 2 | cmake_minimum_required(VERSION 3.14) 3 | project(marchkov_helper LANGUAGES CXX) 4 | 5 | # The name of the executable created for the application. Change this to change 6 | # the on-disk name of your application. 7 | set(BINARY_NAME "marchkov_helper") 8 | 9 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 10 | # versions of CMake. 11 | cmake_policy(VERSION 3.14...3.25) 12 | 13 | # Define build configuration option. 14 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 15 | if(IS_MULTICONFIG) 16 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" 17 | CACHE STRING "" FORCE) 18 | else() 19 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 20 | set(CMAKE_BUILD_TYPE "Debug" CACHE 21 | STRING "Flutter build mode" FORCE) 22 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 23 | "Debug" "Profile" "Release") 24 | endif() 25 | endif() 26 | # Define settings for the Profile build mode. 27 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") 28 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") 29 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") 30 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") 31 | 32 | # Use Unicode for all projects. 33 | add_definitions(-DUNICODE -D_UNICODE) 34 | 35 | # Compilation settings that should be applied to most targets. 36 | # 37 | # Be cautious about adding new options here, as plugins use this function by 38 | # default. In most cases, you should add new options to specific targets instead 39 | # of modifying this function. 40 | function(APPLY_STANDARD_SETTINGS TARGET) 41 | target_compile_features(${TARGET} PUBLIC cxx_std_17) 42 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") 43 | target_compile_options(${TARGET} PRIVATE /EHsc) 44 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") 45 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") 46 | endfunction() 47 | 48 | # Flutter library and tool build rules. 49 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 50 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 51 | 52 | # Application build; see runner/CMakeLists.txt. 53 | add_subdirectory("runner") 54 | 55 | 56 | # Generated plugin build rules, which manage building the plugins and adding 57 | # them to the application. 58 | include(flutter/generated_plugins.cmake) 59 | 60 | 61 | # === Installation === 62 | # Support files are copied into place next to the executable, so that it can 63 | # run in place. This is done instead of making a separate bundle (as on Linux) 64 | # so that building and running from within Visual Studio will work. 65 | set(BUILD_BUNDLE_DIR "$") 66 | # Make the "install" step default, as it's required to run. 67 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) 68 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 69 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 70 | endif() 71 | 72 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 73 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") 74 | 75 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 76 | COMPONENT Runtime) 77 | 78 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 79 | COMPONENT Runtime) 80 | 81 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 82 | COMPONENT Runtime) 83 | 84 | if(PLUGIN_BUNDLED_LIBRARIES) 85 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" 86 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 87 | COMPONENT Runtime) 88 | endif() 89 | 90 | # Copy the native assets provided by the build.dart from all packages. 91 | set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") 92 | install(DIRECTORY "${NATIVE_ASSETS_DIR}" 93 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 94 | COMPONENT Runtime) 95 | 96 | # Fully re-copy the assets directory on each build to avoid having stale files 97 | # from a previous install. 98 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 99 | install(CODE " 100 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 101 | " COMPONENT Runtime) 102 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 103 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 104 | 105 | # Install the AOT library on non-Debug builds only. 106 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 107 | CONFIGURATIONS Profile;Release 108 | COMPONENT Runtime) 109 | -------------------------------------------------------------------------------- /windows/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.14) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") 12 | 13 | # Set fallback configurations for older versions of the flutter tool. 14 | if (NOT DEFINED FLUTTER_TARGET_PLATFORM) 15 | set(FLUTTER_TARGET_PLATFORM "windows-x64") 16 | endif() 17 | 18 | # === Flutter Library === 19 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") 20 | 21 | # Published to parent scope for install step. 22 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 23 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 24 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 25 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) 26 | 27 | list(APPEND FLUTTER_LIBRARY_HEADERS 28 | "flutter_export.h" 29 | "flutter_windows.h" 30 | "flutter_messenger.h" 31 | "flutter_plugin_registrar.h" 32 | "flutter_texture_registrar.h" 33 | ) 34 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") 35 | add_library(flutter INTERFACE) 36 | target_include_directories(flutter INTERFACE 37 | "${EPHEMERAL_DIR}" 38 | ) 39 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") 40 | add_dependencies(flutter flutter_assemble) 41 | 42 | # === Wrapper === 43 | list(APPEND CPP_WRAPPER_SOURCES_CORE 44 | "core_implementations.cc" 45 | "standard_codec.cc" 46 | ) 47 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") 48 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN 49 | "plugin_registrar.cc" 50 | ) 51 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") 52 | list(APPEND CPP_WRAPPER_SOURCES_APP 53 | "flutter_engine.cc" 54 | "flutter_view_controller.cc" 55 | ) 56 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") 57 | 58 | # Wrapper sources needed for a plugin. 59 | add_library(flutter_wrapper_plugin STATIC 60 | ${CPP_WRAPPER_SOURCES_CORE} 61 | ${CPP_WRAPPER_SOURCES_PLUGIN} 62 | ) 63 | apply_standard_settings(flutter_wrapper_plugin) 64 | set_target_properties(flutter_wrapper_plugin PROPERTIES 65 | POSITION_INDEPENDENT_CODE ON) 66 | set_target_properties(flutter_wrapper_plugin PROPERTIES 67 | CXX_VISIBILITY_PRESET hidden) 68 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) 69 | target_include_directories(flutter_wrapper_plugin PUBLIC 70 | "${WRAPPER_ROOT}/include" 71 | ) 72 | add_dependencies(flutter_wrapper_plugin flutter_assemble) 73 | 74 | # Wrapper sources needed for the runner. 75 | add_library(flutter_wrapper_app STATIC 76 | ${CPP_WRAPPER_SOURCES_CORE} 77 | ${CPP_WRAPPER_SOURCES_APP} 78 | ) 79 | apply_standard_settings(flutter_wrapper_app) 80 | target_link_libraries(flutter_wrapper_app PUBLIC flutter) 81 | target_include_directories(flutter_wrapper_app PUBLIC 82 | "${WRAPPER_ROOT}/include" 83 | ) 84 | add_dependencies(flutter_wrapper_app flutter_assemble) 85 | 86 | # === Flutter tool backend === 87 | # _phony_ is a non-existent file to force this command to run every time, 88 | # since currently there's no way to get a full input/output list from the 89 | # flutter tool. 90 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") 91 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) 92 | add_custom_command( 93 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 94 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} 95 | ${CPP_WRAPPER_SOURCES_APP} 96 | ${PHONY_OUTPUT} 97 | COMMAND ${CMAKE_COMMAND} -E env 98 | ${FLUTTER_TOOL_ENVIRONMENT} 99 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" 100 | ${FLUTTER_TARGET_PLATFORM} $ 101 | VERBATIM 102 | ) 103 | add_custom_target(flutter_assemble DEPENDS 104 | "${FLUTTER_LIBRARY}" 105 | ${FLUTTER_LIBRARY_HEADERS} 106 | ${CPP_WRAPPER_SOURCES_CORE} 107 | ${CPP_WRAPPER_SOURCES_PLUGIN} 108 | ${CPP_WRAPPER_SOURCES_APP} 109 | ) 110 | -------------------------------------------------------------------------------- /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 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | void RegisterPlugins(flutter::PluginRegistry* registry) { 17 | EmojiPickerFlutterPluginCApiRegisterWithRegistrar( 18 | registry->GetRegistrarForPlugin("EmojiPickerFlutterPluginCApi")); 19 | GeolocatorWindowsRegisterWithRegistrar( 20 | registry->GetRegistrarForPlugin("GeolocatorWindows")); 21 | PermissionHandlerWindowsPluginRegisterWithRegistrar( 22 | registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin")); 23 | ScreenBrightnessWindowsPluginRegisterWithRegistrar( 24 | registry->GetRegistrarForPlugin("ScreenBrightnessWindowsPlugin")); 25 | SharePlusWindowsPluginCApiRegisterWithRegistrar( 26 | registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi")); 27 | UrlLauncherWindowsRegisterWithRegistrar( 28 | registry->GetRegistrarForPlugin("UrlLauncherWindows")); 29 | } 30 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /windows/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | emoji_picker_flutter 7 | geolocator_windows 8 | permission_handler_windows 9 | screen_brightness_windows 10 | share_plus 11 | url_launcher_windows 12 | ) 13 | 14 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 15 | ) 16 | 17 | set(PLUGIN_BUNDLED_LIBRARIES) 18 | 19 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 20 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 21 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 23 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 24 | endforeach(plugin) 25 | 26 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 27 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) 28 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 29 | endforeach(ffi_plugin) 30 | -------------------------------------------------------------------------------- /windows/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | project(runner LANGUAGES CXX) 3 | 4 | # Define the application target. To change its name, change BINARY_NAME in the 5 | # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer 6 | # work. 7 | # 8 | # Any new source files that you add to the application should be added here. 9 | add_executable(${BINARY_NAME} WIN32 10 | "flutter_window.cpp" 11 | "main.cpp" 12 | "utils.cpp" 13 | "win32_window.cpp" 14 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 15 | "Runner.rc" 16 | "runner.exe.manifest" 17 | ) 18 | 19 | # Apply the standard set of build settings. This can be removed for applications 20 | # that need different build settings. 21 | apply_standard_settings(${BINARY_NAME}) 22 | 23 | # Add preprocessor definitions for the build version. 24 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") 25 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") 26 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") 27 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") 28 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") 29 | 30 | # Disable Windows macros that collide with C++ standard library functions. 31 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 32 | 33 | # Add dependency libraries and include directories. Add any application-specific 34 | # dependencies here. 35 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 36 | target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") 37 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 38 | 39 | # Run the Flutter tool portions of the build. This must not be removed. 40 | add_dependencies(${BINARY_NAME} flutter_assemble) 41 | -------------------------------------------------------------------------------- /windows/runner/Runner.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #pragma code_page(65001) 4 | #include "resource.h" 5 | 6 | #define APSTUDIO_READONLY_SYMBOLS 7 | ///////////////////////////////////////////////////////////////////////////// 8 | // 9 | // Generated from the TEXTINCLUDE 2 resource. 10 | // 11 | #include "winres.h" 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | #undef APSTUDIO_READONLY_SYMBOLS 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // English (United States) resources 18 | 19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Icon 51 | // 52 | 53 | // Icon with lowest ID value placed first to ensure application icon 54 | // remains consistent on all systems. 55 | IDI_APP_ICON ICON "resources\\app_icon.ico" 56 | 57 | 58 | ///////////////////////////////////////////////////////////////////////////// 59 | // 60 | // Version 61 | // 62 | 63 | #if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD) 64 | #define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD 65 | #else 66 | #define VERSION_AS_NUMBER 1,0,0,0 67 | #endif 68 | 69 | #if defined(FLUTTER_VERSION) 70 | #define VERSION_AS_STRING FLUTTER_VERSION 71 | #else 72 | #define VERSION_AS_STRING "1.0.0" 73 | #endif 74 | 75 | VS_VERSION_INFO VERSIONINFO 76 | FILEVERSION VERSION_AS_NUMBER 77 | PRODUCTVERSION VERSION_AS_NUMBER 78 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 79 | #ifdef _DEBUG 80 | FILEFLAGS VS_FF_DEBUG 81 | #else 82 | FILEFLAGS 0x0L 83 | #endif 84 | FILEOS VOS__WINDOWS32 85 | FILETYPE VFT_APP 86 | FILESUBTYPE 0x0L 87 | BEGIN 88 | BLOCK "StringFileInfo" 89 | BEGIN 90 | BLOCK "040904e4" 91 | BEGIN 92 | VALUE "CompanyName", "com.variantconst" "\0" 93 | VALUE "FileDescription", "marchkov_helper" "\0" 94 | VALUE "FileVersion", VERSION_AS_STRING "\0" 95 | VALUE "InternalName", "marchkov_helper" "\0" 96 | VALUE "LegalCopyright", "Copyright (C) 2024 com.variantconst. All rights reserved." "\0" 97 | VALUE "OriginalFilename", "marchkov_helper.exe" "\0" 98 | VALUE "ProductName", "marchkov_helper" "\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 | -------------------------------------------------------------------------------- /windows/runner/flutter_window.cpp: -------------------------------------------------------------------------------- 1 | #include "flutter_window.h" 2 | 3 | #include 4 | 5 | #include "flutter/generated_plugin_registrant.h" 6 | 7 | FlutterWindow::FlutterWindow(const flutter::DartProject& project) 8 | : project_(project) {} 9 | 10 | FlutterWindow::~FlutterWindow() {} 11 | 12 | bool FlutterWindow::OnCreate() { 13 | if (!Win32Window::OnCreate()) { 14 | return false; 15 | } 16 | 17 | RECT frame = GetClientArea(); 18 | 19 | // The size here must match the window dimensions to avoid unnecessary surface 20 | // creation / destruction in the startup path. 21 | flutter_controller_ = std::make_unique( 22 | frame.right - frame.left, frame.bottom - frame.top, project_); 23 | // Ensure that basic setup of the controller was successful. 24 | if (!flutter_controller_->engine() || !flutter_controller_->view()) { 25 | return false; 26 | } 27 | RegisterPlugins(flutter_controller_->engine()); 28 | SetChildContent(flutter_controller_->view()->GetNativeWindow()); 29 | 30 | flutter_controller_->engine()->SetNextFrameCallback([&]() { 31 | this->Show(); 32 | }); 33 | 34 | // Flutter can complete the first frame before the "show window" callback is 35 | // registered. The following call ensures a frame is pending to ensure the 36 | // window is shown. It is a no-op if the first frame hasn't completed yet. 37 | flutter_controller_->ForceRedraw(); 38 | 39 | return true; 40 | } 41 | 42 | void FlutterWindow::OnDestroy() { 43 | if (flutter_controller_) { 44 | flutter_controller_ = nullptr; 45 | } 46 | 47 | Win32Window::OnDestroy(); 48 | } 49 | 50 | LRESULT 51 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message, 52 | WPARAM const wparam, 53 | LPARAM const lparam) noexcept { 54 | // Give Flutter, including plugins, an opportunity to handle window messages. 55 | if (flutter_controller_) { 56 | std::optional result = 57 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, 58 | lparam); 59 | if (result) { 60 | return *result; 61 | } 62 | } 63 | 64 | switch (message) { 65 | case WM_FONTCHANGE: 66 | flutter_controller_->engine()->ReloadSystemFonts(); 67 | break; 68 | } 69 | 70 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam); 71 | } 72 | -------------------------------------------------------------------------------- /windows/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_FLUTTER_WINDOW_H_ 2 | #define RUNNER_FLUTTER_WINDOW_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "win32_window.h" 10 | 11 | // A window that does nothing but host a Flutter view. 12 | class FlutterWindow : public Win32Window { 13 | public: 14 | // Creates a new FlutterWindow hosting a Flutter view running |project|. 15 | explicit FlutterWindow(const flutter::DartProject& project); 16 | virtual ~FlutterWindow(); 17 | 18 | protected: 19 | // Win32Window: 20 | bool OnCreate() override; 21 | void OnDestroy() override; 22 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, 23 | LPARAM const lparam) noexcept override; 24 | 25 | private: 26 | // The project to run. 27 | flutter::DartProject project_; 28 | 29 | // The Flutter instance hosted by this window. 30 | std::unique_ptr flutter_controller_; 31 | }; 32 | 33 | #endif // RUNNER_FLUTTER_WINDOW_H_ 34 | -------------------------------------------------------------------------------- /windows/runner/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "flutter_window.h" 6 | #include "utils.h" 7 | 8 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, 9 | _In_ wchar_t *command_line, _In_ int show_command) { 10 | // Attach to console when present (e.g., 'flutter run') or create a 11 | // new console when running with a debugger. 12 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { 13 | CreateAndAttachConsole(); 14 | } 15 | 16 | // Initialize COM, so that it is available for use in the library and/or 17 | // plugins. 18 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); 19 | 20 | flutter::DartProject project(L"data"); 21 | 22 | std::vector command_line_arguments = 23 | GetCommandLineArguments(); 24 | 25 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 26 | 27 | FlutterWindow window(project); 28 | Win32Window::Point origin(10, 10); 29 | Win32Window::Size size(1280, 720); 30 | if (!window.Create(L"marchkov_helper", origin, size)) { 31 | return EXIT_FAILURE; 32 | } 33 | window.SetQuitOnClose(true); 34 | 35 | ::MSG msg; 36 | while (::GetMessage(&msg, nullptr, 0, 0)) { 37 | ::TranslateMessage(&msg); 38 | ::DispatchMessage(&msg); 39 | } 40 | 41 | ::CoUninitialize(); 42 | return EXIT_SUCCESS; 43 | } 44 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /windows/runner/resources/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/windows/runner/resources/app_icon.ico -------------------------------------------------------------------------------- /windows/runner/runner.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PerMonitorV2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /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 | unsigned int target_length = ::WideCharToMultiByte( 49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 50 | -1, nullptr, 0, nullptr, nullptr) 51 | -1; // remove the trailing null character 52 | int input_length = (int)wcslen(utf16_string); 53 | std::string utf8_string; 54 | if (target_length == 0 || target_length > utf8_string.max_size()) { 55 | return utf8_string; 56 | } 57 | utf8_string.resize(target_length); 58 | int converted_length = ::WideCharToMultiByte( 59 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 60 | input_length, utf8_string.data(), target_length, nullptr, nullptr); 61 | if (converted_length == 0) { 62 | return std::string(); 63 | } 64 | return utf8_string; 65 | } 66 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 a win32 window with |title| that is positioned and sized 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 this function will scale the inputted width and height as 35 | // as appropriate for the default monitor. The window is invisible until 36 | // |Show| is called. Returns true if the window was created successfully. 37 | bool Create(const std::wstring& title, const Point& origin, const Size& size); 38 | 39 | // Show the current window. Returns true if the window was successfully shown. 40 | bool Show(); 41 | 42 | // Release OS resources associated with window. 43 | void Destroy(); 44 | 45 | // Inserts |content| into the window tree. 46 | void SetChildContent(HWND content); 47 | 48 | // Returns the backing Window handle to enable clients to set icon and other 49 | // window properties. Returns nullptr if the window has been destroyed. 50 | HWND GetHandle(); 51 | 52 | // If true, closing this window will quit the application. 53 | void SetQuitOnClose(bool quit_on_close); 54 | 55 | // Return a RECT representing the bounds of the current client area. 56 | RECT GetClientArea(); 57 | 58 | protected: 59 | // Processes and route salient window messages for mouse handling, 60 | // size change and DPI. Delegates handling of these to member overloads that 61 | // inheriting classes can handle. 62 | virtual LRESULT MessageHandler(HWND window, 63 | UINT const message, 64 | WPARAM const wparam, 65 | LPARAM const lparam) noexcept; 66 | 67 | // Called when CreateAndShow is called, allowing subclass window-related 68 | // setup. Subclasses should return false if setup fails. 69 | virtual bool OnCreate(); 70 | 71 | // Called when Destroy is called. 72 | virtual void OnDestroy(); 73 | 74 | private: 75 | friend class WindowClassRegistrar; 76 | 77 | // OS callback called by message pump. Handles the WM_NCCREATE message which 78 | // is passed when the non-client area is being created and enables automatic 79 | // non-client DPI scaling so that the non-client area automatically 80 | // responds to changes in DPI. All other messages are handled by 81 | // MessageHandler. 82 | static LRESULT CALLBACK WndProc(HWND const window, 83 | UINT const message, 84 | WPARAM const wparam, 85 | LPARAM const lparam) noexcept; 86 | 87 | // Retrieves a class instance pointer for |window| 88 | static Win32Window* GetThisFromHandle(HWND const window) noexcept; 89 | 90 | // Update the window frame's theme to match the system theme. 91 | static void UpdateTheme(HWND const window); 92 | 93 | bool quit_on_close_ = false; 94 | 95 | // window handle for top level window. 96 | HWND window_handle_ = nullptr; 97 | 98 | // window handle for hosted content. 99 | HWND child_content_ = nullptr; 100 | }; 101 | 102 | #endif // RUNNER_WIN32_WINDOW_H_ 103 | --------------------------------------------------------------------------------