├── .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 |
16 |
17 | ### 夜间
18 |
19 |
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 |
4 |
--------------------------------------------------------------------------------
/assets/icon/app_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VariantConst/Marchkov-Helper/7a064078d899397ffa4fda4083df1fde5f42db63/assets/icon/app_icon.png
--------------------------------------------------------------------------------
/assets/light_mode.svg:
--------------------------------------------------------------------------------
1 |
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