├── README.md ├── analysis_options.yaml ├── android ├── .gitignore ├── app │ ├── build.gradle │ └── src │ │ ├── debug │ │ └── AndroidManifest.xml │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── kotlin │ │ │ └── com │ │ │ │ └── xiejiapei │ │ │ │ └── jdshop_flutter │ │ │ │ └── jdshop_flutter │ │ │ │ └── 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 ├── jdshop_flutter_android.iml └── settings.gradle ├── images ├── 2.0x │ ├── login.png │ ├── user.png │ └── user_bg.jpg ├── 3.0x │ ├── login.png │ ├── user.png │ └── user_bg.jpg ├── login.png ├── user.png └── user_bg.jpg ├── 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 ├── jdshop_flutter.iml ├── lib ├── address │ ├── AddressAdd.dart │ ├── AddressEdit.dart │ └── AddressList.dart ├── config │ └── Config.dart ├── main.dart ├── model │ ├── CateModel.dart │ ├── FocusModel.dart │ ├── OrderModel.dart │ ├── ProductContentMainModel.dart │ └── ProductList.dart ├── pages │ ├── cart │ │ ├── cartItem.dart │ │ └── cartNum.dart │ ├── login │ │ ├── Login.dart │ │ ├── RegisterFirst.dart │ │ ├── RegisterSecond.dart │ │ └── RegisterThird.dart │ ├── productContent │ │ ├── CheckOut.dart │ │ ├── Order.dart │ │ ├── OrderInfo.dart │ │ ├── Pay.dart │ │ ├── ProductContent.dart │ │ ├── ProductContentCartNum.dart │ │ ├── ProductContentDetail.dart │ │ ├── ProductContentMain.dart │ │ └── ProductContentRate.dart │ └── tabs │ │ ├── Cart.dart │ │ ├── Category.dart │ │ ├── Home.dart │ │ ├── ProductList.dart │ │ ├── Search.dart │ │ ├── Tabs.dart │ │ └── User.dart ├── provider │ ├── CartProvider.dart │ ├── CheckOutProvider.dart │ └── Counter.dart ├── routers │ └── router.dart ├── services │ ├── CartService.dart │ ├── CheckOutServices.dart │ ├── Counter.dart │ ├── EventsBus.dart │ ├── ScreenAdaper.dart │ ├── SearchServices.dart │ ├── SignServices.dart │ ├── Storage.dart │ └── UserServices.dart └── widget │ ├── JDButton.dart │ ├── JDText.dart │ └── LoadingWidget.dart ├── linux ├── .gitignore ├── CMakeLists.txt ├── flutter │ ├── CMakeLists.txt │ ├── generated_plugin_registrant.cc │ ├── generated_plugin_registrant.h │ └── generated_plugins.cmake ├── main.cc ├── my_application.cc └── my_application.h ├── macos ├── .gitignore ├── Flutter │ ├── Flutter-Debug.xcconfig │ ├── Flutter-Release.xcconfig │ └── GeneratedPluginRegistrant.swift ├── Podfile ├── Runner.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── xcshareddata │ │ └── xcschemes │ │ └── Runner.xcscheme ├── Runner.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── Runner │ ├── AppDelegate.swift │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── app_icon_1024.png │ │ ├── app_icon_128.png │ │ ├── app_icon_16.png │ │ ├── app_icon_256.png │ │ ├── app_icon_32.png │ │ ├── app_icon_512.png │ │ └── app_icon_64.png │ ├── Base.lproj │ └── MainMenu.xib │ ├── Configs │ ├── AppInfo.xcconfig │ ├── Debug.xcconfig │ ├── Release.xcconfig │ └── Warnings.xcconfig │ ├── DebugProfile.entitlements │ ├── Info.plist │ ├── MainFlutterWindow.swift │ └── Release.entitlements ├── pubspec.lock ├── pubspec.yaml ├── test └── widget_test.dart ├── web ├── favicon.png ├── icons │ ├── Icon-192.png │ ├── Icon-512.png │ ├── Icon-maskable-192.png │ └── Icon-maskable-512.png ├── index.html └── manifest.json └── windows ├── .gitignore ├── CMakeLists.txt ├── flutter ├── CMakeLists.txt ├── generated_plugin_registrant.cc ├── generated_plugin_registrant.h └── generated_plugins.cmake └── runner ├── CMakeLists.txt ├── Runner.rc ├── flutter_window.cpp ├── flutter_window.h ├── main.cpp ├── resource.h ├── resources └── app_icon.ico ├── runner.exe.manifest ├── utils.cpp ├── utils.h ├── win32_window.cpp └── win32_window.h /README.md: -------------------------------------------------------------------------------- 1 | ### 项目的开发指南 2 | - [Flutter:入门](https://www.jianshu.com/p/fb74b7beec43) 3 | 4 | - [Flutter:进阶](https://www.jianshu.com/p/1d0a51c71597) 5 | 6 | - [Flutter:仿京东商城APP的完整开发指南(一)](https://www.jianshu.com/p/b594f3c83aee) 7 | 8 | - [Flutter:仿京东商城APP的完整开发指南(二)](https://www.jianshu.com/p/86df79b2e74e) 9 | 10 | - [Flutter:仿京东商城APP的完整开发指南(三)](https://www.jianshu.com/p/d729be843578) 11 | 12 | 嘻嘻 13 | 14 | ### 运行效果图 15 | ![列表.png](https://upload-images.jianshu.io/upload_images/9570900-e3fdf46374bf5507.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 16 | 17 | ![分类.png](https://upload-images.jianshu.io/upload_images/9570900-33530db1d40dd9e1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 18 | 19 | ![地址列表.png](https://upload-images.jianshu.io/upload_images/9570900-6ab8ff4e22581190.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 20 | 21 | ![属性.png](https://upload-images.jianshu.io/upload_images/9570900-1e9e0f338780aa35.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 22 | 23 | ![新增地址.png](https://upload-images.jianshu.io/upload_images/9570900-c4874d77f198e3cc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 24 | 25 | ![用户中心.png](https://upload-images.jianshu.io/upload_images/9570900-df2d9cf7462523da.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 26 | 27 | ![订单.png](https://upload-images.jianshu.io/upload_images/9570900-6bb37fff5cc79bbc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 28 | 29 | ![详情.png](https://upload-images.jianshu.io/upload_images/9570900-bb5048e5d5dae69b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 30 | 31 | ![购物车.png](https://upload-images.jianshu.io/upload_images/9570900-fd9344104c746ac1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 32 | 33 | ![首页.png](https://upload-images.jianshu.io/upload_images/9570900-3982bf52e5870b38.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 34 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the analyzer, which statically analyzes Dart code to 2 | # check for errors, warnings, and lints. 3 | # 4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled 5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be 6 | # invoked from the command line by running `flutter analyze`. 7 | 8 | # The following line activates a set of recommended lints for Flutter apps, 9 | # packages, and plugins designed to encourage good coding practices. 10 | include: package:flutter_lints/flutter.yaml 11 | 12 | linter: 13 | # The lint rules applied to this project can be customized in the 14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml` 15 | # included above or to enable additional rules. A list of all available lints 16 | # and their documentation is published at 17 | # https://dart-lang.github.io/linter/lints/index.html. 18 | # 19 | # Instead of disabling a lint rule for the entire project in the 20 | # section below, it can also be suppressed for a single line of code 21 | # or a specific dart file by using the `// ignore: name_of_lint` and 22 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file 23 | # producing the lint. 24 | rules: 25 | # avoid_print: false # Uncomment to disable the `avoid_print` rule 26 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule 27 | 28 | # Additional information about this file can be found at 29 | # https://dart.dev/guides/language/analysis-options 30 | -------------------------------------------------------------------------------- /android/.gitignore: -------------------------------------------------------------------------------- 1 | gradle-wrapper.jar 2 | /.gradle 3 | /captures/ 4 | /gradlew 5 | /gradlew.bat 6 | /local.properties 7 | GeneratedPluginRegistrant.java 8 | 9 | # Remember to never publicly share your keystore. 10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app 11 | key.properties 12 | **/*.keystore 13 | **/*.jks 14 | -------------------------------------------------------------------------------- /android/app/build.gradle: -------------------------------------------------------------------------------- 1 | def localProperties = new Properties() 2 | def localPropertiesFile = rootProject.file('local.properties') 3 | if (localPropertiesFile.exists()) { 4 | localPropertiesFile.withReader('UTF-8') { reader -> 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 15 | if (flutterVersionCode == null) { 16 | flutterVersionCode = '1' 17 | } 18 | 19 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 20 | if (flutterVersionName == null) { 21 | flutterVersionName = '1.0' 22 | } 23 | 24 | apply plugin: 'com.android.application' 25 | apply plugin: 'kotlin-android' 26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 27 | 28 | android { 29 | compileSdkVersion flutter.compileSdkVersion 30 | ndkVersion flutter.ndkVersion 31 | 32 | compileOptions { 33 | sourceCompatibility JavaVersion.VERSION_1_8 34 | targetCompatibility JavaVersion.VERSION_1_8 35 | } 36 | 37 | kotlinOptions { 38 | jvmTarget = '1.8' 39 | } 40 | 41 | sourceSets { 42 | main.java.srcDirs += 'src/main/kotlin' 43 | } 44 | 45 | defaultConfig { 46 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 47 | applicationId "com.xiejiapei.jdshop_flutter.jdshop_flutter" 48 | // You can update the following values to match your application needs. 49 | // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. 50 | minSdkVersion flutter.minSdkVersion 51 | targetSdkVersion flutter.targetSdkVersion 52 | versionCode flutterVersionCode.toInteger() 53 | versionName flutterVersionName 54 | } 55 | 56 | buildTypes { 57 | release { 58 | // TODO: Add your own signing config for the release build. 59 | // Signing with the debug keys for now, so `flutter run --release` works. 60 | signingConfig signingConfigs.debug 61 | } 62 | } 63 | } 64 | 65 | flutter { 66 | source '../..' 67 | } 68 | 69 | dependencies { 70 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 71 | } 72 | -------------------------------------------------------------------------------- /android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 15 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 30 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /android/app/src/main/kotlin/com/xiejiapei/jdshop_flutter/jdshop_flutter/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.xiejiapei.jdshop_flutter.jdshop_flutter 2 | 3 | import io.flutter.embedding.android.FlutterActivity 4 | 5 | class MainActivity: FlutterActivity() { 6 | } 7 | -------------------------------------------------------------------------------- /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/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/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 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.7.10' 3 | repositories { 4 | google() 5 | mavenCentral() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:7.2.0' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | mavenCentral() 18 | } 19 | } 20 | 21 | rootProject.buildDir = '../build' 22 | subprojects { 23 | project.buildDir = "${rootProject.buildDir}/${project.name}" 24 | } 25 | subprojects { 26 | project.evaluationDependsOn(':app') 27 | } 28 | 29 | task clean(type: Delete) { 30 | delete rootProject.buildDir 31 | } 32 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 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-7.5-all.zip 6 | -------------------------------------------------------------------------------- /android/jdshop_flutter_android.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | 3 | def localPropertiesFile = new File(rootProject.projectDir, "local.properties") 4 | def properties = new Properties() 5 | 6 | assert localPropertiesFile.exists() 7 | localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } 8 | 9 | def flutterSdkPath = properties.getProperty("flutter.sdk") 10 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties" 11 | apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" 12 | -------------------------------------------------------------------------------- /images/2.0x/login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/images/2.0x/login.png -------------------------------------------------------------------------------- /images/2.0x/user.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/images/2.0x/user.png -------------------------------------------------------------------------------- /images/2.0x/user_bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/images/2.0x/user_bg.jpg -------------------------------------------------------------------------------- /images/3.0x/login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/images/3.0x/login.png -------------------------------------------------------------------------------- /images/3.0x/user.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/images/3.0x/user.png -------------------------------------------------------------------------------- /images/3.0x/user_bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/images/3.0x/user_bg.jpg -------------------------------------------------------------------------------- /images/login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/images/login.png -------------------------------------------------------------------------------- /images/user.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/images/user.png -------------------------------------------------------------------------------- /images/user_bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/images/user_bg.jpg -------------------------------------------------------------------------------- /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 | 11.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, '11.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 | end 36 | 37 | post_install do |installer| 38 | installer.pods_project.targets.each do |target| 39 | flutter_additional_ios_build_settings(target) 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /ios/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - Flutter (1.0.0) 3 | - flutter_inappwebview (0.0.1): 4 | - Flutter 5 | - fluttertoast (0.0.2): 6 | - Flutter 7 | - Toast 8 | - shared_preferences (0.0.1): 9 | - Flutter 10 | - Toast (4.0.0) 11 | 12 | DEPENDENCIES: 13 | - Flutter (from `Flutter`) 14 | - flutter_inappwebview (from `.symlinks/plugins/flutter_inappwebview/ios`) 15 | - fluttertoast (from `.symlinks/plugins/fluttertoast/ios`) 16 | - shared_preferences (from `.symlinks/plugins/shared_preferences/ios`) 17 | 18 | SPEC REPOS: 19 | trunk: 20 | - Toast 21 | 22 | EXTERNAL SOURCES: 23 | Flutter: 24 | :path: Flutter 25 | flutter_inappwebview: 26 | :path: ".symlinks/plugins/flutter_inappwebview/ios" 27 | fluttertoast: 28 | :path: ".symlinks/plugins/fluttertoast/ios" 29 | shared_preferences: 30 | :path: ".symlinks/plugins/shared_preferences/ios" 31 | 32 | SPEC CHECKSUMS: 33 | Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 34 | flutter_inappwebview: 239198123453705522ba6c4f78d3d7468215f248 35 | fluttertoast: eb263d302cc92e04176c053d2385237e9f43fad0 36 | shared_preferences: af6bfa751691cdc24be3045c43ec037377ada40d 37 | Toast: 91b396c56ee72a5790816f40d3a94dd357abc196 38 | 39 | PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3 40 | 41 | COCOAPODS: 1.11.3 42 | -------------------------------------------------------------------------------- /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 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 69 | 71 | 77 | 78 | 79 | 80 | 82 | 83 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /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 UIKit 2 | import Flutter 3 | 4 | @UIApplicationMain 5 | @objc class AppDelegate: FlutterAppDelegate { 6 | override func application( 7 | _ application: UIApplication, 8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? 9 | ) -> Bool { 10 | GeneratedPluginRegistrant.register(with: self) 11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "Icon-App-20x20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "Icon-App-20x20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "Icon-App-29x29@1x.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "Icon-App-29x29@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "29x29", 29 | "idiom" : "iphone", 30 | "filename" : "Icon-App-29x29@3x.png", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "Icon-App-40x40@2x.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "40x40", 41 | "idiom" : "iphone", 42 | "filename" : "Icon-App-40x40@3x.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "Icon-App-60x60@2x.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "60x60", 53 | "idiom" : "iphone", 54 | "filename" : "Icon-App-60x60@3x.png", 55 | "scale" : "3x" 56 | }, 57 | { 58 | "size" : "20x20", 59 | "idiom" : "ipad", 60 | "filename" : "Icon-App-20x20@1x.png", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "size" : "20x20", 65 | "idiom" : "ipad", 66 | "filename" : "Icon-App-20x20@2x.png", 67 | "scale" : "2x" 68 | }, 69 | { 70 | "size" : "29x29", 71 | "idiom" : "ipad", 72 | "filename" : "Icon-App-29x29@1x.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "29x29", 77 | "idiom" : "ipad", 78 | "filename" : "Icon-App-29x29@2x.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "40x40", 83 | "idiom" : "ipad", 84 | "filename" : "Icon-App-40x40@1x.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "40x40", 89 | "idiom" : "ipad", 90 | "filename" : "Icon-App-40x40@2x.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "76x76", 95 | "idiom" : "ipad", 96 | "filename" : "Icon-App-76x76@1x.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "76x76", 101 | "idiom" : "ipad", 102 | "filename" : "Icon-App-76x76@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "size" : "83.5x83.5", 107 | "idiom" : "ipad", 108 | "filename" : "Icon-App-83.5x83.5@2x.png", 109 | "scale" : "2x" 110 | }, 111 | { 112 | "size" : "1024x1024", 113 | "idiom" : "ios-marketing", 114 | "filename" : "Icon-App-1024x1024@1x.png", 115 | "scale" : "1x" 116 | } 117 | ], 118 | "info" : { 119 | "version" : 1, 120 | "author" : "xcode" 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/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/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/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/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/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/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/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/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/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/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/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/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/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/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/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/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/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/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/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/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/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/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/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/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/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/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/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/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/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/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/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 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDisplayName 8 | Jdshop Flutter 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | jdshop_flutter 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | $(FLUTTER_BUILD_NUMBER) 25 | LSRequiresIPhoneOS 26 | 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | UIViewControllerBasedStatusBarAppearance 45 | 46 | CADisableMinimumFrameDurationOnPhone 47 | 48 | UIApplicationSupportsIndirectInputEvents 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /jdshop_flutter.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /lib/address/AddressAdd.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:dio/dio.dart'; 4 | import 'package:flutter/material.dart'; 5 | import 'package:jdshop_app/config/Config.dart'; 6 | import 'package:jdshop_app/services/EventsBus.dart'; 7 | import 'package:jdshop_app/services/ScreenAdaper.dart'; 8 | import 'package:jdshop_app/services/SignServices.dart'; 9 | import 'package:jdshop_app/services/UserServices.dart'; 10 | import 'package:jdshop_app/widget/JDButton.dart'; 11 | import 'package:jdshop_app/widget/JDText.dart'; 12 | import 'package:city_pickers/city_pickers.dart'; 13 | 14 | class AddressAddPage extends StatefulWidget { 15 | AddressAddPage({Key key}) : super(key: key); 16 | @override 17 | _AddressAddPageState createState() => _AddressAddPageState(); 18 | } 19 | 20 | class _AddressAddPageState extends State { 21 | String area=''; 22 | String name=''; 23 | String phone=''; 24 | String address=''; 25 | 26 | // 页面销毁广播 27 | @override 28 | void dispose() { 29 | // TODO: implement dispose 30 | super.dispose(); 31 | eventBus.fire(new AddressEvent("增加地址成功")); 32 | eventBus.fire(new DefaultAddressEvent('改收货地址成功...')); 33 | } 34 | 35 | @override 36 | Widget build(BuildContext context) { 37 | ScreenAdaper.init(context); 38 | 39 | return Scaffold( 40 | appBar: AppBar( 41 | title: Text("增加收货地址"), 42 | ), 43 | body: Container( 44 | padding: EdgeInsets.all(10), 45 | child: ListView( 46 | children: [ 47 | 48 | SizedBox(height: 20), 49 | JdText( 50 | text: "收货人姓名", 51 | onChanged: (value) { 52 | this.name = value; 53 | }, 54 | ), 55 | SizedBox(height: 10), 56 | JdText( 57 | text: "收货人电话", 58 | onChanged: (value) { 59 | this.phone = value; 60 | }, 61 | ), 62 | SizedBox(height: 10), 63 | 64 | // 弹出省市区 65 | Container( 66 | padding: EdgeInsets.only(left: 5), 67 | height: ScreenAdaper.height(68), 68 | decoration: BoxDecoration( 69 | border: Border( 70 | bottom: BorderSide(width: 1, color: Colors.black12))), 71 | 72 | child: InkWell( 73 | 74 | child: Row( 75 | children: [ 76 | Icon(Icons.add_location), 77 | this.area.length > 0 ? Text('${this.area}', style: TextStyle(color: Colors.black54)): Text('省/市/区', style: TextStyle(color: Colors.black54)) 78 | ], 79 | ), 80 | 81 | onTap: () async{ 82 | Result result = await CityPickers.showCityPicker( 83 | context: context, 84 | cancelWidget: Text("取消", style: TextStyle(color: Colors.blue)), 85 | confirmWidget: Text("确定", style: TextStyle(color: Colors.blue)) 86 | ); 87 | setState(() { 88 | this.area = "${result.provinceName}/${result.cityName}/${result.areaName}"; 89 | }); 90 | }, 91 | ), 92 | ), 93 | 94 | SizedBox(height: 10), 95 | JdText( 96 | text: "详细地址", 97 | maxLines: 4, 98 | height: 200, 99 | onChanged: (value) { 100 | this.address = "${this.area} ${value}"; 101 | }, 102 | ), 103 | SizedBox(height: 40), 104 | JDButton(buttonTitle: "增加", buttonColor: Colors.red, tapEvent: () async { 105 | // 生成签名 106 | List userinfo = await UserServices.getUserInfo(); 107 | var tempJson = { 108 | "uid":userinfo[0]["_id"], 109 | "name":this.name, 110 | "phone":this.phone, 111 | "address":this.address, 112 | "salt":userinfo[0]["salt"] 113 | }; 114 | var sign=SignServices.getSign(tempJson); 115 | // 网络请求 116 | var api = '${Config.domain}api/addAddress'; 117 | var result = await Dio().post(api,data:{ 118 | "uid":userinfo[0]["_id"], 119 | "name":this.name, 120 | "phone":this.phone, 121 | "address":this.address, 122 | "sign":sign 123 | }); 124 | Navigator.pop(context); 125 | }) 126 | ], 127 | ), 128 | ) 129 | ); 130 | } 131 | } -------------------------------------------------------------------------------- /lib/address/AddressEdit.dart: -------------------------------------------------------------------------------- 1 | import 'package:city_pickers/city_pickers.dart'; 2 | import 'package:dio/dio.dart'; 3 | import 'package:flutter/material.dart'; 4 | import 'package:jdshop_app/config/Config.dart'; 5 | import 'package:jdshop_app/services/EventsBus.dart'; 6 | import 'package:jdshop_app/services/ScreenAdaper.dart'; 7 | import 'package:jdshop_app/services/SignServices.dart'; 8 | import 'package:jdshop_app/services/UserServices.dart'; 9 | import 'package:jdshop_app/widget/JDButton.dart'; 10 | import 'package:jdshop_app/widget/JDText.dart'; 11 | 12 | class AddressEditPage extends StatefulWidget { 13 | Map arguments; 14 | AddressEditPage({Key key,this.arguments}) : super(key: key); 15 | 16 | _AddressEditPageState createState() => _AddressEditPageState(); 17 | } 18 | 19 | class _AddressEditPageState extends State { 20 | String area=''; 21 | // 初始化的时候给编辑页面赋值 22 | TextEditingController nameController=new TextEditingController(); 23 | TextEditingController phoneController=new TextEditingController(); 24 | TextEditingController addressController=new TextEditingController(); 25 | 26 | @override 27 | void initState() { 28 | // TODO: implement initState 29 | super.initState(); 30 | 31 | nameController.text = widget.arguments['name']; 32 | phoneController.text = widget.arguments['phone']; 33 | addressController.text = widget.arguments['address']; 34 | } 35 | 36 | //监听页面销毁的事件 37 | dispose(){ 38 | super.dispose(); 39 | eventBus.fire(new AddressEvent('编辑成功...')); 40 | } 41 | 42 | @override 43 | Widget build(BuildContext context) { 44 | return Scaffold( 45 | appBar: AppBar( 46 | title: Text("修改收货地址"), 47 | ), 48 | body: Container( 49 | padding: EdgeInsets.all(10), 50 | child: ListView( 51 | children: [ 52 | 53 | SizedBox(height: 20), 54 | JdText( 55 | controller: nameController, 56 | text: "收货人姓名", 57 | onChanged: (value){ 58 | nameController.text = value; 59 | }, 60 | ), 61 | SizedBox(height: 10), 62 | JdText( 63 | controller: phoneController, 64 | text: "收货人电话", 65 | onChanged: (value){ 66 | phoneController.text = value; 67 | }, 68 | ), 69 | 70 | // 地址 71 | SizedBox(height: 10), 72 | Container( 73 | padding: EdgeInsets.only(left: 5), 74 | height: ScreenAdaper.height(68), 75 | decoration: BoxDecoration( 76 | border: Border( 77 | bottom: BorderSide(width: 1, color: Colors.black12))), 78 | child: InkWell( 79 | child: Row( 80 | children: [ 81 | Icon(Icons.add_location), 82 | this.area.length>0?Text('${this.area}', style: TextStyle(color: Colors.black54)):Text('省/市/区', style: TextStyle(color: Colors.black54)) 83 | ], 84 | ), 85 | onTap: () async{ 86 | Result result = await CityPickers.showCityPicker( 87 | context: context, 88 | // 可以直接定位 89 | // locationCode: "130102", 90 | cancelWidget: 91 | Text("取消", style: TextStyle(color: Colors.blue)), 92 | confirmWidget: 93 | Text("确定", style: TextStyle(color: Colors.blue)) 94 | ); 95 | setState(() { 96 | this.area= "${result.provinceName}/${result.cityName}/${result.areaName}"; 97 | }); 98 | }, 99 | ), 100 | ), 101 | 102 | SizedBox(height: 10), 103 | JdText( 104 | controller: addressController, 105 | text: "详细地址", 106 | maxLines: 4, 107 | height: 200, 108 | onChanged: (value){ 109 | addressController.text = value; 110 | }, 111 | ), 112 | SizedBox(height: 40), 113 | 114 | // 修改 115 | JDButton(buttonTitle: "修改", buttonColor: Colors.red,tapEvent: () async{ 116 | List userinfo=await UserServices.getUserInfo(); 117 | var tempJson={ 118 | "uid":userinfo[0]["_id"], 119 | "id":widget.arguments["id"], 120 | "name": nameController.text, 121 | "phone":phoneController.text, 122 | "address":addressController.text, 123 | "salt":userinfo[0]["salt"] 124 | }; 125 | var sign = SignServices.getSign(tempJson); 126 | var api = '${Config.domain}api/editAddress'; 127 | var response = await Dio().post(api,data:{ 128 | "uid":userinfo[0]["_id"], 129 | "id":widget.arguments["id"], 130 | "name": nameController.text, 131 | "phone":phoneController.text, 132 | "address":addressController.text, 133 | "sign":sign 134 | }); 135 | Navigator.pop(context); 136 | }) 137 | ], 138 | ), 139 | ) 140 | ); 141 | } 142 | } -------------------------------------------------------------------------------- /lib/config/Config.dart: -------------------------------------------------------------------------------- 1 | class Config { 2 | // 静态属性,直接通过类名访问 3 | static String domain = "http://jd.itying.com/"; 4 | } -------------------------------------------------------------------------------- /lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:jdshop_app/provider/CartProvider.dart'; 3 | import 'package:jdshop_app/provider/CheckOutProvider.dart'; 4 | import 'package:jdshop_app/routers/router.dart'; 5 | import 'package:provider/provider.dart'; 6 | 7 | void main() => runApp(MyApp()); 8 | 9 | class MyApp extends StatefulWidget { 10 | MyApp({Key key}) : super(key: key); 11 | 12 | @override 13 | _MyAppState createState() => _MyAppState(); 14 | } 15 | 16 | class _MyAppState extends State { 17 | @override 18 | Widget build(BuildContext context) { 19 | // 提供通知 20 | return MultiProvider( 21 | providers: [ 22 | ChangeNotifierProvider(create: (_) => CheckOutProvider()), 23 | ChangeNotifierProvider(create: (_) => CartProvider()), 24 | ], 25 | 26 | child: MaterialApp( 27 | initialRoute: '/', 28 | onGenerateRoute: onGenerateRoute, 29 | // 修改主题颜色 30 | theme: ThemeData( 31 | primaryColor: Colors.white 32 | ), 33 | // 去掉debug 34 | debugShowCheckedModeBanner: false 35 | ) 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lib/model/CateModel.dart: -------------------------------------------------------------------------------- 1 | class CateModel { 2 | List result; 3 | 4 | CateModel({this.result}); 5 | 6 | CateModel.fromJson(Map json) { 7 | if (json['result'] != null) { 8 | result = new List(); 9 | json['result'].forEach((v) { 10 | result.add(new CateItemModel.fromJson(v)); 11 | }); 12 | } 13 | } 14 | 15 | Map toJson() { 16 | final Map data = new Map(); 17 | if (this.result != null) { 18 | data['result'] = this.result.map((v) => v.toJson()).toList(); 19 | } 20 | return data; 21 | } 22 | } 23 | 24 | class CateItemModel { 25 | String sId; 26 | String title; 27 | Object status; 28 | String pic; 29 | String pid; 30 | String sort; 31 | 32 | CateItemModel({this.sId, this.title, this.status, this.pic, this.pid, this.sort}); 33 | 34 | CateItemModel.fromJson(Map json) { 35 | sId = json['_id']; 36 | title = json['title']; 37 | status = json['status']; 38 | pic = json['pic']; 39 | pid = json['pid']; 40 | sort = json['sort']; 41 | } 42 | 43 | Map toJson() { 44 | final Map data = new Map(); 45 | data['_id'] = this.sId; 46 | data['title'] = this.title; 47 | data['status'] = this.status; 48 | data['pic'] = this.pic; 49 | data['pid'] = this.pid; 50 | data['sort'] = this.sort; 51 | return data; 52 | } 53 | } -------------------------------------------------------------------------------- /lib/model/FocusModel.dart: -------------------------------------------------------------------------------- 1 | // '{"_id":"59f6ef443ce1fb0fb02c7a43","title":"笔记本电脑 ","status":"1","pic":"public\\upload\\UObZahqPYzFvx_C9CQjU8KiX.png"," url":"12" }' 2 | // 小项目中使用 dart:convert 手动序列化 JSON 非常好 3 | // 大项目类型安全(20看不出int还是string、自动补全people.name而不是people["name"] 4 | // 最重要的编译时异常people["neme"]打错不能发现,编译了才能发现 5 | 6 | class FocusModel { 7 | List result; 8 | 9 | FocusModel({this.result}); 10 | 11 | FocusModel.fromJson(Map json) { 12 | if (json['result'] != null) { 13 | result = new List(); 14 | json['result'].forEach((v) { 15 | result.add(new FocusItem.fromJson(v)); 16 | }); 17 | } 18 | } 19 | 20 | Map toJson() { 21 | final Map data = new Map(); 22 | if (this.result != null) { 23 | data['result'] = this.result.map((v) => v.toJson()).toList(); 24 | } 25 | return data; 26 | } 27 | } 28 | 29 | class FocusItem { 30 | String sId;// 商品id 31 | String title;// 标题 32 | String status; 33 | String pic;// 图片地址 34 | String url;// 跳转地址 35 | 36 | // 可选构造函数 37 | FocusItem({this.sId, this.title, this.status, this.pic, this.url}); 38 | 39 | // 命名构造函数 40 | FocusItem.fromJson(Map json) { 41 | sId = json['_id']; 42 | title = json['title']; 43 | status = json['status']; 44 | pic = json['pic']; 45 | url = json['url']; 46 | } 47 | 48 | // 类里面的属性转化为Map类型 49 | Map toJson() { 50 | final Map data = new Map(); 51 | data['_id'] = this.sId; 52 | data['title'] = this.title; 53 | data['status'] = this.status; 54 | data['pic'] = this.pic; 55 | data['url'] = this.url; 56 | return data; 57 | } 58 | } -------------------------------------------------------------------------------- /lib/model/OrderModel.dart: -------------------------------------------------------------------------------- 1 | class OrderModel { 2 | bool success; 3 | String message; 4 | List result; 5 | 6 | OrderModel({this.success, this.message, this.result}); 7 | 8 | OrderModel.fromJson(Map json) { 9 | success = json['success']; 10 | message = json['message']; 11 | if (json['result'] != null) { 12 | result = new List(); 13 | json['result'].forEach((v) { 14 | result.add(new Result.fromJson(v)); 15 | }); 16 | } 17 | } 18 | 19 | Map toJson() { 20 | final Map data = new Map(); 21 | data['success'] = this.success; 22 | data['message'] = this.message; 23 | if (this.result != null) { 24 | data['result'] = this.result.map((v) => v.toJson()).toList(); 25 | } 26 | return data; 27 | } 28 | } 29 | 30 | class Result { 31 | String sId; 32 | String uid; 33 | String name; 34 | String phone; 35 | String address; 36 | String allPrice; 37 | int payStatus; 38 | int orderStatus; 39 | List orderItem; 40 | 41 | Result( 42 | {this.sId, 43 | this.uid, 44 | this.name, 45 | this.phone, 46 | this.address, 47 | this.allPrice, 48 | this.payStatus, 49 | this.orderStatus, 50 | this.orderItem}); 51 | 52 | Result.fromJson(Map json) { 53 | sId = json['_id']; 54 | uid = json['uid']; 55 | name = json['name']; 56 | phone = json['phone']; 57 | address = json['address']; 58 | allPrice = json['all_price']; 59 | payStatus = json['pay_status']; 60 | orderStatus = json['order_status']; 61 | if (json['order_item'] != null) { 62 | orderItem = new List(); 63 | json['order_item'].forEach((v) { 64 | orderItem.add(new OrderItem.fromJson(v)); 65 | }); 66 | } 67 | } 68 | 69 | Map toJson() { 70 | final Map data = new Map(); 71 | data['_id'] = this.sId; 72 | data['uid'] = this.uid; 73 | data['name'] = this.name; 74 | data['phone'] = this.phone; 75 | data['address'] = this.address; 76 | data['all_price'] = this.allPrice; 77 | data['pay_status'] = this.payStatus; 78 | data['order_status'] = this.orderStatus; 79 | if (this.orderItem != null) { 80 | data['order_item'] = this.orderItem.map((v) => v.toJson()).toList(); 81 | } 82 | return data; 83 | } 84 | } 85 | 86 | class OrderItem { 87 | String sId; 88 | String orderId; 89 | String productTitle; 90 | String productId; 91 | int productPrice; 92 | String productImg; 93 | int productCount; 94 | String selectedAttr; 95 | int addTime; 96 | 97 | OrderItem( 98 | {this.sId, 99 | this.orderId, 100 | this.productTitle, 101 | this.productId, 102 | this.productPrice, 103 | this.productImg, 104 | this.productCount, 105 | this.selectedAttr, 106 | this.addTime}); 107 | 108 | OrderItem.fromJson(Map json) { 109 | sId = json['_id']; 110 | orderId = json['order_id']; 111 | productTitle = json['product_title']; 112 | productId = json['product_id']; 113 | productPrice = json['product_price']; 114 | productImg = json['product_img']; 115 | productCount = json['product_count']; 116 | selectedAttr = json['selected_attr']; 117 | addTime = json['add_time']; 118 | } 119 | 120 | Map toJson() { 121 | final Map data = new Map(); 122 | data['_id'] = this.sId; 123 | data['order_id'] = this.orderId; 124 | data['product_title'] = this.productTitle; 125 | data['product_id'] = this.productId; 126 | data['product_price'] = this.productPrice; 127 | data['product_img'] = this.productImg; 128 | data['product_count'] = this.productCount; 129 | data['selected_attr'] = this.selectedAttr; 130 | data['add_time'] = this.addTime; 131 | return data; 132 | } 133 | } -------------------------------------------------------------------------------- /lib/model/ProductContentMainModel.dart: -------------------------------------------------------------------------------- 1 | class ProductContentMainModel { 2 | ProductContentMainItem result; 3 | 4 | ProductContentMainModel({this.result}); 5 | 6 | ProductContentMainModel.fromJson(Map json) { 7 | result = 8 | json['result'] != null ? new ProductContentMainItem.fromJson(json['result']) : null; 9 | } 10 | 11 | Map toJson() { 12 | final Map data = new Map(); 13 | if (this.result != null) { 14 | data['result'] = this.result.toJson(); 15 | } 16 | return data; 17 | } 18 | } 19 | 20 | class ProductContentMainItem { 21 | String sId; 22 | String title; 23 | String cid; 24 | Object price; 25 | String oldPrice; 26 | Object isBest; 27 | Object isHot; 28 | Object isNew; 29 | String status; 30 | String pic; 31 | String content; 32 | String cname; 33 | List attr; 34 | String subTitle; 35 | Object salecount; 36 | // 新增 37 | int count; 38 | String selectedAttr; 39 | 40 | ProductContentMainItem( 41 | {this.sId, 42 | this.title, 43 | this.cid, 44 | this.price, 45 | this.oldPrice, 46 | this.isBest, 47 | this.isHot, 48 | this.isNew, 49 | this.status, 50 | this.pic, 51 | this.content, 52 | this.cname, 53 | this.attr, 54 | this.subTitle, 55 | this.salecount, 56 | this.count, 57 | this.selectedAttr}); 58 | 59 | ProductContentMainItem.fromJson(Map json) { 60 | sId = json['_id']; 61 | title = json['title']; 62 | cid = json['cid']; 63 | price = json['price']; 64 | oldPrice = json['old_price']; 65 | isBest = json['is_best']; 66 | isHot = json['is_hot']; 67 | isNew = json['is_new']; 68 | status = json['status']; 69 | pic = json['pic']; 70 | content = json['content']; 71 | cname = json['cname']; 72 | if (json['attr'] != null) { 73 | attr = new List(); 74 | json['attr'].forEach((v) { 75 | attr.add(new Attr.fromJson(v)); 76 | }); 77 | } 78 | subTitle = json['sub_title']; 79 | salecount = json['salecount']; 80 | 81 | // 新增 82 | count = 1; 83 | selectedAttr = ''; 84 | } 85 | 86 | Map toJson() { 87 | final Map data = new Map(); 88 | data['_id'] = this.sId; 89 | data['title'] = this.title; 90 | data['cid'] = this.cid; 91 | data['price'] = this.price; 92 | data['old_price'] = this.oldPrice; 93 | data['is_best'] = this.isBest; 94 | data['is_hot'] = this.isHot; 95 | data['is_new'] = this.isNew; 96 | data['status'] = this.status; 97 | data['pic'] = this.pic; 98 | data['content'] = this.content; 99 | data['cname'] = this.cname; 100 | if (this.attr != null) { 101 | data['attr'] = this.attr.map((v) => v.toJson()).toList(); 102 | } 103 | data['sub_title'] = this.subTitle; 104 | data['salecount'] = this.salecount; 105 | return data; 106 | } 107 | } 108 | 109 | class Attr { 110 | String cate; 111 | List list; 112 | // 新添属性,用于添加CHECK 113 | List attrList; 114 | Attr({this.cate, this.list}); 115 | 116 | Attr.fromJson(Map json) { 117 | cate = json['cate']; 118 | list = json['list'].cast(); 119 | attrList = []; 120 | } 121 | 122 | Map toJson() { 123 | final Map data = new Map(); 124 | data['cate'] = this.cate; 125 | data['list'] = this.list; 126 | return data; 127 | } 128 | } -------------------------------------------------------------------------------- /lib/model/ProductList.dart: -------------------------------------------------------------------------------- 1 | class ProductListModel { 2 | List result; 3 | 4 | ProductListModel({this.result}); 5 | 6 | ProductListModel.fromJson(Map json) { 7 | if (json['result'] != null) { 8 | result = new List(); 9 | json['result'].forEach((v) { 10 | result.add(new ProductListItemModel.fromJson(v)); 11 | }); 12 | } 13 | } 14 | 15 | Map toJson() { 16 | final Map data = new Map(); 17 | if (this.result != null) { 18 | data['result'] = this.result.map((v) => v.toJson()).toList(); 19 | } 20 | return data; 21 | } 22 | } 23 | 24 | class ProductListItemModel { 25 | String sId; 26 | String title; 27 | String cid; 28 | Object price; 29 | String oldPrice; 30 | String pic; 31 | // 自动会 去掉下划线,以驼峰形式命名 32 | String sPic; 33 | 34 | ProductListItemModel( 35 | {this.sId, 36 | this.title, 37 | this.cid, 38 | this.price, 39 | this.oldPrice, 40 | this.pic, 41 | this.sPic}); 42 | 43 | ProductListItemModel.fromJson(Map json) { 44 | sId = json['_id']; 45 | title = json['title']; 46 | cid = json['cid']; 47 | price = json['price']; 48 | oldPrice = json['old_price']; 49 | pic = json['pic']; 50 | sPic = json['s_pic']; 51 | } 52 | 53 | Map toJson() { 54 | final Map data = new Map(); 55 | data['_id'] = this.sId; 56 | data['title'] = this.title; 57 | data['cid'] = this.cid; 58 | data['price'] = this.price; 59 | data['old_price'] = this.oldPrice; 60 | data['pic'] = this.pic; 61 | data['s_pic'] = this.sPic; 62 | return data; 63 | } 64 | } -------------------------------------------------------------------------------- /lib/pages/cart/cartItem.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:jdshop_app/pages/cart/cartNum.dart'; 3 | import 'package:jdshop_app/provider/CartProvider.dart'; 4 | import 'package:jdshop_app/services/ScreenAdaper.dart'; 5 | import 'package:provider/provider.dart'; 6 | 7 | class CartItem extends StatefulWidget { 8 | Map _itemData; 9 | CartItem(this._itemData,{Key key}) : super(key: key); 10 | 11 | @override 12 | _CartItemState createState() => _CartItemState(); 13 | } 14 | 15 | class _CartItemState extends State { 16 | // 获取item的值 17 | Map _itemData; 18 | @override 19 | void initState() { 20 | // TODO: implement initState 21 | super.initState(); 22 | 23 | // 删除中间数据 _itemData 不会重新赋值,因为该initState不会被触发,但是build方法会重新触发 24 | // 也就是该页面_itemData仍为旧数据, 但是List数量删除后减少了,原来5条,删除中间2条后剩余3条,这样页面显示的是前面3条 25 | // 当重新运行的时候init执行获取数据,显示正确 26 | // this._itemData = widget._itemData; 27 | } 28 | 29 | @override 30 | Widget build(BuildContext context) { 31 | // 重新给该属性赋值: 只需要一次赋值,放在init里,需要多次赋予值放在build 32 | this._itemData = widget._itemData; 33 | var cartProvider = Provider.of(context); 34 | 35 | return Container( 36 | height: ScreenAdaper.height(200), 37 | padding: EdgeInsets.all(5), 38 | 39 | // 底部线条 40 | decoration: BoxDecoration( 41 | border: Border( 42 | bottom: BorderSide( 43 | width: ScreenAdaper.width(2), 44 | color: Colors.black12 45 | ) 46 | ) 47 | ), 48 | 49 | // cell 50 | child: Row( 51 | children: [ 52 | // 单选框 53 | Container( 54 | width: ScreenAdaper.width(60), 55 | child: Checkbox( 56 | value: this._itemData["checked"], 57 | activeColor: Colors.pink, 58 | onChanged: (value) { 59 | setState(() { 60 | // 改变了_itemData --》 改变了_cartList 61 | this._itemData["checked"] = !this._itemData["checked"]; 62 | }); 63 | // 判断是否全选 64 | cartProvider.itemChange(); 65 | }, 66 | ), 67 | ), 68 | 69 | // 图片 70 | Container( 71 | width: ScreenAdaper.width(160), 72 | child: Image.network("${this._itemData["pic"]}",fit: BoxFit.cover) 73 | ), 74 | 75 | // 标题 76 | Expanded(// 浮动 77 | flex: 1, 78 | child: Container( 79 | padding: EdgeInsets.fromLTRB(10, 10, 10, 5), 80 | child: Column(// 上title 下detail 81 | mainAxisAlignment: MainAxisAlignment.spaceBetween, 82 | crossAxisAlignment: CrossAxisAlignment.start, 83 | children: [ 84 | // title 85 | Text("${this._itemData["title"]}",maxLines: 2), 86 | // attr 87 | Text("${this._itemData["selectedAttr"]}",maxLines: 2), 88 | 89 | // 左:¥12 右:+- 90 | Stack( 91 | children: [ 92 | // ¥12 93 | Align( 94 | alignment: Alignment.centerLeft, 95 | child: Text("¥${this._itemData["price"]}",style: TextStyle( 96 | color: Colors.red 97 | )) 98 | ), 99 | 100 | // +- 101 | Align( 102 | alignment: Alignment.centerRight, 103 | child: CartNum(this._itemData), 104 | ) 105 | ], 106 | ) 107 | ], 108 | ), 109 | ), 110 | ) 111 | ], 112 | ), 113 | ); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /lib/pages/cart/cartNum.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:jdshop_app/provider/CartProvider.dart'; 3 | import 'package:jdshop_app/services/ScreenAdaper.dart'; 4 | import 'package:provider/provider.dart'; 5 | 6 | class CartNum extends StatefulWidget { 7 | Map _itemData; 8 | CartNum(this._itemData, {Key key}) : super(key: key); 9 | 10 | @override 11 | _CartNumState createState() => _CartNumState(); 12 | } 13 | 14 | class _CartNumState extends State { 15 | CartProvider _cartProvider; 16 | 17 | // 获得上一个页面传入的数据 18 | Map _itemData; 19 | @override 20 | void initState() { 21 | // TODO: implement initState 22 | super.initState(); 23 | 24 | this._itemData = widget._itemData; 25 | } 26 | 27 | @override 28 | Widget build(BuildContext context) { 29 | ScreenAdaper.init(context); 30 | this._cartProvider = Provider.of(context); 31 | 32 | //左侧按钮 33 | Widget _leftBtn() { 34 | return InkWell( 35 | onTap: () { 36 | if (this._itemData["count"] > 1) { 37 | // 数据不是直接绑定在provider 38 | this._itemData["count"] = this._itemData["count"] - 1; 39 | // 但没有存储到本地,重新运行后值还是以前的 40 | this._cartProvider.itemCountChange(); 41 | } 42 | }, 43 | child: Container( 44 | alignment: Alignment.center, 45 | width: ScreenAdaper.width(45), 46 | height: ScreenAdaper.height(45), 47 | child: Text("-"), 48 | ), 49 | ); 50 | } 51 | 52 | //右侧按钮 53 | Widget _rightBtn() { 54 | return InkWell( 55 | onTap: (){ 56 | // 改变了_cartList的值 57 | this._itemData["count"] = this._itemData["count"] + 1; 58 | // 但没有存储到本地,重新运行后值还是以前的 59 | this._cartProvider.itemCountChange(); 60 | }, 61 | child: Container( 62 | alignment: Alignment.center, 63 | width: ScreenAdaper.width(45), 64 | height: ScreenAdaper.height(45), 65 | child: Text("+"), 66 | ), 67 | ); 68 | } 69 | 70 | Widget _centerArea() { 71 | return Container( 72 | alignment: Alignment.center, 73 | width: ScreenAdaper.width(70), 74 | decoration: BoxDecoration( 75 | border: Border( 76 | left: BorderSide(width: ScreenAdaper.width(2), color: Colors.black12), 77 | right: BorderSide(width: ScreenAdaper.width(2), color: Colors.black12), 78 | )), 79 | height: ScreenAdaper.height(45), 80 | child: Text("${this._itemData["count"]}"), 81 | ); 82 | } 83 | 84 | return Container( 85 | width: ScreenAdaper.width(168), 86 | decoration: 87 | BoxDecoration(border: Border.all(width: ScreenAdaper.width(2), color: Colors.black12)), 88 | child: Row( 89 | children: [ 90 | _leftBtn(), 91 | _centerArea(), 92 | _rightBtn() 93 | ], 94 | ), 95 | ); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /lib/pages/login/Login.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:dio/dio.dart'; 4 | import 'package:flutter/material.dart'; 5 | import 'package:fluttertoast/fluttertoast.dart'; 6 | import 'package:jdshop_app/config/Config.dart'; 7 | import 'package:jdshop_app/services/EventsBus.dart'; 8 | import 'package:jdshop_app/services/ScreenAdaper.dart'; 9 | import 'package:jdshop_app/services/Storage.dart'; 10 | import 'package:jdshop_app/widget/JDButton.dart'; 11 | import 'package:jdshop_app/widget/JDText.dart'; 12 | 13 | class LoginPage extends StatefulWidget { 14 | LoginPage({Key key}) : super(key: key); 15 | 16 | @override 17 | _LoginPageState createState() => _LoginPageState(); 18 | } 19 | 20 | class _LoginPageState extends State { 21 | 22 | // 登陆 23 | String _password = ""; 24 | String _username = ""; 25 | doLogin() async { 26 | // 验证手机号码是否正确 27 | RegExp reg = RegExp(r"^1\d{10}$"); 28 | if (!reg.hasMatch(this._username)) { 29 | Fluttertoast.showToast(msg: "用户名格式不正确",toastLength: Toast.LENGTH_SHORT,gravity: ToastGravity.CENTER); 30 | } else if (this._password.length < 6) { 31 | Fluttertoast.showToast(msg: "密码格式 不正确", 32 | toastLength: Toast.LENGTH_SHORT, 33 | gravity: ToastGravity.CENTER); 34 | } else { 35 | var api = "${Config.domain}api/doLogin"; 36 | var response = await new Dio().post(api,data: {"username":this._username, "password":this._password}); 37 | if (response.data["success"]) { 38 | //保存用户信息 39 | Storage.setString('userInfo', json.encode(response.data["userinfo"])); 40 | Navigator.pop(context); 41 | } else { 42 | Fluttertoast.showToast( 43 | msg: '${response.data["message"]}', 44 | toastLength: Toast.LENGTH_SHORT, 45 | gravity: ToastGravity.CENTER, 46 | ); 47 | } 48 | } 49 | } 50 | // 从子页面Login回到上级页面User,不会刷新User 51 | // 监听登陆页面销毁的事件 52 | @override 53 | void dispose() { 54 | // TODO: implement dispose 55 | super.dispose(); 56 | 57 | // 广播:登陆页面退出的时候,通知用户中心刷新页面 58 | eventBus.fire(new UserEvent("登陆成功...")); 59 | } 60 | 61 | @override 62 | Widget build(BuildContext context) { 63 | ScreenAdaper.init(context); 64 | return Scaffold( 65 | appBar: AppBar( 66 | leading: IconButton( 67 | icon: Icon(Icons.close), 68 | onPressed: () { 69 | Navigator.pop(context); 70 | }, 71 | ), 72 | actions: [ 73 | TextButton( 74 | child: Text("客服"), 75 | onPressed: () { 76 | 77 | }, 78 | ) 79 | ], 80 | ), 81 | 82 | // ListView:当键盘放不下的时候可以滑动页面 83 | body: Container( 84 | padding: EdgeInsets.all(ScreenAdaper.width(20)), 85 | child: ListView( 86 | children: [ 87 | // 方框图 88 | Center( 89 | child: Container( 90 | margin: EdgeInsets.only(top: 30), 91 | height: ScreenAdaper.height(160), 92 | width: ScreenAdaper.height(160), 93 | child: Image.network('https://i0.hdslb.com/bfs/article/eda171aacf3a5a14b659bddda2f1d02efa99ed96.jpg@1320w_866h.jpg',fit: BoxFit.cover), 94 | ), 95 | ), 96 | SizedBox(height: 30), 97 | 98 | // 用户名 99 | JdText(text: "请输入用户名",onChanged: (value) { 100 | this._username = value; 101 | }), 102 | SizedBox(height: 10), 103 | 104 | // 密码 105 | JdText(text: "请输入密码",onChanged: (value) { 106 | this._password = value; 107 | }), 108 | SizedBox(height: 20), 109 | 110 | // 忘记密码/新用户注册 111 | Container( 112 | padding: EdgeInsets.all(20), 113 | child: Stack( 114 | children: [ 115 | Align( 116 | alignment: Alignment.centerLeft, 117 | child: InkWell( 118 | onTap: () { 119 | 120 | }, 121 | child: Text("忘记密码"), 122 | ), 123 | ), 124 | Align( 125 | alignment: Alignment.centerRight, 126 | child: InkWell( 127 | onTap: () { 128 | Navigator.pushNamed(context, '/registerFirst'); 129 | }, 130 | child: Text("新用户注册"), 131 | ), 132 | ) 133 | ], 134 | ), 135 | ), 136 | 137 | // 登陆按钮 138 | JDButton( 139 | buttonColor: Colors.red, 140 | buttonTitle: "登录", 141 | height: 74, 142 | tapEvent: doLogin 143 | ) 144 | ], 145 | ), 146 | ), 147 | ); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /lib/pages/login/RegisterFirst.dart: -------------------------------------------------------------------------------- 1 | import 'package:dio/dio.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:fluttertoast/fluttertoast.dart'; 4 | import 'package:jdshop_app/config/Config.dart'; 5 | import 'package:jdshop_app/services/ScreenAdaper.dart'; 6 | import 'package:jdshop_app/widget/JDButton.dart'; 7 | import 'package:jdshop_app/widget/JDText.dart'; 8 | 9 | class RegisterFirstPage extends StatefulWidget { 10 | RegisterFirstPage({Key key}) : super(key: key); 11 | 12 | _RegisterFirstPageState createState() => _RegisterFirstPageState(); 13 | } 14 | 15 | class _RegisterFirstPageState extends State { 16 | // 手机号:直接点击提交赋值为空 17 | String _tel = ""; 18 | // 发送验证码 19 | sendCode() async { 20 | // 验证手机号码是否正确 21 | RegExp reg = RegExp(r"^1\d{10}$"); 22 | if (reg.hasMatch(this._tel)) { 23 | var api = "${Config.domain}api/sendCode"; 24 | var response = await new Dio().post(api,data: {"tel":this._tel}); 25 | if (response.data["success"]) { 26 | print(response); //演示期间服务器直接返回 给手机发送的验证码 27 | Navigator.pushNamed(context, '/registerSecond', arguments: { 28 | "tel":this._tel 29 | }); 30 | } else { 31 | Fluttertoast.showToast(msg: "${response.data["message"]}",toastLength: Toast.LENGTH_SHORT,gravity: ToastGravity.CENTER); 32 | } 33 | } else { 34 | Fluttertoast.showToast(msg: "手机号码格式不正确",toastLength: Toast.LENGTH_SHORT,gravity: ToastGravity.CENTER); 35 | } 36 | } 37 | 38 | @override 39 | Widget build(BuildContext context) { 40 | return Scaffold( 41 | appBar: AppBar( 42 | title: Text("用户注册-第一步"), 43 | ), 44 | body: Container( 45 | padding: EdgeInsets.all(ScreenAdaper.width(20)), 46 | child: ListView( 47 | children: [ 48 | SizedBox(height: 50), 49 | JdText( 50 | text: "请输入手机号", 51 | onChanged: (value) { 52 | this._tel = value; 53 | }, 54 | ), 55 | SizedBox(height: 20), 56 | JDButton( 57 | buttonTitle: "下一步", 58 | buttonColor: Colors.red, 59 | height: 74, 60 | tapEvent: sendCode 61 | ) 62 | ], 63 | ), 64 | ), 65 | ); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /lib/pages/login/RegisterSecond.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:dio/dio.dart'; 4 | import 'package:flutter/material.dart'; 5 | import 'package:fluttertoast/fluttertoast.dart'; 6 | import 'package:jdshop_app/config/Config.dart'; 7 | import 'package:jdshop_app/services/ScreenAdaper.dart'; 8 | import 'package:jdshop_app/widget/JDButton.dart'; 9 | import 'package:jdshop_app/widget/JDText.dart'; 10 | 11 | class RegisterSecondPage extends StatefulWidget { 12 | final Map arguments; 13 | RegisterSecondPage({Key key, this.arguments}) : super(key: key); 14 | 15 | _RegisterSecondPageState createState() => _RegisterSecondPageState(); 16 | } 17 | 18 | class _RegisterSecondPageState extends State { 19 | // 手机号码 20 | String _tel; 21 | @override 22 | void initState() { 23 | // TODO: implement initState 24 | super.initState(); 25 | this._tel = widget.arguments["tel"]; 26 | // 调用倒计时 27 | _showTimer(); 28 | } 29 | 30 | // 倒计时 31 | bool _sendCodeBtn = false; 32 | int _seconds = 10; 33 | // 倒计时 34 | _showTimer() { 35 | Timer timer; 36 | timer = Timer.periodic(Duration(milliseconds: 1000), (timer) { 37 | // 每秒减1 38 | setState(() { 39 | this._seconds--; 40 | }); 41 | // 减为0清除定时器 42 | if (this._seconds == 0) { 43 | timer.cancel(); 44 | // 回归原样 45 | setState(() { 46 | this._sendCodeBtn = true; 47 | }); 48 | } 49 | }); 50 | } 51 | // 重新发送验证码 52 | sendCode() async { 53 | // 显示倒计时 54 | setState(() { 55 | this._sendCodeBtn = false; 56 | this._seconds = 10; 57 | this._showTimer(); 58 | }); 59 | // 请求验证码 60 | var api = '${Config.domain}api/sendCode'; 61 | var response = await Dio().post(api, data: {"tel": this._tel}); 62 | if (response.data["success"]) { 63 | print(response); //演示期间服务器直接返回 给手机发送的验证码 64 | } 65 | } 66 | // 验证码 67 | String _code; 68 | // 验证验证码 69 | validateCode() async { 70 | var api = '${Config.domain}api/validateCode'; 71 | var response = await Dio().post(api, data: {"tel": this._tel,"code": this._code}); 72 | 73 | if (response.data["success"]) { 74 | Navigator.pushNamed(context, '/registerThird', arguments: { 75 | "tel" : this._tel, 76 | "code" : this._code 77 | }); 78 | } else { 79 | Fluttertoast.showToast( 80 | msg: '${response.data["message"]}', 81 | toastLength: Toast.LENGTH_SHORT, 82 | gravity: ToastGravity.CENTER, 83 | ); 84 | } 85 | } 86 | 87 | @override 88 | Widget build(BuildContext context) { 89 | return Scaffold( 90 | appBar: AppBar( 91 | title: Text("用户注册-第二步"), 92 | ), 93 | body: Container( 94 | padding: EdgeInsets.all(ScreenAdaper.width(20)), 95 | child: ListView( 96 | children: [ 97 | SizedBox(height: 50), 98 | 99 | Container( 100 | padding: EdgeInsets.only(left: 10), 101 | child: Text("验证码已经发送到了您的${this._tel}手机,请输入${this._tel}手机号收到的验证码"), 102 | ), 103 | SizedBox(height:40), 104 | 105 | Stack( 106 | children: [ 107 | Container( 108 | child: JdText( 109 | text: "请输入验证码", 110 | onChanged: (value) { 111 | this._code = value; 112 | }, 113 | ), 114 | height: ScreenAdaper.height(100), 115 | ), 116 | 117 | Positioned( 118 | right: 0, 119 | top: 0, 120 | child: this._sendCodeBtn ? ElevatedButton( 121 | child: Text('重新发送'), 122 | onPressed: sendCode 123 | ) : ElevatedButton( 124 | child: Text('${this._seconds}秒后重发'), 125 | onPressed: (){ 126 | 127 | }, 128 | ), 129 | ) 130 | 131 | ], 132 | ), 133 | SizedBox(height: 20), 134 | JDButton( 135 | buttonTitle: "下一步", 136 | buttonColor: Colors.red, 137 | height: 74, 138 | tapEvent: validateCode 139 | ) 140 | ], 141 | ), 142 | ), 143 | ); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /lib/pages/login/RegisterThird.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:dio/dio.dart'; 4 | import 'package:flutter/material.dart'; 5 | import 'package:fluttertoast/fluttertoast.dart'; 6 | import 'package:jdshop_app/config/Config.dart'; 7 | import 'package:jdshop_app/pages/tabs/Tabs.dart'; 8 | import 'package:jdshop_app/services/ScreenAdaper.dart'; 9 | import 'package:jdshop_app/services/Storage.dart'; 10 | import 'package:jdshop_app/widget/JDButton.dart'; 11 | import 'package:jdshop_app/widget/JDText.dart'; 12 | 13 | class RegisterThirdPage extends StatefulWidget { 14 | Map arguments; 15 | RegisterThirdPage({Key key, this.arguments}) : super(key: key); 16 | 17 | _RegisterThirdPageState createState() => _RegisterThirdPageState(); 18 | } 19 | 20 | class _RegisterThirdPageState extends State { 21 | // 传入的值 22 | String _tel, _code; 23 | String _password = ""; 24 | String _repassword = ""; 25 | @override 26 | void initState() { 27 | // TODO: implement initState 28 | super.initState(); 29 | this._tel = widget.arguments["tel"]; 30 | this._code = widget.arguments["code"]; 31 | } 32 | 33 | // 注册 34 | doRegister() async { 35 | if (this._password.length < 6) { 36 | Fluttertoast.showToast( 37 | msg: '密码长度不能太短', 38 | toastLength: Toast.LENGTH_SHORT, 39 | gravity: ToastGravity.CENTER, 40 | ); 41 | } else if (this._password != this._repassword) { 42 | Fluttertoast.showToast( 43 | msg: '密码和确认密码不一致', 44 | toastLength: Toast.LENGTH_SHORT, 45 | gravity: ToastGravity.CENTER, 46 | ); 47 | } else { 48 | var api = '${Config.domain}api/register'; 49 | var response = await Dio().post(api, data: {"tel": this._tel,"code": this._code,"password":this._password}); 50 | 51 | if (response.data["success"]) { 52 | // 保存用户信息 53 | await Storage.setString("userInfo", json.encode(response.data["userinfo"])); 54 | // 返回首页 55 | Navigator.of(context).pushAndRemoveUntil(new MaterialPageRoute(builder: (context) => new Tabs()), (route) => route == null); 56 | 57 | } else { 58 | Fluttertoast.showToast( 59 | msg: '${response.data["message"]}', 60 | toastLength: Toast.LENGTH_SHORT, 61 | gravity: ToastGravity.CENTER, 62 | ); 63 | } 64 | } 65 | } 66 | 67 | @override 68 | Widget build(BuildContext context) { 69 | return Scaffold( 70 | appBar: AppBar( 71 | title: Text("用户注册-第三步"), 72 | ), 73 | body: Container( 74 | padding: EdgeInsets.all(ScreenAdaper.width(20)), 75 | child: ListView( 76 | children: [ 77 | SizedBox(height: 50), 78 | JdText( 79 | text: "请输入密码", 80 | password: true, 81 | onChanged: (value) { 82 | this._password = value; 83 | }, 84 | ), 85 | SizedBox(height: 10), 86 | JdText( 87 | text: "请输入确认密码", 88 | password: true, 89 | onChanged: (value) { 90 | this._repassword = value; 91 | }, 92 | ), 93 | SizedBox(height: 20), 94 | JDButton( 95 | buttonTitle: "注册", 96 | buttonColor: Colors.red, 97 | height: 74, 98 | tapEvent: doRegister 99 | ) 100 | ], 101 | ), 102 | ), 103 | ); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /lib/pages/productContent/Order.dart: -------------------------------------------------------------------------------- 1 | import 'package:dio/dio.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:jdshop_app/config/Config.dart'; 4 | import 'package:jdshop_app/model/OrderModel.dart'; 5 | import 'package:jdshop_app/services/ScreenAdaper.dart'; 6 | import 'package:jdshop_app/services/SignServices.dart'; 7 | import 'package:jdshop_app/services/UserServices.dart'; 8 | 9 | class OrderPage extends StatefulWidget { 10 | OrderPage({Key key}) : super(key: key); 11 | 12 | _OrderPageState createState() => _OrderPageState(); 13 | } 14 | 15 | class _OrderPageState extends State { 16 | 17 | // 获取数据 18 | List _orderList = []; 19 | @override 20 | void initState() { 21 | // TODO: implement initState 22 | super.initState(); 23 | this._getListData(); 24 | } 25 | void _getListData() async { 26 | List userinfo = await UserServices.getUserInfo(); 27 | var tempJson = {"uid": userinfo[0]['_id'], "salt": userinfo[0]["salt"]}; 28 | var sign = SignServices.getSign(tempJson); 29 | var api = '${Config.domain}api/orderList?uid=${userinfo[0]['_id']}&sign=${sign}'; 30 | var response = await Dio().get(api); 31 | print(response.data is Map); 32 | setState(() { 33 | var orderMode = new OrderModel.fromJson(response.data); 34 | this._orderList = orderMode.result; 35 | print(this._orderList[0].name); 36 | }); 37 | } 38 | 39 | //自定义商品列表组件 40 | List _orderItemWidget(orderItems) { 41 | List tempList = []; 42 | for (var i = 0; i < orderItems.length; i++) { 43 | tempList.add(Column( 44 | children: [ 45 | SizedBox(height: 10), 46 | ListTile( 47 | leading: Container( 48 | width: ScreenAdaper.width(120), 49 | height: ScreenAdaper.height(120), 50 | child: Image.network( 51 | '${orderItems[i].productImg}', 52 | fit: BoxFit.cover, 53 | ), 54 | ), 55 | title: Text("${orderItems[i].productTitle}"), 56 | trailing: Text('x${orderItems[i].productCount}'), 57 | ), 58 | SizedBox(height: 10) 59 | ], 60 | )); 61 | } 62 | return tempList; 63 | } 64 | 65 | @override 66 | Widget build(BuildContext context) { 67 | return Scaffold( 68 | appBar: AppBar( 69 | title: Text("我的订单"), 70 | ), 71 | body: Stack( 72 | children: [ 73 | Container( 74 | margin: EdgeInsets.fromLTRB(0, ScreenAdaper.height(80), 0, 0), 75 | padding: EdgeInsets.all(ScreenAdaper.width(16)), 76 | child: ListView( 77 | children: this._orderList.map((value) { 78 | return InkWell( 79 | onTap: (){ 80 | Navigator.pushNamed(context, '/orderinfo'); 81 | }, 82 | child: Card( 83 | child: Column( 84 | children: [ 85 | ListTile( 86 | title: Text("订单编号:${value.sId}", 87 | style: TextStyle(color: Colors.black54)), 88 | ), 89 | Divider(), 90 | Column( 91 | children: this._orderItemWidget(value.orderItem), 92 | ), 93 | SizedBox(height: 10), 94 | ListTile( 95 | leading: Text("合计:¥${value.allPrice}"), 96 | trailing: TextButton( 97 | child: Text("申请售后"), 98 | onPressed: () {}, 99 | style: ButtonStyle( 100 | backgroundColor: MaterialStateProperty.resolveWith((states) { 101 | return Colors.grey[100]; 102 | }), 103 | ), 104 | ), 105 | ), 106 | ], 107 | ), 108 | ), 109 | ); 110 | }).toList()), 111 | ), 112 | Positioned( 113 | top: 0, 114 | width: ScreenAdaper.width(750), 115 | height: ScreenAdaper.height(76), 116 | child: Container( 117 | width: ScreenAdaper.width(750), 118 | height: ScreenAdaper.height(76), 119 | color: Colors.white, 120 | child: Row( 121 | children: [ 122 | Expanded( 123 | child: Text("全部", textAlign: TextAlign.center), 124 | ), 125 | Expanded( 126 | child: Text("待付款", textAlign: TextAlign.center), 127 | ), 128 | Expanded( 129 | child: Text("待收货", textAlign: TextAlign.center), 130 | ), 131 | Expanded( 132 | child: Text("已完成", textAlign: TextAlign.center), 133 | ), 134 | Expanded( 135 | child: Text("已取消", textAlign: TextAlign.center), 136 | ) 137 | ], 138 | ), 139 | ), 140 | ) 141 | ], 142 | ), 143 | ); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /lib/pages/productContent/Pay.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:jdshop_app/widget/JDButton.dart'; 3 | 4 | class PayPage extends StatefulWidget { 5 | PayPage({Key key}) : super(key: key); 6 | 7 | _PayPageState createState() => _PayPageState(); 8 | } 9 | 10 | class _PayPageState extends State { 11 | List payList = [ 12 | { 13 | "title": "支付宝支付", 14 | "chekced": true, 15 | "image": "https://www.itying.com/themes/itying/images/alipay.png" 16 | }, 17 | { 18 | "title": "微信支付", 19 | "chekced": false, 20 | "image": "https://www.itying.com/themes/itying/images/weixinpay.png" 21 | } 22 | ]; 23 | 24 | @override 25 | Widget build(BuildContext context) { 26 | return Scaffold( 27 | appBar: AppBar( 28 | title: Text("去支付"), 29 | ), 30 | body: Column( 31 | children: [ 32 | Container( 33 | height: 400, 34 | padding: EdgeInsets.all(20), 35 | child: ListView.builder( 36 | itemCount: this.payList.length, 37 | itemBuilder: (context, index) { 38 | return Column( 39 | children: [ 40 | ListTile( 41 | leading: Image.network("${this.payList[index]["image"]}"), 42 | title: Text("${this.payList[index]["title"]}"), 43 | trailing: this.payList[index]["chekced"] ? Icon(Icons.check) : Text(""), 44 | 45 | 46 | onTap: () { 47 | setState(() { 48 | //让payList里面的checked都等于false 49 | for (var i = 0; i < this.payList.length; i++) { 50 | this.payList[i]['chekced'] = false; 51 | } 52 | // 当前选中的true 53 | this.payList[index]["chekced"] = true; 54 | }); 55 | }, 56 | ), 57 | Divider(), 58 | ], 59 | ); 60 | }, 61 | )), 62 | JDButton( 63 | buttonTitle: "支付", 64 | buttonColor: Colors.red, 65 | height: 74, 66 | tapEvent: () { 67 | print('支付1111'); 68 | }, 69 | ) 70 | ], 71 | ), 72 | ); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /lib/pages/productContent/ProductContentCartNum.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:jdshop_app/model/ProductContentMainModel.dart'; 3 | import 'package:jdshop_app/services/ScreenAdaper.dart'; 4 | 5 | // 数据存放在model里 6 | class ProductContentCartNum extends StatefulWidget { 7 | ProductContentMainItem _productContent; 8 | 9 | ProductContentCartNum(this._productContent,{Key key}) : super(key: key); 10 | 11 | @override 12 | _ProductContentCartNumState createState() => _ProductContentCartNumState(); 13 | } 14 | 15 | class _ProductContentCartNumState extends State { 16 | // 获取上个页面传入的_productContent数据 17 | ProductContentMainItem _productContent; 18 | @override 19 | void initState() { 20 | // TODO: implement initState 21 | super.initState(); 22 | this._productContent = widget._productContent; 23 | } 24 | 25 | @override 26 | Widget build(BuildContext context) { 27 | ScreenAdaper.init(context); 28 | 29 | //左侧按钮 30 | Widget _leftBtn() { 31 | return InkWell( 32 | onTap: () { 33 | // 最多减为1 34 | if (this._productContent.count > 1) { 35 | setState(() { 36 | this._productContent.count = this._productContent.count - 1; 37 | }); 38 | } 39 | }, 40 | child: Container( 41 | alignment: Alignment.center, 42 | width: ScreenAdaper.width(45), 43 | height: ScreenAdaper.height(45), 44 | child: Text("-"), 45 | ), 46 | ); 47 | } 48 | 49 | //右侧按钮 50 | Widget _rightBtn() { 51 | return InkWell( 52 | onTap: (){ 53 | setState(() { 54 | this._productContent.count++; 55 | }); 56 | }, 57 | child: Container( 58 | alignment: Alignment.center, 59 | width: ScreenAdaper.width(45), 60 | height: ScreenAdaper.height(45), 61 | child: Text("+"), 62 | ), 63 | ); 64 | } 65 | 66 | Widget _centerArea() { 67 | return Container( 68 | alignment: Alignment.center, 69 | width: ScreenAdaper.width(70), 70 | decoration: BoxDecoration( 71 | border: Border( 72 | left: BorderSide(width: 1, color: Colors.black12), 73 | right: BorderSide(width: 1, color: Colors.black12), 74 | )), 75 | height: ScreenAdaper.height(45), 76 | child: Text("${this._productContent.count}"), 77 | ); 78 | } 79 | 80 | return Container( 81 | width: ScreenAdaper.width(164), 82 | decoration: 83 | BoxDecoration(border: Border.all(width: 1, color: Colors.black12)), 84 | child: Row( 85 | children: [ 86 | _leftBtn(), 87 | _centerArea(), 88 | _rightBtn() 89 | ], 90 | ), 91 | ); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /lib/pages/productContent/ProductContentDetail.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:jdshop_app/services/ScreenAdaper.dart'; 3 | import 'package:flutter_inappwebview/flutter_inappwebview.dart'; 4 | 5 | 6 | class ProductContentDetailPage extends StatefulWidget { 7 | final List _productContentList; 8 | ProductContentDetailPage(this._productContentList, {Key key}) : super(key: key); 9 | 10 | @override 11 | _ProductContentDetailPageState createState() => _ProductContentDetailPageState(); 12 | } 13 | 14 | class _ProductContentDetailPageState extends State with AutomaticKeepAliveClientMixin { 15 | 16 | InAppWebViewController webView; 17 | String url = ""; 18 | double progress = 0; 19 | var _id; 20 | 21 | @override 22 | void initState() { 23 | // TODO: implement initState 24 | super.initState(); 25 | // 传入详情ID 26 | this._id = widget._productContentList[0].sId; 27 | } 28 | 29 | @override 30 | Widget build(BuildContext context) { 31 | return Container( 32 | child: Column(children: [ 33 | Expanded( 34 | child: Container( 35 | margin: const EdgeInsets.all(10.0), 36 | decoration: 37 | BoxDecoration(border: Border.all(color: Colors.blueAccent)), 38 | child: InAppWebView( 39 | initialUrl: "http://jd.itying.com/pcontent?id=${this._id}", 40 | initialHeaders: {}, 41 | 42 | initialOptions: InAppWebViewWidgetOptions( 43 | inAppWebViewOptions: InAppWebViewOptions( 44 | debuggingEnabled: true, 45 | ) 46 | ), 47 | 48 | onWebViewCreated: (InAppWebViewController controller) { 49 | webView = controller; 50 | }, 51 | onLoadStart: (InAppWebViewController controller, String url) { 52 | setState(() { 53 | this.url = url; 54 | }); 55 | }, 56 | onLoadStop: (InAppWebViewController controller, String url) async { 57 | setState(() { 58 | this.url = url; 59 | }); 60 | }, 61 | onProgressChanged: (InAppWebViewController controller, int progress) { 62 | setState(() { 63 | this.progress = progress / 100; 64 | }); 65 | }, 66 | ), 67 | ), 68 | ), 69 | ]) 70 | ); 71 | } 72 | 73 | @override 74 | // TODO: implement wantKeepAlive 75 | bool get wantKeepAlive => true; 76 | } 77 | -------------------------------------------------------------------------------- /lib/pages/productContent/ProductContentRate.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class ProductContentRatePage extends StatefulWidget { 4 | @override 5 | _ProductContentRatePageState createState() => _ProductContentRatePageState(); 6 | } 7 | 8 | class _ProductContentRatePageState extends State { 9 | @override 10 | Widget build(BuildContext context) { 11 | return Container( 12 | child: ListView.builder( 13 | itemCount: 30, 14 | itemBuilder: (context,index) { 15 | return ListTile( 16 | title: Text("第${index}条数据"), 17 | ); 18 | }, 19 | ), 20 | ); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lib/pages/tabs/Cart.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:fluttertoast/fluttertoast.dart'; 3 | import 'package:jdshop_app/pages/cart/cartItem.dart'; 4 | import 'package:jdshop_app/provider/CartProvider.dart'; 5 | import 'package:jdshop_app/provider/CheckOutProvider.dart'; 6 | import 'package:jdshop_app/services/CartService.dart'; 7 | import 'package:jdshop_app/services/ScreenAdaper.dart'; 8 | import 'package:jdshop_app/services/UserServices.dart'; 9 | import 'package:provider/provider.dart'; 10 | 11 | class CartPage extends StatefulWidget { 12 | @override 13 | _CartPageState createState() => _CartPageState(); 14 | } 15 | 16 | class _CartPageState extends State { 17 | CheckOutProvider _checkOutProvider; 18 | 19 | // 点击结算按钮 20 | doCheckOut() async { 21 | // 获取结算数据 22 | List checkOutData = await CartService.getCheckOutData(); 23 | // 保存选中数据 24 | this._checkOutProvider.changeCheckOutListData(checkOutData); 25 | // 购物车是否有选中的数据 26 | if (checkOutData.length > 0) { 27 | // 判断用户是否登陆 28 | bool userLoginState = await UserServices.getUserState(); 29 | if (userLoginState) { 30 | Navigator.pushNamed(context, "/checkOut"); 31 | } else { 32 | Fluttertoast.showToast( msg: "请先登陆再结算", toastLength: Toast.LENGTH_SHORT,gravity: ToastGravity.CENTER); 33 | Navigator.pushNamed(context, "/login"); 34 | } 35 | } else { 36 | Fluttertoast.showToast( msg: "没有选中商品哦", toastLength: Toast.LENGTH_SHORT,gravity: ToastGravity.CENTER); 37 | } 38 | } 39 | 40 | // 是否编辑状态支持删除 41 | bool _isEdit = false; 42 | 43 | @override 44 | void initState() { 45 | // TODO: implement initState 46 | super.initState(); 47 | } 48 | 49 | @override 50 | Widget build(BuildContext context) { 51 | ScreenAdaper.init(context); 52 | 53 | // 获取通知提供的值: 全选按钮 54 | CartProvider cartProvider = Provider.of(context); 55 | // 获取结算页面的值 56 | this._checkOutProvider = Provider.of(context); 57 | 58 | return Scaffold( 59 | appBar: AppBar( 60 | title: Text("购物车"), 61 | actions: [ 62 | IconButton( 63 | icon: this._isEdit == false ? Icon(Icons.edit) : Icon(Icons.done), 64 | onPressed: () { 65 | // 点击后处于编辑状态 66 | setState(() { 67 | this._isEdit = !this._isEdit; 68 | }); 69 | }, 70 | ) 71 | ], 72 | ), 73 | // 判断列表数量是否大于0 74 | body: cartProvider.cartList.length > 0 ? Stack(// 上ListView 下Position 75 | children: [ 76 | 77 | // 商品·列表 78 | ListView( 79 | children: [ 80 | // 加入Column, 商品数量多时候不会被全选按钮覆盖 81 | Column( 82 | children: cartProvider.cartList.map((value){ 83 | return CartItem(value); 84 | }).toList(), 85 | ), 86 | 87 | // 和全选按钮来点距离 88 | SizedBox(height: ScreenAdaper.height(100)) 89 | ], 90 | ), 91 | 92 | // 底部按钮条 93 | Positioned( 94 | bottom: 0, 95 | width: ScreenAdaper.width(750), 96 | height: ScreenAdaper.height(78), 97 | child: Container( 98 | width: ScreenAdaper.width(750), 99 | height: ScreenAdaper.height(78), 100 | 101 | // 顶部线条 102 | decoration: BoxDecoration( 103 | border: Border( 104 | top: BorderSide( 105 | width: ScreenAdaper.width(2), 106 | color: Colors.black12 107 | ) 108 | ), 109 | color: Colors.white 110 | ), 111 | 112 | // 左全选 右结算 113 | child: Stack( 114 | children: [ 115 | // 全选 116 | Align( 117 | alignment: Alignment.centerLeft, 118 | child: Row(// 左单选框 右文本 119 | children: [ 120 | // 单选框 121 | Container( 122 | width: ScreenAdaper.width(60), 123 | child: Checkbox( 124 | value: cartProvider.isCheckAll, 125 | activeColor: Colors.pink, 126 | onChanged: (value) { 127 | // 实现全选反选 128 | cartProvider.checkAll(value); 129 | }, 130 | ), 131 | ), 132 | // 文本 133 | Text("全选"), 134 | SizedBox(width: 20), 135 | this._isEdit == false ? Text("合计:") : Text(""), 136 | this._isEdit == false ? Text("¥ ${cartProvider.allPrice}",style: TextStyle(color: Colors.red)) : Text("") 137 | ], 138 | ), 139 | ), 140 | 141 | // 结算 142 | this._isEdit == false ? Align( 143 | alignment: Alignment.centerRight, 144 | child: ElevatedButton( 145 | child: Text("结算",style: TextStyle(color: Colors.white)), 146 | onPressed: doCheckOut, 147 | style: ElevatedButton.styleFrom( 148 | backgroundColor: Colors.red, 149 | ), 150 | ), 151 | ) : Align( 152 | alignment: Alignment.centerRight, 153 | child: ElevatedButton( 154 | child: Text("删除",style: TextStyle(color: Colors.white)), 155 | style: ElevatedButton.styleFrom( 156 | backgroundColor: Colors.red, 157 | ), 158 | onPressed: () { 159 | // 删除数据 160 | cartProvider.removeItem(); 161 | }, 162 | ), 163 | ), 164 | ], 165 | ), 166 | ), 167 | ) 168 | ], 169 | 170 | ):Center( 171 | child: Text("购物车是空的..."), 172 | ) 173 | ); 174 | } 175 | } -------------------------------------------------------------------------------- /lib/pages/tabs/Tabs.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/cupertino.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:jdshop_app/pages/tabs/Cart.dart'; 4 | import 'package:jdshop_app/pages/tabs/Category.dart'; 5 | import 'package:jdshop_app/pages/tabs/Home.dart'; 6 | import 'package:jdshop_app/pages/tabs/User.dart'; 7 | import 'package:jdshop_app/services/ScreenAdaper.dart'; 8 | 9 | class Tabs extends StatefulWidget { 10 | Tabs({Key key}) : super(key: key); 11 | 12 | @override 13 | _TabsState createState() => _TabsState(); 14 | } 15 | 16 | class _TabsState extends State { 17 | // 默认加载分类页面 18 | int _currentIndex = 0; 19 | 20 | List _pageList = [ 21 | HomePage(), 22 | CategoryPage(), 23 | CartPage(), 24 | UserPage(), 25 | ]; 26 | 27 | // 部分页面缓存部分页面重新加载 28 | var _pageController; 29 | @override 30 | void initState() { 31 | // TODO: implement initState 32 | super.initState(); 33 | // 初始化 34 | this._pageController = new PageController(initialPage: this._currentIndex); 35 | } 36 | 37 | @override 38 | Widget build(BuildContext context) { 39 | ScreenAdaper.init(context); 40 | 41 | return Scaffold( 42 | 43 | //body: this._pageList[this._currentIndex], 44 | /* 45 | //优点:层叠组件,切换TAB时候不用重新请求接口,实现状态保持,不会重新刷新页面 46 | //缺点:刚开始一次性加载四个页面,根据_currentIndex决定显示哪个, 所以切换到购物车时候不会重新请求刷新数据 47 | body: IndexedStack( 48 | index: this._currentIndex, 49 | children: this._pageList 50 | ), 51 | */ 52 | // 部分页面缓存部分页面重新加载 53 | body: PageView(// 实现页面加载 54 | controller: this._pageController, 55 | children: this._pageList, 56 | onPageChanged: (index){// 手左右滑动的索引值 57 | // 让底部Tab也对应选中 58 | setState(() { 59 | this._currentIndex = index; 60 | }); 61 | }, 62 | // 禁止手左右滑动 63 | // physics: NeverScrollableScrollPhysics(), 64 | ), 65 | bottomNavigationBar: BottomNavigationBar( 66 | currentIndex: this._currentIndex, 67 | onTap: (index) { 68 | setState(() { 69 | this._currentIndex = index; 70 | // 实现页面切换 71 | this._pageController.jumpToPage(index); 72 | }); 73 | }, 74 | type: BottomNavigationBarType.fixed, 75 | fixedColor: Colors.red, 76 | items: [ 77 | BottomNavigationBarItem( 78 | icon: Icon(Icons.home), 79 | label: "首页" 80 | ), 81 | BottomNavigationBarItem( 82 | icon: Icon(Icons.category), 83 | label: "分类" 84 | ), 85 | BottomNavigationBarItem( 86 | icon: Icon(Icons.shopping_cart), 87 | label: "购物车" 88 | ), 89 | BottomNavigationBarItem( 90 | icon: Icon(Icons.people), 91 | label: "我的" 92 | ) 93 | ], 94 | ), 95 | ); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /lib/pages/tabs/User.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:jdshop_app/provider/CartProvider.dart'; 3 | import 'package:jdshop_app/services/EventsBus.dart'; 4 | import 'package:jdshop_app/services/ScreenAdaper.dart'; 5 | import 'package:jdshop_app/services/UserServices.dart'; 6 | import 'package:jdshop_app/widget/JDButton.dart'; 7 | import 'package:provider/provider.dart'; 8 | 9 | class UserPage extends StatefulWidget { 10 | @override 11 | _UserPageState createState() => _UserPageState(); 12 | } 13 | 14 | class _UserPageState extends State { 15 | 16 | // 判断用户是否登陆 17 | bool _isLogin = false; 18 | List _userInfo = []; 19 | @override 20 | void initState() { 21 | // TODO: implement initState 22 | super.initState(); 23 | this._getUserInfo(); 24 | 25 | // 监听登陆界面的广播事件 26 | eventBus.on().listen((event){ 27 | print("object"); 28 | print(event.str); 29 | // 重新获取用户信息,因为不会子页面返回不会触发init 30 | this._getUserInfo(); 31 | }); 32 | } 33 | _getUserInfo() async { 34 | var isLogin = await UserServices.getUserState(); 35 | var userInfo = await UserServices.getUserInfo(); 36 | setState(() { 37 | this._userInfo = userInfo; 38 | this._isLogin = isLogin; 39 | }); 40 | } 41 | 42 | @override 43 | Widget build(BuildContext context) { 44 | // 获取通知提供的值: 全选按钮 45 | 46 | var counterProvider = Provider.of(context); 47 | 48 | return Scaffold( 49 | // 操作列表: ListView当太多操作的时候支持滑动 50 | body: ListView( 51 | children: [ 52 | Container( 53 | height: ScreenAdaper.height(220), 54 | width: double.infinity, 55 | // 背景图片 56 | decoration: BoxDecoration( 57 | image: DecorationImage( 58 | image: AssetImage("images/user_bg.jpg"), 59 | fit: BoxFit.cover 60 | ) 61 | ), 62 | child: Row( 63 | children: [ 64 | // 头像 65 | Container(// 可以给左右来点间距 66 | margin: EdgeInsets.fromLTRB(10, 0, 10, 0), 67 | child: ClipOval( 68 | // child: Image.asset('images/user.png',fit: BoxFit.cover,width: ScreenAdaper.width(100),height: ScreenAdaper.height(100)), 69 | child: Image.network("http://i0.hdslb.com/bfs/article/0d3f17d197577d794d70a8dc874d4f0b92fe795c.jpg",fit: BoxFit.cover,width: ScreenAdaper.width(100),height: ScreenAdaper.height(100)), 70 | ), 71 | ), 72 | 73 | this._isLogin ? Expanded( 74 | flex: 1, 75 | child: Column( 76 | mainAxisAlignment: MainAxisAlignment.center, 77 | crossAxisAlignment: CrossAxisAlignment.start, 78 | children: [ 79 | Text("用户名:${this._userInfo[0]["username"]}", style: TextStyle(color: Colors.white, fontSize: ScreenAdaper.fontSize(32))), 80 | Text("普通会员", style: TextStyle( color: Colors.white, fontSize: ScreenAdaper.fontSize(24))), 81 | ], 82 | ), 83 | ) : Expanded( 84 | flex: 1, 85 | child: InkWell( 86 | onTap: () { 87 | Navigator.pushNamed(context, "/login"); 88 | }, 89 | child: Text("登陆/注册", style: TextStyle(color: Colors.white)), 90 | ), 91 | ) 92 | ], 93 | ), 94 | ), 95 | 96 | ListTile( 97 | leading: Icon(Icons.assignment, color: Colors.red), 98 | title: Text("全部订单"), 99 | onTap: () { 100 | Navigator.pushNamed(context, "/order"); 101 | }, 102 | ), 103 | Divider(), 104 | ListTile( 105 | leading: Icon(Icons.payment, color: Colors.green), 106 | title: Text("待付款"), 107 | ), 108 | Divider(), 109 | ListTile( 110 | leading: Icon(Icons.local_car_wash, color: Colors.orange), 111 | title: Text("待收货"), 112 | ), 113 | Container( 114 | width: double.infinity, 115 | height: 10, 116 | color: Color.fromRGBO(242, 242, 242, 0.9)), 117 | ListTile( 118 | leading: Icon(Icons.favorite, color: Colors.lightGreen), 119 | title: Text("我的收藏"), 120 | ), 121 | Divider(), 122 | ListTile( 123 | leading: Icon(Icons.people, color: Colors.black54), 124 | title: Text("在线客服"), 125 | ), 126 | Divider(), 127 | 128 | // 退出登陆 129 | this._isLogin ? JDButton( 130 | buttonTitle: "退出登陆", 131 | buttonColor: Colors.red, 132 | tapEvent: () { 133 | UserServices.loginOut(); 134 | this._getUserInfo(); 135 | }, 136 | ) : Text("") 137 | ], 138 | ), 139 | ); 140 | } 141 | } -------------------------------------------------------------------------------- /lib/provider/CartProvider.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:jdshop_app/services/Storage.dart'; 5 | 6 | // Provider: 存放购物车数据,存放全选状态 7 | class CartProvider with ChangeNotifier { 8 | List _cartList = []; 9 | // 底部Num 10 | int get cartNum=>this._cartList.length; 11 | // 列表 12 | List get cartList=>this._cartList; 13 | 14 | // 初始化赋值,获取购物车数据 15 | CartProvider(){ 16 | this.init(); 17 | } 18 | 19 | init() async { 20 | // 判断有无数据 21 | try { 22 | this._cartList = json.decode(await Storage.getString("cartList")); 23 | } catch (error) { 24 | // 无数据则置为空 25 | this._cartList = []; 26 | } 27 | 28 | // 获取是否第一次全选 29 | this._isCheckAll = this.isFirstCheckAll(); 30 | 31 | //计算总价 32 | this.computeAllPrice(); 33 | 34 | // 通知其他组件更新数据 35 | notifyListeners(); 36 | } 37 | 38 | // 更新列表数据 39 | updateCartList() { 40 | init(); 41 | } 42 | 43 | // 全选 44 | bool _isCheckAll = false; 45 | // 获取私有属性 46 | bool get isCheckAll=>this._isCheckAll; 47 | // 全选反选 48 | checkAll(value) async { 49 | this._cartList.forEach((item) { 50 | item["checked"] = value; 51 | }); 52 | this._isCheckAll = value; 53 | //计算总价 54 | this.computeAllPrice(); 55 | await Storage.setString("cartList", json.encode(this._cartList)); 56 | notifyListeners(); 57 | } 58 | // 判断刚进入页面时候是否处于全选状态 59 | bool isFirstCheckAll() { 60 | if (this._cartList.length > 0) { 61 | for (var i = 0; i < this._cartList.length; i++) { 62 | if (this._cartList[i]["checked"] == false) { 63 | return false; 64 | } 65 | } 66 | return true; 67 | } else { 68 | return false; 69 | } 70 | } 71 | 72 | // + - 后将数据保存到本地 73 | // 监听每一项的选中事件,使列表和全选按钮保持同步 74 | itemChange() async { 75 | if (this.isFirstCheckAll()) { 76 | this._isCheckAll = true; 77 | } else { 78 | this._isCheckAll = false; 79 | } 80 | // 计算总价 81 | this.computeAllPrice(); 82 | await Storage.setString("cartList", json.encode(this._cartList)); 83 | // 通知其他页面更新 84 | notifyListeners(); 85 | } 86 | 87 | itemCountChange() { 88 | Storage.setString("cartList", json.encode(this._cartList)); 89 | //计算总价 90 | this.computeAllPrice(); 91 | 92 | notifyListeners(); 93 | } 94 | 95 | // 删除商品 96 | removeItem() async { 97 | List tempList = []; 98 | for (var i = 0; i < this._cartList.length; i++) { 99 | if (this._cartList[i]["checked"] == false) { 100 | // ['1111','2222','333333333','4444444444'] 101 | // 数组删除后会向前移动一位,导致删除2222(索引1)后,再删除(索引2)就会变成删除444444 102 | // this._cartList.removeAt(i); 103 | 104 | tempList.add(this._cartList[i]); 105 | } 106 | } 107 | this._cartList = tempList; 108 | // 计算总价 109 | this.computeAllPrice(); 110 | await Storage.setString("cartList", json.encode(this._cartList)); 111 | // 通知其他页面更新 112 | notifyListeners(); 113 | } 114 | 115 | // 总价 116 | double _allPrice = 0; //总价 117 | double get allPrice => this._allPrice; 118 | // 计算总价 119 | computeAllPrice() { 120 | double tempAllPrice = 0; 121 | for (var i = 0; i < this._cartList.length; i++) { 122 | if (this._cartList[i]["checked"] == true) { 123 | tempAllPrice += this._cartList[i]["price"] * this._cartList[i]["count"]; 124 | } 125 | } 126 | this._allPrice = tempAllPrice; 127 | 128 | notifyListeners(); 129 | } 130 | } -------------------------------------------------------------------------------- /lib/provider/CheckOutProvider.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class CheckOutProvider with ChangeNotifier { 4 | List _checkOutListData = []; //购物车数据 5 | List get checkOutListData => this._checkOutListData; 6 | 7 | changeCheckOutListData(data){ 8 | this._checkOutListData = data; 9 | notifyListeners(); 10 | } 11 | 12 | } -------------------------------------------------------------------------------- /lib/provider/Counter.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class Counter with ChangeNotifier{ 4 | 5 | int _count=1; //状态 6 | 7 | Counter(){ 8 | this._count=10; 9 | } 10 | 11 | int get count=>_count; //获取状态 12 | 13 | intCount(){ //更新状态 14 | this._count++; 15 | notifyListeners(); //表示更新状态 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /lib/routers/router.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:jdshop_app/address/AddressAdd.dart'; 3 | import 'package:jdshop_app/address/AddressEdit.dart'; 4 | import 'package:jdshop_app/address/AddressList.dart'; 5 | import 'package:jdshop_app/pages/login/Login.dart'; 6 | import 'package:jdshop_app/pages/login/RegisterFirst.dart'; 7 | import 'package:jdshop_app/pages/login/RegisterSecond.dart'; 8 | import 'package:jdshop_app/pages/login/RegisterThird.dart'; 9 | import 'package:jdshop_app/pages/productContent/CheckOut.dart'; 10 | import 'package:jdshop_app/pages/productContent/Order.dart'; 11 | import 'package:jdshop_app/pages/productContent/OrderInfo.dart'; 12 | import 'package:jdshop_app/pages/productContent/Pay.dart'; 13 | import 'package:jdshop_app/pages/productContent/ProductContent.dart'; 14 | import 'package:jdshop_app/pages/tabs/Cart.dart'; 15 | import 'package:jdshop_app/pages/tabs/ProductList.dart'; 16 | import 'package:jdshop_app/pages/tabs/Search.dart'; 17 | import 'package:jdshop_app/pages/tabs/Tabs.dart'; 18 | 19 | //配置路由 20 | final routes = { 21 | '/': (context) => Tabs(), 22 | '/cart':(context) => CartPage(), 23 | '/login':(context) => LoginPage(), 24 | '/registerFirst':(context) => RegisterFirstPage(), 25 | '/registerSecond': (context,{arguments}) => RegisterSecondPage(arguments: arguments), 26 | '/registerThird':(context,{arguments}) => RegisterThirdPage(arguments: arguments), 27 | '/search': (context) => SearchPage(), 28 | '/productList': (context,{arguments}) => ProductListPage(arguments:arguments), 29 | '/productContent': (context,{arguments}) => ProductContentPage(arguments:arguments), 30 | '/checkOut': (context) => CheckOutPage(), 31 | '/addressAdd': (context) => AddressAddPage(), 32 | '/addressEdit': (context,{arguments}) => AddressEditPage(arguments:arguments), 33 | '/addressList': (context) => AddressListPage(), 34 | '/pay': (context) => PayPage(), 35 | '/order': (context) => OrderPage(), 36 | '/orderinfo': (context) => OrderInfoPage(), 37 | }; 38 | 39 | //固定写法 40 | var onGenerateRoute = (RouteSettings settings) { 41 | // 统一处理 42 | final String name = settings.name; 43 | final Function pageContentBuilder = routes[name]; 44 | if (pageContentBuilder != null) { 45 | if (settings.arguments != null) { 46 | final Route route = MaterialPageRoute( 47 | builder: (context) => 48 | pageContentBuilder(context, arguments: settings.arguments)); 49 | return route; 50 | } else { 51 | final Route route = 52 | MaterialPageRoute(builder: (context) => pageContentBuilder(context)); 53 | return route; 54 | } 55 | } 56 | }; 57 | -------------------------------------------------------------------------------- /lib/services/CartService.dart: -------------------------------------------------------------------------------- 1 | // 服务类:涉及增加、删除购物车数据 2 | import 'dart:convert'; 3 | 4 | import 'package:jdshop_app/config/Config.dart'; 5 | import 'package:jdshop_app/services/Storage.dart'; 6 | 7 | class CartService { 8 | 9 | // 获取购物车选中的数据 10 | static getCheckOutData() async { 11 | // 全部数据 12 | List cartListData = []; 13 | try { 14 | cartListData = json.decode(await Storage.getString('cartList')); 15 | } catch (e) { 16 | cartListData = []; 17 | } 18 | 19 | // 筛选选中数据 20 | List tempCheckOutData = []; 21 | for (var i = 0; i < cartListData.length; i++) { 22 | if (cartListData[i]["checked"] == true) { 23 | tempCheckOutData.add(cartListData[i]); 24 | } 25 | } 26 | return tempCheckOutData; 27 | } 28 | 29 | // 加入购物车: 本地加入有点类似保存历史记录,远端加入只需要上传和重新请求 30 | static addCart(item) async { 31 | // 把对象转换成Map类型的数据 32 | item = CartService.formatCartData(item); 33 | 34 | // 类似本地缓存历史记录 35 | try { 36 | List cartListData = json.decode(await Storage.getString('cartList')); 37 | // 是否有当前类型的数据 38 | bool hasData = cartListData.any((value){ 39 | // 相同ID的商品由于属性不一样,也要另外添加一行 40 | if (item['_id'] == value['_id'] && item['selectedAttr'] == value['selectedAttr']) { 41 | return true; 42 | } 43 | return false; 44 | }); 45 | if (hasData) { 46 | for(var i=0;i(); 75 | // 唯一ID用于删除添加 76 | data['_id'] = item.sId; 77 | data['title'] = item.title; 78 | 79 | // 处理string和int类型的购物出价格 80 | if (item.price is int || item.price is double) { 81 | data['price'] = item.price; 82 | } else { 83 | data['price'] = double.parse(item.price); 84 | } 85 | 86 | data['selectedAttr'] = item.selectedAttr; 87 | data['count'] = item.count; 88 | data['pic'] = sPic; 89 | 90 | //是否选中,默认加入购物车即选中 91 | data['checked'] = true; 92 | 93 | return data; 94 | } 95 | } 96 | 97 | 98 | /* 99 | 1、获取本地存储的cartList数据 100 | 2、判断cartList是否有数据 101 | 有数据: 102 | 1、判断购物车有没有当前数据: 103 | 有当前数据: 104 | 1、让购物车中的当前数据数量 等于以前的数量+现在的数量 105 | 2、重新写入本地存储 106 | 107 | 没有当前数据: 108 | 1、把购物车cartList的数据和当前数据拼接,拼接后重新写入本地存储。 109 | 110 | 没有数据: 111 | 1、把当前商品数据以及属性数据放在数组中然后写入本地存储 112 | 113 | 114 | 115 | List list=[ 116 | {"_id": "1", 117 | "title": "磨砂牛皮男休闲鞋-有属性", 118 | "price": 688, 119 | "selectedAttr": "牛皮 ,系带,黄色", 120 | "count": 4, 121 | "pic":"public\upload\RinsvExKu7Ed-ocs_7W1DxYO.png", 122 | "checked": true 123 | }, 124 | {"_id": "2", 125 | "title": "磨xxxxxxxxxxxxx", 126 | "price": 688, 127 | "selectedAttr": "牛皮 ,系带,黄色", 128 | "count": 2, 129 | "pic":"public\upload\RinsvExKu7Ed-ocs_7W1DxYO.png", 130 | "checked": true 131 | } 132 | 133 | ]; 134 | 135 | 136 | */ -------------------------------------------------------------------------------- /lib/services/CheckOutServices.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:jdshop_app/services/Storage.dart'; 4 | 5 | class CheckOutServices{ 6 | //计算总价 7 | static getAllPrice(checkOutListData) { 8 | var tempAllPrice=0.0; 9 | for (var i = 0; i < checkOutListData.length; i++) { 10 | if (checkOutListData[i]["checked"] == true) { 11 | tempAllPrice += checkOutListData[i]["price"] * checkOutListData[i]["count"]; 12 | } 13 | } 14 | return tempAllPrice; 15 | } 16 | static removeUnSelectedCartItem() async{ 17 | List _cartList=[]; 18 | List _tempList=[]; 19 | 20 | //获取购物车的数据 21 | try { 22 | List cartListData = json.decode(await Storage.getString('cartList')); 23 | _cartList = cartListData; 24 | } catch (error) { 25 | _cartList = []; 26 | } 27 | 28 | for (var i = 0; i < _cartList.length; i++) { 29 | if (_cartList[i]["checked"] == false) { 30 | _tempList.add(_cartList[i]); 31 | } 32 | } 33 | 34 | Storage.setString("cartList", json.encode(_tempList)); 35 | } 36 | } -------------------------------------------------------------------------------- /lib/services/Counter.dart: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/lib/services/Counter.dart -------------------------------------------------------------------------------- /lib/services/EventsBus.dart: -------------------------------------------------------------------------------- 1 | import 'package:event_bus/event_bus.dart'; 2 | 3 | EventBus eventBus = EventBus(); 4 | 5 | // 购物车广播 6 | class ProductContentEvent { 7 | String str; 8 | ProductContentEvent(String str) { 9 | this.str = str; 10 | } 11 | } 12 | 13 | // 用户中心广播 14 | class UserEvent { 15 | String str; 16 | UserEvent(String str) { 17 | this.str = str; 18 | } 19 | } 20 | 21 | // 增加地址广播 22 | class AddressEvent { 23 | String str; 24 | AddressEvent(String str) { 25 | this.str = str; 26 | } 27 | } 28 | 29 | // 默认地址广播 30 | class DefaultAddressEvent { 31 | String str; 32 | DefaultAddressEvent(String str) { 33 | this.str = str; 34 | } 35 | } -------------------------------------------------------------------------------- /lib/services/ScreenAdaper.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_screenutil/flutter_screenutil.dart'; 2 | 3 | // 封装静态宽、高方法,直接通过类名称来访问 4 | class ScreenAdaper { 5 | 6 | // 解决Flutter 不同终端屏幕适配问题,传入context和设计稿子上的宽高 7 | static init(context) { 8 | ScreenUtil.init(context, width: 750, height: 1334); 9 | } 10 | 11 | // 获取计算后的高度: 传入int 转化为 double 12 | static height(double value) { 13 | return ScreenUtil().setHeight(value); 14 | } 15 | 16 | // 获取计算后的宽度 17 | static width(double value) { 18 | return ScreenUtil().setWidth(value); 19 | } 20 | 21 | // 获取屏幕高度 22 | static getScreenHeight() { 23 | return ScreenUtil.screenHeightDp; 24 | } 25 | 26 | // 获取屏幕宽度 27 | static getScreenWidth(){ 28 | return ScreenUtil.screenWidthDp; 29 | } 30 | 31 | // 获取字体大小 32 | static fontSize(double value) { 33 | return ScreenUtil().setSp(value); 34 | } 35 | } -------------------------------------------------------------------------------- /lib/services/SearchServices.dart: -------------------------------------------------------------------------------- 1 | import 'package:jdshop_app/services/Storage.dart'; 2 | import 'dart:convert'; 3 | 4 | class SearchServices { 5 | // 保存历史搜索记录到本地缓存里 6 | static setHistoryData(keywords) async { 7 | /* 8 | 1、获取本地存储里面的数据 (searchList) 9 | 2、判断本地存储是否有数据 10 | 2.1、如果有数据 11 | 1、读取本地存储的数据 12 | 2、判断本地存储中有没有当前数据, 13 | 如果有不做操作、 14 | 如果没有当前数据,本地存储的数据和当前数据拼接后重新写入 15 | 2.2、如果没有数据 16 | 直接把当前数据放在数组中写入到本地存储 17 | */ 18 | try { 19 | // 将json字符串转化为map数组 20 | List searchListData = json.decode(await Storage.getString('searchList')); 21 | 22 | // 判断本地存储是否有数据: 判断数组中是否有某个值 23 | var hasKeywords = searchListData.any((value) { 24 | return value == keywords; 25 | }); 26 | 27 | // 如果没有当前数据:本地存储的数据和当前数据拼接后重新写入 28 | if (!hasKeywords) { 29 | searchListData.add(keywords); 30 | await Storage.setString('searchList', json.encode(searchListData)); 31 | } 32 | } catch (error) {// 获取不到数据,为空 33 | // 直接把当前数据放在数组中写入到本地存储 34 | List tempList = new List(); 35 | tempList.add(keywords); 36 | // 将数组转化为字符串 37 | await Storage.setString('searchList', json.encode(tempList)); 38 | } 39 | 40 | } 41 | // 从本地缓存里取出历史搜索记录 42 | static getHistoryData() async { 43 | try { 44 | List searchListData = json.decode(await Storage.getString('searchList')); 45 | return searchListData; 46 | } catch(error) { 47 | return [];// 无数据返回空数组 48 | } 49 | } 50 | 51 | // 清空历史记录 52 | static clearHistoryList() async{ 53 | await Storage.remove('searchList'); 54 | } 55 | 56 | // 长按删除某条历史记录 57 | static removeHistoryData(keywords) async{ 58 | List searchListData = json.decode(await Storage.getString('searchList')); 59 | searchListData.remove(keywords); 60 | await Storage.setString('searchList', json.encode(searchListData)); 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /lib/services/SignServices.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'package:crypto/crypto.dart'; 3 | 4 | class SignServices { 5 | static getSign(json) { 6 | // Map addressListAttr={ 7 | // "uid":'1', 8 | // "age":10, 9 | // "salt":'xxxxxxxxxxxxxx' //私钥 10 | // }; 11 | List attrKeys = json.keys.toList(); 12 | attrKeys.sort(); 13 | 14 | String str=''; 15 | for(var i = 0; i < attrKeys.length; i++){ 16 | str += "${attrKeys[i]}${json[attrKeys[i]]}"; 17 | } 18 | return md5.convert(utf8.encode(str)).toString(); 19 | } 20 | } -------------------------------------------------------------------------------- /lib/services/Storage.dart: -------------------------------------------------------------------------------- 1 | import 'package:shared_preferences/shared_preferences.dart'; 2 | 3 | class Storage{ 4 | 5 | static Future setString(key,value) async{ 6 | SharedPreferences sp=await SharedPreferences.getInstance(); 7 | sp.setString(key, value); 8 | } 9 | static Future getString(key) async{ 10 | SharedPreferences sp=await SharedPreferences.getInstance(); 11 | return sp.getString(key); 12 | } 13 | static Future remove(key) async{ 14 | SharedPreferences sp=await SharedPreferences.getInstance(); 15 | sp.remove(key); 16 | } 17 | static Future clear() async{ 18 | SharedPreferences sp=await SharedPreferences.getInstance(); 19 | sp.clear(); 20 | } 21 | 22 | 23 | } -------------------------------------------------------------------------------- /lib/services/UserServices.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'package:jdshop_app/services/Storage.dart'; 3 | 4 | class UserServices { 5 | // 获取用户信息 6 | static getUserInfo() async { 7 | List userInfo; 8 | try { 9 | userInfo = json.decode(await Storage.getString('userInfo')); 10 | } catch (error) { 11 | userInfo = []; 12 | } 13 | return userInfo; 14 | } 15 | 16 | // 获取用户登陆状态 17 | static getUserState() async { 18 | List userInfo = await UserServices.getUserInfo(); 19 | if (userInfo.length > 0 && userInfo[0]["username"] != "") { 20 | return true; 21 | } 22 | return false; 23 | } 24 | 25 | // 退出登陆 26 | static loginOut() async { 27 | Storage.remove("userInfo"); 28 | } 29 | } -------------------------------------------------------------------------------- /lib/widget/JDButton.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:jdshop_app/services/ScreenAdaper.dart'; 3 | 4 | class JDButton extends StatelessWidget { 5 | final Color buttonColor; 6 | final String buttonTitle; 7 | final Object tapEvent; 8 | final double height; 9 | // 默认构造函数: 不能用下划线 10 | JDButton({Key key, this.buttonColor = Colors.black, this.buttonTitle = "按钮",this.height = 68, this.tapEvent = null}) : super(key: key); 11 | 12 | @override 13 | Widget build(BuildContext context) { 14 | ScreenAdaper.init(context); 15 | 16 | return InkWell( 17 | onTap: this.tapEvent, 18 | child: Container( 19 | margin: EdgeInsets.all(5), 20 | padding: EdgeInsets.all(5), 21 | height: ScreenAdaper.height(this.height), 22 | width: double.infinity, 23 | // 边框 24 | decoration: BoxDecoration( 25 | color: this.buttonColor, 26 | borderRadius: BorderRadius.circular(10) 27 | ), 28 | child: Center( 29 | child: Text("${this.buttonTitle}",style: TextStyle(color: Colors.white)), 30 | ), 31 | ), 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lib/widget/JDText.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter/rendering.dart'; 3 | import 'package:jdshop_app/services/ScreenAdaper.dart'; 4 | 5 | class JdText extends StatelessWidget { 6 | 7 | // final常量 8 | final String text; 9 | final bool password; 10 | final Object onChanged; 11 | final int maxLines; 12 | final double height; 13 | final TextEditingController controller; 14 | JdText({Key key,this.text="输入内容",this.password=false,this.onChanged=null,this.maxLines=1,this.height=68,this.controller=null}) : super(key: key); 15 | 16 | @override 17 | Widget build(BuildContext context) { 18 | return Container( 19 | height: ScreenAdaper.height(this.height), 20 | 21 | // 文本框 22 | child: TextField( 23 | controller: controller, 24 | maxLines: this.maxLines, 25 | obscureText: this.password, 26 | decoration: InputDecoration( 27 | hintText: this.text, 28 | border: OutlineInputBorder( 29 | borderRadius: BorderRadius.circular(30), 30 | borderSide: BorderSide.none)), 31 | onChanged: this.onChanged, 32 | ), 33 | 34 | // 底部线条 35 | decoration: BoxDecoration( 36 | border: Border( 37 | bottom: BorderSide( 38 | width: 1, 39 | color: Colors.black12 40 | ) 41 | ) 42 | ), 43 | ); 44 | } 45 | } -------------------------------------------------------------------------------- /lib/widget/LoadingWidget.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | class LoadingWidget extends StatelessWidget { 3 | const LoadingWidget({Key key}) : super(key: key); 4 | 5 | @override 6 | Widget build(BuildContext context) { 7 | return Center( 8 | child: Padding( 9 | padding: EdgeInsets.all(10.0), 10 | child: Row( 11 | mainAxisAlignment: MainAxisAlignment.center, 12 | crossAxisAlignment: CrossAxisAlignment.center, 13 | children: [ 14 | CircularProgressIndicator( 15 | strokeWidth: 1.0, 16 | ),Text( 17 | '加载中...', 18 | style: TextStyle(fontSize: 16.0), 19 | ) 20 | ], 21 | ), 22 | ), 23 | );; 24 | } 25 | } -------------------------------------------------------------------------------- /linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project-level configuration. 2 | cmake_minimum_required(VERSION 3.10) 3 | project(runner LANGUAGES CXX) 4 | 5 | # The name of the executable created for the application. Change this to change 6 | # the on-disk name of your application. 7 | set(BINARY_NAME "jdshop_flutter") 8 | # The unique GTK application identifier for this application. See: 9 | # https://wiki.gnome.org/HowDoI/ChooseApplicationID 10 | set(APPLICATION_ID "com.xiejiapei.jdshop_flutter.jdshop_flutter") 11 | 12 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 13 | # versions of CMake. 14 | cmake_policy(SET CMP0063 NEW) 15 | 16 | # Load bundled libraries from the lib/ directory relative to the binary. 17 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") 18 | 19 | # Root filesystem for cross-building. 20 | if(FLUTTER_TARGET_PLATFORM_SYSROOT) 21 | set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) 22 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) 23 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 24 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 25 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 26 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 27 | endif() 28 | 29 | # Define build configuration options. 30 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 31 | set(CMAKE_BUILD_TYPE "Debug" CACHE 32 | STRING "Flutter build mode" FORCE) 33 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 34 | "Debug" "Profile" "Release") 35 | endif() 36 | 37 | # Compilation settings that should be applied to most targets. 38 | # 39 | # Be cautious about adding new options here, as plugins use this function by 40 | # default. In most cases, you should add new options to specific targets instead 41 | # of modifying this function. 42 | function(APPLY_STANDARD_SETTINGS TARGET) 43 | target_compile_features(${TARGET} PUBLIC cxx_std_14) 44 | target_compile_options(${TARGET} PRIVATE -Wall -Werror) 45 | target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") 46 | target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") 47 | endfunction() 48 | 49 | # Flutter library and tool build rules. 50 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 51 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 52 | 53 | # System-level dependencies. 54 | find_package(PkgConfig REQUIRED) 55 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 56 | 57 | add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") 58 | 59 | # Define the application target. To change its name, change BINARY_NAME above, 60 | # not the value here, or `flutter run` will no longer work. 61 | # 62 | # Any new source files that you add to the application should be added here. 63 | add_executable(${BINARY_NAME} 64 | "main.cc" 65 | "my_application.cc" 66 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 67 | ) 68 | 69 | # Apply the standard set of build settings. This can be removed for applications 70 | # that need different build settings. 71 | apply_standard_settings(${BINARY_NAME}) 72 | 73 | # Add dependency libraries. Add any application-specific dependencies here. 74 | target_link_libraries(${BINARY_NAME} PRIVATE flutter) 75 | target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) 76 | 77 | # Run the Flutter tool portions of the build. This must not be removed. 78 | add_dependencies(${BINARY_NAME} flutter_assemble) 79 | 80 | # Only the install-generated bundle's copy of the executable will launch 81 | # correctly, since the resources must in the right relative locations. To avoid 82 | # people trying to run the unbundled copy, put it in a subdirectory instead of 83 | # the default top-level location. 84 | set_target_properties(${BINARY_NAME} 85 | PROPERTIES 86 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" 87 | ) 88 | 89 | # Generated plugin build rules, which manage building the plugins and adding 90 | # them to the application. 91 | include(flutter/generated_plugins.cmake) 92 | 93 | 94 | # === Installation === 95 | # By default, "installing" just makes a relocatable bundle in the build 96 | # directory. 97 | set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") 98 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 99 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 100 | endif() 101 | 102 | # Start with a clean build bundle directory every time. 103 | install(CODE " 104 | file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") 105 | " COMPONENT Runtime) 106 | 107 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 108 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") 109 | 110 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 111 | COMPONENT Runtime) 112 | 113 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 114 | COMPONENT Runtime) 115 | 116 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 117 | COMPONENT Runtime) 118 | 119 | foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) 120 | install(FILES "${bundled_library}" 121 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 122 | COMPONENT Runtime) 123 | endforeach(bundled_library) 124 | 125 | # Fully re-copy the assets directory on each build to avoid having stale files 126 | # from a previous install. 127 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 128 | install(CODE " 129 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 130 | " COMPONENT Runtime) 131 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 132 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 133 | 134 | # Install the AOT library on non-Debug builds only. 135 | if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") 136 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 137 | COMPONENT Runtime) 138 | endif() 139 | -------------------------------------------------------------------------------- /linux/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.10) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | 12 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...), 13 | # which isn't available in 3.10. 14 | function(list_prepend LIST_NAME PREFIX) 15 | set(NEW_LIST "") 16 | foreach(element ${${LIST_NAME}}) 17 | list(APPEND NEW_LIST "${PREFIX}${element}") 18 | endforeach(element) 19 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) 20 | endfunction() 21 | 22 | # === Flutter Library === 23 | # System-level dependencies. 24 | find_package(PkgConfig REQUIRED) 25 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 26 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) 27 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) 28 | 29 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") 30 | 31 | # Published to parent scope for install step. 32 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 33 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 34 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 35 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) 36 | 37 | list(APPEND FLUTTER_LIBRARY_HEADERS 38 | "fl_basic_message_channel.h" 39 | "fl_binary_codec.h" 40 | "fl_binary_messenger.h" 41 | "fl_dart_project.h" 42 | "fl_engine.h" 43 | "fl_json_message_codec.h" 44 | "fl_json_method_codec.h" 45 | "fl_message_codec.h" 46 | "fl_method_call.h" 47 | "fl_method_channel.h" 48 | "fl_method_codec.h" 49 | "fl_method_response.h" 50 | "fl_plugin_registrar.h" 51 | "fl_plugin_registry.h" 52 | "fl_standard_message_codec.h" 53 | "fl_standard_method_codec.h" 54 | "fl_string_codec.h" 55 | "fl_value.h" 56 | "fl_view.h" 57 | "flutter_linux.h" 58 | ) 59 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") 60 | add_library(flutter INTERFACE) 61 | target_include_directories(flutter INTERFACE 62 | "${EPHEMERAL_DIR}" 63 | ) 64 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") 65 | target_link_libraries(flutter INTERFACE 66 | PkgConfig::GTK 67 | PkgConfig::GLIB 68 | PkgConfig::GIO 69 | ) 70 | add_dependencies(flutter flutter_assemble) 71 | 72 | # === Flutter tool backend === 73 | # _phony_ is a non-existent file to force this command to run every time, 74 | # since currently there's no way to get a full input/output list from the 75 | # flutter tool. 76 | add_custom_command( 77 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 78 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_ 79 | COMMAND ${CMAKE_COMMAND} -E env 80 | ${FLUTTER_TOOL_ENVIRONMENT} 81 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" 82 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} 83 | VERBATIM 84 | ) 85 | add_custom_target(flutter_assemble DEPENDS 86 | "${FLUTTER_LIBRARY}" 87 | ${FLUTTER_LIBRARY_HEADERS} 88 | ) 89 | -------------------------------------------------------------------------------- /linux/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void fl_register_plugins(FlPluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /linux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void fl_register_plugins(FlPluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /linux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /linux/main.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | int main(int argc, char** argv) { 4 | g_autoptr(MyApplication) app = my_application_new(); 5 | return g_application_run(G_APPLICATION(app), argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /linux/my_application.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | #include 4 | #ifdef GDK_WINDOWING_X11 5 | #include 6 | #endif 7 | 8 | #include "flutter/generated_plugin_registrant.h" 9 | 10 | struct _MyApplication { 11 | GtkApplication parent_instance; 12 | char** dart_entrypoint_arguments; 13 | }; 14 | 15 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) 16 | 17 | // Implements GApplication::activate. 18 | static void my_application_activate(GApplication* application) { 19 | MyApplication* self = MY_APPLICATION(application); 20 | GtkWindow* window = 21 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); 22 | 23 | // Use a header bar when running in GNOME as this is the common style used 24 | // by applications and is the setup most users will be using (e.g. Ubuntu 25 | // desktop). 26 | // If running on X and not using GNOME then just use a traditional title bar 27 | // in case the window manager does more exotic layout, e.g. tiling. 28 | // If running on Wayland assume the header bar will work (may need changing 29 | // if future cases occur). 30 | gboolean use_header_bar = TRUE; 31 | #ifdef GDK_WINDOWING_X11 32 | GdkScreen* screen = gtk_window_get_screen(window); 33 | if (GDK_IS_X11_SCREEN(screen)) { 34 | const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); 35 | if (g_strcmp0(wm_name, "GNOME Shell") != 0) { 36 | use_header_bar = FALSE; 37 | } 38 | } 39 | #endif 40 | if (use_header_bar) { 41 | GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); 42 | gtk_widget_show(GTK_WIDGET(header_bar)); 43 | gtk_header_bar_set_title(header_bar, "jdshop_flutter"); 44 | gtk_header_bar_set_show_close_button(header_bar, TRUE); 45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); 46 | } else { 47 | gtk_window_set_title(window, "jdshop_flutter"); 48 | } 49 | 50 | gtk_window_set_default_size(window, 1280, 720); 51 | gtk_widget_show(GTK_WIDGET(window)); 52 | 53 | g_autoptr(FlDartProject) project = fl_dart_project_new(); 54 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments); 55 | 56 | FlView* view = fl_view_new(project); 57 | gtk_widget_show(GTK_WIDGET(view)); 58 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); 59 | 60 | fl_register_plugins(FL_PLUGIN_REGISTRY(view)); 61 | 62 | gtk_widget_grab_focus(GTK_WIDGET(view)); 63 | } 64 | 65 | // Implements GApplication::local_command_line. 66 | static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) { 67 | MyApplication* self = MY_APPLICATION(application); 68 | // Strip out the first argument as it is the binary name. 69 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); 70 | 71 | g_autoptr(GError) error = nullptr; 72 | if (!g_application_register(application, nullptr, &error)) { 73 | g_warning("Failed to register: %s", error->message); 74 | *exit_status = 1; 75 | return TRUE; 76 | } 77 | 78 | g_application_activate(application); 79 | *exit_status = 0; 80 | 81 | return TRUE; 82 | } 83 | 84 | // Implements GObject::dispose. 85 | static void my_application_dispose(GObject* object) { 86 | MyApplication* self = MY_APPLICATION(object); 87 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); 88 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object); 89 | } 90 | 91 | static void my_application_class_init(MyApplicationClass* klass) { 92 | G_APPLICATION_CLASS(klass)->activate = my_application_activate; 93 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line; 94 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose; 95 | } 96 | 97 | static void my_application_init(MyApplication* self) {} 98 | 99 | MyApplication* my_application_new() { 100 | return MY_APPLICATION(g_object_new(my_application_get_type(), 101 | "application-id", APPLICATION_ID, 102 | "flags", G_APPLICATION_NON_UNIQUE, 103 | nullptr)); 104 | } 105 | -------------------------------------------------------------------------------- /linux/my_application.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_MY_APPLICATION_H_ 2 | #define FLUTTER_MY_APPLICATION_H_ 3 | 4 | #include 5 | 6 | G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, 7 | GtkApplication) 8 | 9 | /** 10 | * my_application_new: 11 | * 12 | * Creates a new Flutter-based application. 13 | * 14 | * Returns: a new #MyApplication. 15 | */ 16 | MyApplication* my_application_new(); 17 | 18 | #endif // FLUTTER_MY_APPLICATION_H_ 19 | -------------------------------------------------------------------------------- /macos/.gitignore: -------------------------------------------------------------------------------- 1 | # Flutter-related 2 | **/Flutter/ephemeral/ 3 | **/Pods/ 4 | 5 | # Xcode-related 6 | **/dgph 7 | **/xcuserdata/ 8 | -------------------------------------------------------------------------------- /macos/Flutter/Flutter-Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" 2 | #include "ephemeral/Flutter-Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /macos/Flutter/Flutter-Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" 2 | #include "ephemeral/Flutter-Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /macos/Flutter/GeneratedPluginRegistrant.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | import FlutterMacOS 6 | import Foundation 7 | 8 | import shared_preferences_macos 9 | 10 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { 11 | SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) 12 | } 13 | -------------------------------------------------------------------------------- /macos/Podfile: -------------------------------------------------------------------------------- 1 | platform :osx, '10.14' 2 | 3 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency. 4 | ENV['COCOAPODS_DISABLE_STATS'] = 'true' 5 | 6 | project 'Runner', { 7 | 'Debug' => :debug, 8 | 'Profile' => :release, 9 | 'Release' => :release, 10 | } 11 | 12 | def flutter_root 13 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__) 14 | unless File.exist?(generated_xcode_build_settings_path) 15 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first" 16 | end 17 | 18 | File.foreach(generated_xcode_build_settings_path) do |line| 19 | matches = line.match(/FLUTTER_ROOT\=(.*)/) 20 | return matches[1].strip if matches 21 | end 22 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\"" 23 | end 24 | 25 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) 26 | 27 | flutter_macos_podfile_setup 28 | 29 | target 'Runner' do 30 | use_frameworks! 31 | use_modular_headers! 32 | 33 | flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__)) 34 | end 35 | 36 | post_install do |installer| 37 | installer.pods_project.targets.each do |target| 38 | flutter_additional_macos_build_settings(target) 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 69 | 71 | 77 | 78 | 79 | 80 | 82 | 83 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /macos/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /macos/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | @NSApplicationMain 5 | class AppDelegate: FlutterAppDelegate { 6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { 7 | return true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "16x16", 5 | "idiom" : "mac", 6 | "filename" : "app_icon_16.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "16x16", 11 | "idiom" : "mac", 12 | "filename" : "app_icon_32.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "32x32", 17 | "idiom" : "mac", 18 | "filename" : "app_icon_32.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "32x32", 23 | "idiom" : "mac", 24 | "filename" : "app_icon_64.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "128x128", 29 | "idiom" : "mac", 30 | "filename" : "app_icon_128.png", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "size" : "128x128", 35 | "idiom" : "mac", 36 | "filename" : "app_icon_256.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "256x256", 41 | "idiom" : "mac", 42 | "filename" : "app_icon_256.png", 43 | "scale" : "1x" 44 | }, 45 | { 46 | "size" : "256x256", 47 | "idiom" : "mac", 48 | "filename" : "app_icon_512.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "512x512", 53 | "idiom" : "mac", 54 | "filename" : "app_icon_512.png", 55 | "scale" : "1x" 56 | }, 57 | { 58 | "size" : "512x512", 59 | "idiom" : "mac", 60 | "filename" : "app_icon_1024.png", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png -------------------------------------------------------------------------------- /macos/Runner/Configs/AppInfo.xcconfig: -------------------------------------------------------------------------------- 1 | // Application-level settings for the Runner target. 2 | // 3 | // This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the 4 | // future. If not, the values below would default to using the project name when this becomes a 5 | // 'flutter create' template. 6 | 7 | // The application's name. By default this is also the title of the Flutter window. 8 | PRODUCT_NAME = jdshop_flutter 9 | 10 | // The application's bundle identifier 11 | PRODUCT_BUNDLE_IDENTIFIER = com.xiejiapei.jdshopflutter.jdshopFlutter 12 | 13 | // The copyright displayed in application information 14 | PRODUCT_COPYRIGHT = Copyright © 2023 com.xiejiapei.jdshop_flutter. All rights reserved. 15 | -------------------------------------------------------------------------------- /macos/Runner/Configs/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Debug.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /macos/Runner/Configs/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Release.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /macos/Runner/Configs/Warnings.xcconfig: -------------------------------------------------------------------------------- 1 | WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings 2 | GCC_WARN_UNDECLARED_SELECTOR = YES 3 | CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES 4 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE 5 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES 6 | CLANG_WARN_PRAGMA_PACK = YES 7 | CLANG_WARN_STRICT_PROTOTYPES = YES 8 | CLANG_WARN_COMMA = YES 9 | GCC_WARN_STRICT_SELECTOR_MATCH = YES 10 | CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES 11 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES 12 | GCC_WARN_SHADOW = YES 13 | CLANG_WARN_UNREACHABLE_CODE = YES 14 | -------------------------------------------------------------------------------- /macos/Runner/DebugProfile.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.cs.allow-jit 8 | 9 | com.apple.security.network.server 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /macos/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSMinimumSystemVersion 24 | $(MACOSX_DEPLOYMENT_TARGET) 25 | NSHumanReadableCopyright 26 | $(PRODUCT_COPYRIGHT) 27 | NSMainNibFile 28 | MainMenu 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /macos/Runner/MainFlutterWindow.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | class MainFlutterWindow: NSWindow { 5 | override func awakeFromNib() { 6 | let flutterViewController = FlutterViewController.init() 7 | let windowFrame = self.frame 8 | self.contentViewController = flutterViewController 9 | self.setFrame(windowFrame, display: true) 10 | 11 | RegisterGeneratedPlugins(registry: flutterViewController) 12 | 13 | super.awakeFromNib() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /macos/Runner/Release.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: jdshop_app 2 | description: A new Flutter project. 3 | 4 | # The following defines the version and build number for your application. 5 | # A version number is three numbers separated by dots, like 1.2.43 6 | # followed by an optional build number separated by a +. 7 | # Both the version and the builder number may be overridden in flutter 8 | # build by specifying --build-name and --build-number, respectively. 9 | # In Android, build-name is used as versionName while build-number used as versionCode. 10 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning 11 | # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. 12 | # Read more about iOS versioning at 13 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html 14 | version: 1.0.0+1 15 | 16 | environment: 17 | sdk: ">=2.1.0 <3.0.0" 18 | 19 | dependencies: 20 | flutter: 21 | sdk: flutter 22 | 23 | # The following adds the Cupertino Icons font to your application. 24 | # Use with the CupertinoIcons class for iOS style icons. 25 | cupertino_icons: ^0.1.2 26 | flutter_swiper: ^1.1.6 27 | flutter_screenutil: ^1.1.0 28 | dio: ^3.0.9 29 | shared_preferences: ^0.5.7 30 | provider: ^4.0.5 31 | flutter_inappwebview: ^2.1.0+1 32 | event_bus: ^1.1.1 33 | fluttertoast: ^8.1.2 34 | city_pickers: ^1.2.0 35 | crypto: ^2.1.3 36 | 37 | dev_dependencies: 38 | flutter_test: 39 | sdk: flutter 40 | 41 | 42 | # For information on the generic Dart part of this file, see the 43 | # following page: https://dart.dev/tools/pub/pubspec 44 | 45 | # The following section is specific to Flutter. 46 | flutter: 47 | 48 | # The following line ensures that the Material Icons font is 49 | # included with your application, so that you can use the icons in 50 | # the material Icons class. 51 | uses-material-design: true 52 | 53 | # To add assets to your application, add an assets section, like this: 54 | assets: 55 | - images/user_bg.jpg 56 | - images/2.0x/user_bg.jpg 57 | - images/3.0x/user_bg.jpg 58 | - images/user.png 59 | - images/2.0x/user.png 60 | - images/3.0x/user.png 61 | - images/login.png 62 | - images/2.0x/login.png 63 | - images/3.0x/login.png 64 | 65 | # An image asset can refer to one or more resolution-specific "variants", see 66 | # https://flutter.dev/assets-and-images/#resolution-aware. 67 | 68 | # For details regarding adding assets from package dependencies, see 69 | # https://flutter.dev/assets-and-images/#from-packages 70 | 71 | # To add custom fonts to your application, add a fonts section here, 72 | # in this "flutter" section. Each entry in this list should have a 73 | # "family" key with the font family name, and a "fonts" key with a 74 | # list giving the asset and other descriptors for the font. For 75 | # example: 76 | # fonts: 77 | # - family: Schyler 78 | # fonts: 79 | # - asset: fonts/Schyler-Regular.ttf 80 | # - asset: fonts/Schyler-Italic.ttf 81 | # style: italic 82 | # - family: Trajan Pro 83 | # fonts: 84 | # - asset: fonts/TrajanPro.ttf 85 | # - asset: fonts/TrajanPro_Bold.ttf 86 | # weight: 700 87 | # 88 | # For details regarding fonts from package dependencies, 89 | # see https://flutter.dev/custom-fonts/#from-packages 90 | -------------------------------------------------------------------------------- /test/widget_test.dart: -------------------------------------------------------------------------------- 1 | // This is a basic Flutter widget test. 2 | // 3 | // To perform an interaction with a widget in your test, use the WidgetTester 4 | // utility in the flutter_test package. For example, you can send tap and scroll 5 | // gestures. You can also use WidgetTester to find child widgets in the widget 6 | // tree, read text, and verify that the values of widget properties are correct. 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:flutter_test/flutter_test.dart'; 10 | 11 | import 'package:jdshop_app/main.dart'; 12 | 13 | void main() { 14 | testWidgets('Counter increments smoke test', (WidgetTester tester) async { 15 | // Build our app and trigger a frame. 16 | await tester.pumpWidget(MyApp()); 17 | 18 | // Verify that our counter starts at 0. 19 | expect(find.text('0'), findsOneWidget); 20 | expect(find.text('1'), findsNothing); 21 | 22 | // Tap the '+' icon and trigger a frame. 23 | await tester.tap(find.byIcon(Icons.add)); 24 | await tester.pump(); 25 | 26 | // Verify that our counter has incremented. 27 | expect(find.text('0'), findsNothing); 28 | expect(find.text('1'), findsOneWidget); 29 | }); 30 | } 31 | -------------------------------------------------------------------------------- /web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/web/favicon.png -------------------------------------------------------------------------------- /web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/web/icons/Icon-192.png -------------------------------------------------------------------------------- /web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/web/icons/Icon-512.png -------------------------------------------------------------------------------- /web/icons/Icon-maskable-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/web/icons/Icon-maskable-192.png -------------------------------------------------------------------------------- /web/icons/Icon-maskable-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/web/icons/Icon-maskable-512.png -------------------------------------------------------------------------------- /web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | jdshop_flutter 33 | 34 | 35 | 39 | 40 | 41 | 42 | 43 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jdshop_flutter", 3 | "short_name": "jdshop_flutter", 4 | "start_url": ".", 5 | "display": "standalone", 6 | "background_color": "#0175C2", 7 | "theme_color": "#0175C2", 8 | "description": "A new Flutter project.", 9 | "orientation": "portrait-primary", 10 | "prefer_related_applications": false, 11 | "icons": [ 12 | { 13 | "src": "icons/Icon-192.png", 14 | "sizes": "192x192", 15 | "type": "image/png" 16 | }, 17 | { 18 | "src": "icons/Icon-512.png", 19 | "sizes": "512x512", 20 | "type": "image/png" 21 | }, 22 | { 23 | "src": "icons/Icon-maskable-192.png", 24 | "sizes": "192x192", 25 | "type": "image/png", 26 | "purpose": "maskable" 27 | }, 28 | { 29 | "src": "icons/Icon-maskable-512.png", 30 | "sizes": "512x512", 31 | "type": "image/png", 32 | "purpose": "maskable" 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /windows/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral/ 2 | 3 | # Visual Studio user-specific files. 4 | *.suo 5 | *.user 6 | *.userosscache 7 | *.sln.docstates 8 | 9 | # Visual Studio build-related files. 10 | x64/ 11 | x86/ 12 | 13 | # Visual Studio cache files 14 | # files ending in .cache can be ignored 15 | *.[Cc]ache 16 | # but keep track of directories ending in .cache 17 | !*.[Cc]ache/ 18 | -------------------------------------------------------------------------------- /windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project-level configuration. 2 | cmake_minimum_required(VERSION 3.14) 3 | project(jdshop_flutter LANGUAGES CXX) 4 | 5 | # The name of the executable created for the application. Change this to change 6 | # the on-disk name of your application. 7 | set(BINARY_NAME "jdshop_flutter") 8 | 9 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 10 | # versions of CMake. 11 | cmake_policy(SET CMP0063 NEW) 12 | 13 | # Define build configuration option. 14 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 15 | if(IS_MULTICONFIG) 16 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" 17 | CACHE STRING "" FORCE) 18 | else() 19 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 20 | set(CMAKE_BUILD_TYPE "Debug" CACHE 21 | STRING "Flutter build mode" FORCE) 22 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 23 | "Debug" "Profile" "Release") 24 | endif() 25 | endif() 26 | # Define settings for the Profile build mode. 27 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") 28 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") 29 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") 30 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") 31 | 32 | # Use Unicode for all projects. 33 | add_definitions(-DUNICODE -D_UNICODE) 34 | 35 | # Compilation settings that should be applied to most targets. 36 | # 37 | # Be cautious about adding new options here, as plugins use this function by 38 | # default. In most cases, you should add new options to specific targets instead 39 | # of modifying this function. 40 | function(APPLY_STANDARD_SETTINGS TARGET) 41 | target_compile_features(${TARGET} PUBLIC cxx_std_17) 42 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") 43 | target_compile_options(${TARGET} PRIVATE /EHsc) 44 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") 45 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") 46 | endfunction() 47 | 48 | # Flutter library and tool build rules. 49 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 50 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 51 | 52 | # Application build; see runner/CMakeLists.txt. 53 | add_subdirectory("runner") 54 | 55 | # Generated plugin build rules, which manage building the plugins and adding 56 | # them to the application. 57 | include(flutter/generated_plugins.cmake) 58 | 59 | 60 | # === Installation === 61 | # Support files are copied into place next to the executable, so that it can 62 | # run in place. This is done instead of making a separate bundle (as on Linux) 63 | # so that building and running from within Visual Studio will work. 64 | set(BUILD_BUNDLE_DIR "$") 65 | # Make the "install" step default, as it's required to run. 66 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) 67 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 68 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 69 | endif() 70 | 71 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 72 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") 73 | 74 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 75 | COMPONENT Runtime) 76 | 77 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 78 | COMPONENT Runtime) 79 | 80 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 81 | COMPONENT Runtime) 82 | 83 | if(PLUGIN_BUNDLED_LIBRARIES) 84 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" 85 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 86 | COMPONENT Runtime) 87 | endif() 88 | 89 | # Fully re-copy the assets directory on each build to avoid having stale files 90 | # from a previous install. 91 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 92 | install(CODE " 93 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 94 | " COMPONENT Runtime) 95 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 96 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 97 | 98 | # Install the AOT library on non-Debug builds only. 99 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 100 | CONFIGURATIONS Profile;Release 101 | COMPONENT Runtime) 102 | -------------------------------------------------------------------------------- /windows/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.14) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") 12 | 13 | # === Flutter Library === 14 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") 15 | 16 | # Published to parent scope for install step. 17 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 18 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 19 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 20 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) 21 | 22 | list(APPEND FLUTTER_LIBRARY_HEADERS 23 | "flutter_export.h" 24 | "flutter_windows.h" 25 | "flutter_messenger.h" 26 | "flutter_plugin_registrar.h" 27 | "flutter_texture_registrar.h" 28 | ) 29 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") 30 | add_library(flutter INTERFACE) 31 | target_include_directories(flutter INTERFACE 32 | "${EPHEMERAL_DIR}" 33 | ) 34 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") 35 | add_dependencies(flutter flutter_assemble) 36 | 37 | # === Wrapper === 38 | list(APPEND CPP_WRAPPER_SOURCES_CORE 39 | "core_implementations.cc" 40 | "standard_codec.cc" 41 | ) 42 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") 43 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN 44 | "plugin_registrar.cc" 45 | ) 46 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") 47 | list(APPEND CPP_WRAPPER_SOURCES_APP 48 | "flutter_engine.cc" 49 | "flutter_view_controller.cc" 50 | ) 51 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") 52 | 53 | # Wrapper sources needed for a plugin. 54 | add_library(flutter_wrapper_plugin STATIC 55 | ${CPP_WRAPPER_SOURCES_CORE} 56 | ${CPP_WRAPPER_SOURCES_PLUGIN} 57 | ) 58 | apply_standard_settings(flutter_wrapper_plugin) 59 | set_target_properties(flutter_wrapper_plugin PROPERTIES 60 | POSITION_INDEPENDENT_CODE ON) 61 | set_target_properties(flutter_wrapper_plugin PROPERTIES 62 | CXX_VISIBILITY_PRESET hidden) 63 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) 64 | target_include_directories(flutter_wrapper_plugin PUBLIC 65 | "${WRAPPER_ROOT}/include" 66 | ) 67 | add_dependencies(flutter_wrapper_plugin flutter_assemble) 68 | 69 | # Wrapper sources needed for the runner. 70 | add_library(flutter_wrapper_app STATIC 71 | ${CPP_WRAPPER_SOURCES_CORE} 72 | ${CPP_WRAPPER_SOURCES_APP} 73 | ) 74 | apply_standard_settings(flutter_wrapper_app) 75 | target_link_libraries(flutter_wrapper_app PUBLIC flutter) 76 | target_include_directories(flutter_wrapper_app PUBLIC 77 | "${WRAPPER_ROOT}/include" 78 | ) 79 | add_dependencies(flutter_wrapper_app flutter_assemble) 80 | 81 | # === Flutter tool backend === 82 | # _phony_ is a non-existent file to force this command to run every time, 83 | # since currently there's no way to get a full input/output list from the 84 | # flutter tool. 85 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") 86 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) 87 | add_custom_command( 88 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 89 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} 90 | ${CPP_WRAPPER_SOURCES_APP} 91 | ${PHONY_OUTPUT} 92 | COMMAND ${CMAKE_COMMAND} -E env 93 | ${FLUTTER_TOOL_ENVIRONMENT} 94 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" 95 | windows-x64 $ 96 | VERBATIM 97 | ) 98 | add_custom_target(flutter_assemble DEPENDS 99 | "${FLUTTER_LIBRARY}" 100 | ${FLUTTER_LIBRARY_HEADERS} 101 | ${CPP_WRAPPER_SOURCES_CORE} 102 | ${CPP_WRAPPER_SOURCES_PLUGIN} 103 | ${CPP_WRAPPER_SOURCES_APP} 104 | ) 105 | -------------------------------------------------------------------------------- /windows/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void RegisterPlugins(flutter::PluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /windows/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void RegisterPlugins(flutter::PluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /windows/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /windows/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | project(runner LANGUAGES CXX) 3 | 4 | # Define the application target. To change its name, change BINARY_NAME in the 5 | # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer 6 | # work. 7 | # 8 | # Any new source files that you add to the application should be added here. 9 | add_executable(${BINARY_NAME} WIN32 10 | "flutter_window.cpp" 11 | "main.cpp" 12 | "utils.cpp" 13 | "win32_window.cpp" 14 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 15 | "Runner.rc" 16 | "runner.exe.manifest" 17 | ) 18 | 19 | # Apply the standard set of build settings. This can be removed for applications 20 | # that need different build settings. 21 | apply_standard_settings(${BINARY_NAME}) 22 | 23 | # Add preprocessor definitions for the build version. 24 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") 25 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") 26 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") 27 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") 28 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") 29 | 30 | # Disable Windows macros that collide with C++ standard library functions. 31 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 32 | 33 | # Add dependency libraries and include directories. Add any application-specific 34 | # dependencies here. 35 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 36 | target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") 37 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 38 | 39 | # Run the Flutter tool portions of the build. This must not be removed. 40 | add_dependencies(${BINARY_NAME} flutter_assemble) 41 | -------------------------------------------------------------------------------- /windows/runner/Runner.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #pragma code_page(65001) 4 | #include "resource.h" 5 | 6 | #define APSTUDIO_READONLY_SYMBOLS 7 | ///////////////////////////////////////////////////////////////////////////// 8 | // 9 | // Generated from the TEXTINCLUDE 2 resource. 10 | // 11 | #include "winres.h" 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | #undef APSTUDIO_READONLY_SYMBOLS 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // English (United States) resources 18 | 19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Icon 51 | // 52 | 53 | // Icon with lowest ID value placed first to ensure application icon 54 | // remains consistent on all systems. 55 | IDI_APP_ICON ICON "resources\\app_icon.ico" 56 | 57 | 58 | ///////////////////////////////////////////////////////////////////////////// 59 | // 60 | // Version 61 | // 62 | 63 | #if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD) 64 | #define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD 65 | #else 66 | #define VERSION_AS_NUMBER 1,0,0,0 67 | #endif 68 | 69 | #if defined(FLUTTER_VERSION) 70 | #define VERSION_AS_STRING FLUTTER_VERSION 71 | #else 72 | #define VERSION_AS_STRING "1.0.0" 73 | #endif 74 | 75 | VS_VERSION_INFO VERSIONINFO 76 | FILEVERSION VERSION_AS_NUMBER 77 | PRODUCTVERSION VERSION_AS_NUMBER 78 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 79 | #ifdef _DEBUG 80 | FILEFLAGS VS_FF_DEBUG 81 | #else 82 | FILEFLAGS 0x0L 83 | #endif 84 | FILEOS VOS__WINDOWS32 85 | FILETYPE VFT_APP 86 | FILESUBTYPE 0x0L 87 | BEGIN 88 | BLOCK "StringFileInfo" 89 | BEGIN 90 | BLOCK "040904e4" 91 | BEGIN 92 | VALUE "CompanyName", "com.xiejiapei.jdshop_flutter" "\0" 93 | VALUE "FileDescription", "jdshop_flutter" "\0" 94 | VALUE "FileVersion", VERSION_AS_STRING "\0" 95 | VALUE "InternalName", "jdshop_flutter" "\0" 96 | VALUE "LegalCopyright", "Copyright (C) 2023 com.xiejiapei.jdshop_flutter. All rights reserved." "\0" 97 | VALUE "OriginalFilename", "jdshop_flutter.exe" "\0" 98 | VALUE "ProductName", "jdshop_flutter" "\0" 99 | VALUE "ProductVersion", VERSION_AS_STRING "\0" 100 | END 101 | END 102 | BLOCK "VarFileInfo" 103 | BEGIN 104 | VALUE "Translation", 0x409, 1252 105 | END 106 | END 107 | 108 | #endif // English (United States) resources 109 | ///////////////////////////////////////////////////////////////////////////// 110 | 111 | 112 | 113 | #ifndef APSTUDIO_INVOKED 114 | ///////////////////////////////////////////////////////////////////////////// 115 | // 116 | // Generated from the TEXTINCLUDE 3 resource. 117 | // 118 | 119 | 120 | ///////////////////////////////////////////////////////////////////////////// 121 | #endif // not APSTUDIO_INVOKED 122 | -------------------------------------------------------------------------------- /windows/runner/flutter_window.cpp: -------------------------------------------------------------------------------- 1 | #include "flutter_window.h" 2 | 3 | #include 4 | 5 | #include "flutter/generated_plugin_registrant.h" 6 | 7 | FlutterWindow::FlutterWindow(const flutter::DartProject& project) 8 | : project_(project) {} 9 | 10 | FlutterWindow::~FlutterWindow() {} 11 | 12 | bool FlutterWindow::OnCreate() { 13 | if (!Win32Window::OnCreate()) { 14 | return false; 15 | } 16 | 17 | RECT frame = GetClientArea(); 18 | 19 | // The size here must match the window dimensions to avoid unnecessary surface 20 | // creation / destruction in the startup path. 21 | flutter_controller_ = std::make_unique( 22 | frame.right - frame.left, frame.bottom - frame.top, project_); 23 | // Ensure that basic setup of the controller was successful. 24 | if (!flutter_controller_->engine() || !flutter_controller_->view()) { 25 | return false; 26 | } 27 | RegisterPlugins(flutter_controller_->engine()); 28 | SetChildContent(flutter_controller_->view()->GetNativeWindow()); 29 | 30 | flutter_controller_->engine()->SetNextFrameCallback([&]() { 31 | this->Show(); 32 | }); 33 | 34 | return true; 35 | } 36 | 37 | void FlutterWindow::OnDestroy() { 38 | if (flutter_controller_) { 39 | flutter_controller_ = nullptr; 40 | } 41 | 42 | Win32Window::OnDestroy(); 43 | } 44 | 45 | LRESULT 46 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message, 47 | WPARAM const wparam, 48 | LPARAM const lparam) noexcept { 49 | // Give Flutter, including plugins, an opportunity to handle window messages. 50 | if (flutter_controller_) { 51 | std::optional result = 52 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, 53 | lparam); 54 | if (result) { 55 | return *result; 56 | } 57 | } 58 | 59 | switch (message) { 60 | case WM_FONTCHANGE: 61 | flutter_controller_->engine()->ReloadSystemFonts(); 62 | break; 63 | } 64 | 65 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam); 66 | } 67 | -------------------------------------------------------------------------------- /windows/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_FLUTTER_WINDOW_H_ 2 | #define RUNNER_FLUTTER_WINDOW_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "win32_window.h" 10 | 11 | // A window that does nothing but host a Flutter view. 12 | class FlutterWindow : public Win32Window { 13 | public: 14 | // Creates a new FlutterWindow hosting a Flutter view running |project|. 15 | explicit FlutterWindow(const flutter::DartProject& project); 16 | virtual ~FlutterWindow(); 17 | 18 | protected: 19 | // Win32Window: 20 | bool OnCreate() override; 21 | void OnDestroy() override; 22 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, 23 | LPARAM const lparam) noexcept override; 24 | 25 | private: 26 | // The project to run. 27 | flutter::DartProject project_; 28 | 29 | // The Flutter instance hosted by this window. 30 | std::unique_ptr flutter_controller_; 31 | }; 32 | 33 | #endif // RUNNER_FLUTTER_WINDOW_H_ 34 | -------------------------------------------------------------------------------- /windows/runner/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "flutter_window.h" 6 | #include "utils.h" 7 | 8 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, 9 | _In_ wchar_t *command_line, _In_ int show_command) { 10 | // Attach to console when present (e.g., 'flutter run') or create a 11 | // new console when running with a debugger. 12 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { 13 | CreateAndAttachConsole(); 14 | } 15 | 16 | // Initialize COM, so that it is available for use in the library and/or 17 | // plugins. 18 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); 19 | 20 | flutter::DartProject project(L"data"); 21 | 22 | std::vector command_line_arguments = 23 | GetCommandLineArguments(); 24 | 25 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 26 | 27 | FlutterWindow window(project); 28 | Win32Window::Point origin(10, 10); 29 | Win32Window::Size size(1280, 720); 30 | if (!window.Create(L"jdshop_flutter", origin, size)) { 31 | return EXIT_FAILURE; 32 | } 33 | window.SetQuitOnClose(true); 34 | 35 | ::MSG msg; 36 | while (::GetMessage(&msg, nullptr, 0, 0)) { 37 | ::TranslateMessage(&msg); 38 | ::DispatchMessage(&msg); 39 | } 40 | 41 | ::CoUninitialize(); 42 | return EXIT_SUCCESS; 43 | } 44 | -------------------------------------------------------------------------------- /windows/runner/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Runner.rc 4 | // 5 | #define IDI_APP_ICON 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /windows/runner/resources/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiejiapei-creator/JDShop_Flutter/4c166270173332b45f83af679009973016fbe0c9/windows/runner/resources/app_icon.ico -------------------------------------------------------------------------------- /windows/runner/runner.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PerMonitorV2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /windows/runner/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | void CreateAndAttachConsole() { 11 | if (::AllocConsole()) { 12 | FILE *unused; 13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) { 14 | _dup2(_fileno(stdout), 1); 15 | } 16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) { 17 | _dup2(_fileno(stdout), 2); 18 | } 19 | std::ios::sync_with_stdio(); 20 | FlutterDesktopResyncOutputStreams(); 21 | } 22 | } 23 | 24 | std::vector GetCommandLineArguments() { 25 | // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. 26 | int argc; 27 | wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); 28 | if (argv == nullptr) { 29 | return std::vector(); 30 | } 31 | 32 | std::vector command_line_arguments; 33 | 34 | // Skip the first argument as it's the binary name. 35 | for (int i = 1; i < argc; i++) { 36 | command_line_arguments.push_back(Utf8FromUtf16(argv[i])); 37 | } 38 | 39 | ::LocalFree(argv); 40 | 41 | return command_line_arguments; 42 | } 43 | 44 | std::string Utf8FromUtf16(const wchar_t* utf16_string) { 45 | if (utf16_string == nullptr) { 46 | return std::string(); 47 | } 48 | int target_length = ::WideCharToMultiByte( 49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 50 | -1, nullptr, 0, nullptr, nullptr); 51 | std::string utf8_string; 52 | if (target_length == 0 || target_length > utf8_string.max_size()) { 53 | return utf8_string; 54 | } 55 | utf8_string.resize(target_length); 56 | int converted_length = ::WideCharToMultiByte( 57 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 58 | -1, utf8_string.data(), 59 | target_length, nullptr, nullptr); 60 | if (converted_length == 0) { 61 | return std::string(); 62 | } 63 | return utf8_string; 64 | } 65 | -------------------------------------------------------------------------------- /windows/runner/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_UTILS_H_ 2 | #define RUNNER_UTILS_H_ 3 | 4 | #include 5 | #include 6 | 7 | // Creates a console for the process, and redirects stdout and stderr to 8 | // it for both the runner and the Flutter library. 9 | void CreateAndAttachConsole(); 10 | 11 | // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string 12 | // encoded in UTF-8. Returns an empty std::string on failure. 13 | std::string Utf8FromUtf16(const wchar_t* utf16_string); 14 | 15 | // Gets the command line arguments passed in as a std::vector, 16 | // encoded in UTF-8. Returns an empty std::vector on failure. 17 | std::vector GetCommandLineArguments(); 18 | 19 | #endif // RUNNER_UTILS_H_ 20 | -------------------------------------------------------------------------------- /windows/runner/win32_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_WIN32_WINDOW_H_ 2 | #define RUNNER_WIN32_WINDOW_H_ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | // A class abstraction for a high DPI-aware Win32 Window. Intended to be 11 | // inherited from by classes that wish to specialize with custom 12 | // rendering and input handling 13 | class Win32Window { 14 | public: 15 | struct Point { 16 | unsigned int x; 17 | unsigned int y; 18 | Point(unsigned int x, unsigned int y) : x(x), y(y) {} 19 | }; 20 | 21 | struct Size { 22 | unsigned int width; 23 | unsigned int height; 24 | Size(unsigned int width, unsigned int height) 25 | : width(width), height(height) {} 26 | }; 27 | 28 | Win32Window(); 29 | virtual ~Win32Window(); 30 | 31 | // Creates a win32 window with |title| that is positioned and sized using 32 | // |origin| and |size|. New windows are created on the default monitor. Window 33 | // sizes are specified to the OS in physical pixels, hence to ensure a 34 | // consistent size this function will scale the inputted width and height as 35 | // as appropriate for the default monitor. The window is invisible until 36 | // |Show| is called. Returns true if the window was created successfully. 37 | bool Create(const std::wstring& title, const Point& origin, const Size& size); 38 | 39 | // Show the current window. Returns true if the window was successfully shown. 40 | bool Show(); 41 | 42 | // Release OS resources associated with window. 43 | void Destroy(); 44 | 45 | // Inserts |content| into the window tree. 46 | void SetChildContent(HWND content); 47 | 48 | // Returns the backing Window handle to enable clients to set icon and other 49 | // window properties. Returns nullptr if the window has been destroyed. 50 | HWND GetHandle(); 51 | 52 | // If true, closing this window will quit the application. 53 | void SetQuitOnClose(bool quit_on_close); 54 | 55 | // Return a RECT representing the bounds of the current client area. 56 | RECT GetClientArea(); 57 | 58 | protected: 59 | // Processes and route salient window messages for mouse handling, 60 | // size change and DPI. Delegates handling of these to member overloads that 61 | // inheriting classes can handle. 62 | virtual LRESULT MessageHandler(HWND window, 63 | UINT const message, 64 | WPARAM const wparam, 65 | LPARAM const lparam) noexcept; 66 | 67 | // Called when CreateAndShow is called, allowing subclass window-related 68 | // setup. Subclasses should return false if setup fails. 69 | virtual bool OnCreate(); 70 | 71 | // Called when Destroy is called. 72 | virtual void OnDestroy(); 73 | 74 | private: 75 | friend class WindowClassRegistrar; 76 | 77 | // OS callback called by message pump. Handles the WM_NCCREATE message which 78 | // is passed when the non-client area is being created and enables automatic 79 | // non-client DPI scaling so that the non-client area automatically 80 | // responsponds to changes in DPI. All other messages are handled by 81 | // MessageHandler. 82 | static LRESULT CALLBACK WndProc(HWND const window, 83 | UINT const message, 84 | WPARAM const wparam, 85 | LPARAM const lparam) noexcept; 86 | 87 | // Retrieves a class instance pointer for |window| 88 | static Win32Window* GetThisFromHandle(HWND const window) noexcept; 89 | 90 | // Update the window frame's theme to match the system theme. 91 | static void UpdateTheme(HWND const window); 92 | 93 | bool quit_on_close_ = false; 94 | 95 | // window handle for top level window. 96 | HWND window_handle_ = nullptr; 97 | 98 | // window handle for hosted content. 99 | HWND child_content_ = nullptr; 100 | }; 101 | 102 | #endif // RUNNER_WIN32_WINDOW_H_ 103 | --------------------------------------------------------------------------------