├── .gitignore ├── .metadata ├── README.md ├── analysis_options.yaml ├── android ├── .gitignore ├── app │ ├── build.gradle │ └── src │ │ ├── debug │ │ └── AndroidManifest.xml │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── kotlin │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── tcp_client │ │ │ │ └── MainActivity.kt │ │ └── res │ │ │ ├── drawable-v21 │ │ │ └── launch_background.xml │ │ │ ├── drawable │ │ │ └── launch_background.xml │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── values-night │ │ │ └── styles.xml │ │ │ └── values │ │ │ └── styles.xml │ │ └── profile │ │ └── AndroidManifest.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ └── gradle-wrapper.properties └── settings.gradle ├── inno_setup.iss ├── ios ├── .gitignore ├── Flutter │ ├── AppFrameworkInfo.plist │ ├── Debug.xcconfig │ └── Release.xcconfig ├── Runner.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ └── WorkspaceSettings.xcsettings │ └── xcshareddata │ │ └── xcschemes │ │ └── Runner.xcscheme ├── Runner.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ ├── IDEWorkspaceChecks.plist │ │ └── WorkspaceSettings.xcsettings └── Runner │ ├── AppDelegate.swift │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── Icon-App-1024x1024@1x.png │ │ ├── Icon-App-20x20@1x.png │ │ ├── Icon-App-20x20@2x.png │ │ ├── Icon-App-20x20@3x.png │ │ ├── Icon-App-29x29@1x.png │ │ ├── Icon-App-29x29@2x.png │ │ ├── Icon-App-29x29@3x.png │ │ ├── Icon-App-40x40@1x.png │ │ ├── Icon-App-40x40@2x.png │ │ ├── Icon-App-40x40@3x.png │ │ ├── Icon-App-60x60@2x.png │ │ ├── Icon-App-60x60@3x.png │ │ ├── Icon-App-76x76@1x.png │ │ ├── Icon-App-76x76@2x.png │ │ └── Icon-App-83.5x83.5@2x.png │ └── LaunchImage.imageset │ │ ├── Contents.json │ │ ├── LaunchImage.png │ │ ├── LaunchImage@2x.png │ │ ├── LaunchImage@3x.png │ │ └── README.md │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ └── Runner-Bridging-Header.h ├── lib ├── chat │ ├── chat_page.dart │ ├── cubit │ │ ├── chat_cubit.dart │ │ └── chat_state.dart │ ├── model │ │ └── chat_history.dart │ └── view │ │ ├── common │ │ ├── file_box.dart │ │ ├── image_box.dart │ │ └── text_box.dart │ │ ├── history_tile.dart │ │ ├── in_message_box.dart │ │ ├── input_box │ │ ├── cubit │ │ │ ├── input_cubit.dart │ │ │ └── input_state.dart │ │ ├── input_box.dart │ │ └── model │ │ │ └── input.dart │ │ └── out_message_box.dart ├── common │ ├── avatar │ │ ├── avatar.dart │ │ └── cubit │ │ │ ├── avatar_cubit.dart │ │ │ └── avatar_state.dart │ └── username │ │ ├── cubit │ │ ├── username_cubit.dart │ │ └── username_state.dart │ │ └── username.dart ├── home │ ├── cubit │ │ ├── home_cubit.dart │ │ └── home_state.dart │ ├── home_page.dart │ └── view │ │ ├── bottom_bar.dart │ │ ├── contact_page │ │ ├── contact_page.dart │ │ ├── cubit │ │ │ ├── contact_cubit.dart │ │ │ └── contact_state.dart │ │ ├── models │ │ │ └── contact_model.dart │ │ └── view │ │ │ └── contact_tile.dart │ │ ├── message_page │ │ ├── cubit │ │ │ ├── msg_list_cubit.dart │ │ │ └── msg_list_state.dart │ │ ├── mesage_page.dart │ │ ├── models │ │ │ └── message_info.dart │ │ └── view │ │ │ └── message_tile.dart │ │ └── profile_page │ │ ├── cubit │ │ ├── log_out_cubit.dart │ │ └── log_out_state.dart │ │ ├── profile_page.dart │ │ └── view │ │ └── log_out_button.dart ├── initialization │ ├── cubit │ │ ├── initialization_cubit.dart │ │ └── initialization_state.dart │ └── initialization_page.dart ├── login │ ├── cubit │ │ ├── login_cubit.dart │ │ └── login_state.dart │ ├── login_page.dart │ ├── models │ │ ├── password.dart │ │ └── username.dart │ └── view │ │ ├── avatar_widget.dart │ │ └── login_form.dart ├── main.dart ├── profile │ ├── cubit │ │ ├── user_profile_cubit.dart │ │ └── user_profile_state.dart │ ├── user_profile_page.dart │ └── view │ │ └── add_contact_button.dart ├── register │ ├── cubit │ │ ├── register_cubit.dart │ │ └── register_state.dart │ ├── models │ │ ├── password.dart │ │ └── username.dart │ ├── register_page.dart │ └── view │ │ └── register_form.dart ├── repositories │ ├── common_models │ │ ├── json_encodable.dart │ │ ├── message.dart │ │ ├── useridentity.dart │ │ └── userinfo.dart │ ├── local_service_repository │ │ ├── local_service_repository.dart │ │ └── models │ │ │ └── local_file.dart │ ├── tcp_repository │ │ ├── models │ │ │ ├── tcp_request.dart │ │ │ └── tcp_response.dart │ │ └── tcp_repository.dart │ └── user_repository │ │ └── user_repository.dart └── search │ ├── cubit │ ├── search_cubit.dart │ └── search_state.dart │ ├── model │ ├── history_result.dart │ └── user_result.dart │ ├── search_page.dart │ └── view │ ├── history_tile.dart │ ├── search_bar.dart │ └── user_tile.dart ├── license ├── linux ├── .gitignore ├── CMakeLists.txt ├── flutter │ ├── CMakeLists.txt │ ├── generated_plugin_registrant.cc │ ├── generated_plugin_registrant.h │ └── generated_plugins.cmake ├── main.cc ├── my_application.cc └── my_application.h ├── macos ├── .gitignore ├── Flutter │ ├── Flutter-Debug.xcconfig │ ├── Flutter-Release.xcconfig │ └── GeneratedPluginRegistrant.swift ├── Runner.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── xcshareddata │ │ └── xcschemes │ │ └── Runner.xcscheme ├── Runner.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── Runner │ ├── AppDelegate.swift │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── app_icon_1024.png │ │ ├── app_icon_128.png │ │ ├── app_icon_16.png │ │ ├── app_icon_256.png │ │ ├── app_icon_32.png │ │ ├── app_icon_512.png │ │ └── app_icon_64.png │ ├── Base.lproj │ └── MainMenu.xib │ ├── Configs │ ├── AppInfo.xcconfig │ ├── Debug.xcconfig │ ├── Release.xcconfig │ └── Warnings.xcconfig │ ├── DebugProfile.entitlements │ ├── Info.plist │ ├── MainFlutterWindow.swift │ └── Release.entitlements ├── pubspec.lock ├── pubspec.yaml ├── web ├── favicon.png ├── icons │ ├── Icon-192.png │ ├── Icon-512.png │ ├── Icon-maskable-192.png │ └── Icon-maskable-512.png ├── index.html └── manifest.json └── windows ├── .gitignore ├── CMakeLists.txt ├── flutter ├── CMakeLists.txt ├── generated_plugin_registrant.cc ├── generated_plugin_registrant.h └── generated_plugins.cmake └── runner ├── CMakeLists.txt ├── Runner.rc ├── flutter_window.cpp ├── flutter_window.h ├── main.cpp ├── resource.h ├── resources └── app_icon.ico ├── runner.exe.manifest ├── utils.cpp ├── utils.h ├── win32_window.cpp └── win32_window.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | migrate_working_dir/ 12 | 13 | # IntelliJ related 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # The .vscode folder contains launch configuration and tasks you configure in 20 | # VS Code which you may wish to be included in version control, so this line 21 | # is commented out by default. 22 | #.vscode/ 23 | 24 | # Flutter/Dart/Pub related 25 | **/doc/api/ 26 | **/ios/Flutter/.last_build_id 27 | .dart_tool/ 28 | .flutter-plugins 29 | .flutter-plugins-dependencies 30 | .packages 31 | .pub-cache/ 32 | .pub/ 33 | /build/ 34 | 35 | # Symbolication related 36 | app.*.symbols 37 | 38 | # Obfuscation related 39 | app.*.map.json 40 | 41 | # Android Studio will place build artifacts here 42 | /android/app/debug 43 | /android/app/profile 44 | /android/app/release 45 | 46 | .tmp/ 47 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled. 5 | 6 | version: 7 | revision: 18a827f3933c19f51862dde3fa472197683249d6 8 | channel: stable 9 | 10 | project_type: app 11 | 12 | # Tracks metadata for the flutter migrate command 13 | migration: 14 | platforms: 15 | - platform: root 16 | create_revision: 18a827f3933c19f51862dde3fa472197683249d6 17 | base_revision: 18a827f3933c19f51862dde3fa472197683249d6 18 | - platform: android 19 | create_revision: 18a827f3933c19f51862dde3fa472197683249d6 20 | base_revision: 18a827f3933c19f51862dde3fa472197683249d6 21 | - platform: ios 22 | create_revision: 18a827f3933c19f51862dde3fa472197683249d6 23 | base_revision: 18a827f3933c19f51862dde3fa472197683249d6 24 | - platform: linux 25 | create_revision: 18a827f3933c19f51862dde3fa472197683249d6 26 | base_revision: 18a827f3933c19f51862dde3fa472197683249d6 27 | - platform: macos 28 | create_revision: 18a827f3933c19f51862dde3fa472197683249d6 29 | base_revision: 18a827f3933c19f51862dde3fa472197683249d6 30 | - platform: web 31 | create_revision: 18a827f3933c19f51862dde3fa472197683249d6 32 | base_revision: 18a827f3933c19f51862dde3fa472197683249d6 33 | - platform: windows 34 | create_revision: 18a827f3933c19f51862dde3fa472197683249d6 35 | base_revision: 18a827f3933c19f51862dde3fa472197683249d6 36 | 37 | # User provided section 38 | 39 | # List of Local paths (relative to this file) that should be 40 | # ignored by the migrate tool. 41 | # 42 | # Files that are not part of the templates will be ignored by default. 43 | unmanaged_files: 44 | - 'lib/main.dart' 45 | - 'ios/Runner.xcodeproj/project.pbxproj' 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simple TCP Client 2 | 3 | This is a simple chat client based on Flutter 4 | 5 | ## Screenshots 6 | 7 | ![Message Page](https://pic.linloir.cn/images/2022/10/21/message_page.png) 8 | ![Contacts Page](https://pic.linloir.cn/images/2022/10/21/contacts_page.png) 9 | ![Profile Page](https://pic.linloir.cn/images/2022/10/21/profile_page.png) 10 | ![Chat Page](https://pic.linloir.cn/images/2022/10/21/chat_page.png) 11 | ![Search Page](https://pic.linloir.cn/images/2022/10/21/search_page.png) 12 | -------------------------------------------------------------------------------- /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 33 30 | ndkVersion flutter.ndkVersion 31 | 32 | compileOptions { 33 | sourceCompatibility JavaVersion.VERSION_1_8 34 | targetCompatibility JavaVersion.VERSION_1_8 35 | } 36 | 37 | kotlinOptions { 38 | jvmTarget = '1.8' 39 | } 40 | 41 | sourceSets { 42 | main.java.srcDirs += 'src/main/kotlin' 43 | } 44 | 45 | defaultConfig { 46 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 47 | applicationId "com.example.tcp_client" 48 | // You can update the following values to match your application needs. 49 | // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. 50 | minSdkVersion flutter.minSdkVersion 51 | targetSdkVersion flutter.targetSdkVersion 52 | versionCode flutterVersionCode.toInteger() 53 | versionName flutterVersionName 54 | } 55 | 56 | buildTypes { 57 | release { 58 | // TODO: Add your own signing config for the release build. 59 | // Signing with the debug keys for now, so `flutter run --release` works. 60 | signingConfig signingConfigs.debug 61 | } 62 | } 63 | } 64 | 65 | flutter { 66 | source '../..' 67 | } 68 | 69 | dependencies { 70 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 71 | } 72 | -------------------------------------------------------------------------------- /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 | 36 | -------------------------------------------------------------------------------- /android/app/src/main/kotlin/com/example/tcp_client/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.tcp_client 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/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/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.6.10' 3 | repositories { 4 | google() 5 | mavenCentral() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:7.1.2' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | mavenCentral() 18 | } 19 | } 20 | 21 | rootProject.buildDir = '../build' 22 | subprojects { 23 | project.buildDir = "${rootProject.buildDir}/${project.name}" 24 | } 25 | subprojects { 26 | project.evaluationDependsOn(':app') 27 | } 28 | 29 | task clean(type: Delete) { 30 | delete rootProject.buildDir 31 | } 32 | -------------------------------------------------------------------------------- /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.4-all.zip 6 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /inno_setup.iss: -------------------------------------------------------------------------------- 1 | ; Script generated by the Inno Setup Script Wizard. 2 | ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! 3 | 4 | #define MyAppName "LChatClient" 5 | #define MyAppVersion "1.1" 6 | #define MyAppPublisher "Linloir" 7 | #define MyAppExeName "LChatClient.exe" 8 | #define MyAppComp "com.linloir" 9 | 10 | [Setup] 11 | ; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications. 12 | ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.) 13 | AppId={{45C34500-34D4-4E59-A222-5BD12A410F98} 14 | AppName={#MyAppName} 15 | AppVersion={#MyAppVersion} 16 | ;AppVerName={#MyAppName} {#MyAppVersion} 17 | AppPublisher={#MyAppPublisher} 18 | DefaultDirName={autopf}\{#MyAppName} 19 | DisableProgramGroupPage=yes 20 | ; Uncomment the following line to run in non administrative install mode (install for current user only.) 21 | ;PrivilegesRequired=lowest 22 | PrivilegesRequiredOverridesAllowed=dialog 23 | OutputDir=build\inno 24 | OutputBaseFilename=mysetup 25 | Compression=lzma 26 | SolidCompression=yes 27 | WizardStyle=modern 28 | 29 | [Languages] 30 | Name: "english"; MessagesFile: "compiler:Default.isl" 31 | 32 | [Tasks] 33 | Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked 34 | 35 | [Files] 36 | Source: "build\windows\runner\Release\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion 37 | Source: "build\windows\runner\Release\data\*"; DestDir: "{app}\data"; Flags: ignoreversion recursesubdirs createallsubdirs 38 | Source: "build\windows\runner\Release\flutter_windows.dll"; DestDir: "{app}"; Flags: ignoreversion 39 | Source: "build\windows\runner\Release\window_manager_plugin.dll"; DestDir: "{app}"; Flags: ignoreversion 40 | Source: "build\windows\runner\Release\screen_retriever_plugin.dll"; DestDir: "{app}"; Flags: ignoreversion 41 | Source: "build\windows\runner\Release\sqlite3.dll"; DestDir: "{app}"; Flags: ignoreversion 42 | ; NOTE: Don't use "Flags: ignoreversion" on any shared system files 43 | 44 | [Dirs] 45 | Name: "{userappdata}\{#MyAppComp}\{#MyAppName}"; Flags: uninsalwaysuninstall 46 | Name: "{userdocs}\{#MyAppName}"; Flags: uninsalwaysuninstall 47 | 48 | [Icons] 49 | Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}" 50 | Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon 51 | 52 | [UninstallDelete] 53 | Type: filesandordirs; Name: "{userdocs}\{#MyAppName}\*" 54 | Type: filesandordirs; Name: "{userdocs}\{#MyAppName}" 55 | Type: filesandordirs; Name: "{userappdata}\{#MyAppComp}\{#MyAppName}\*" 56 | Type: filesandordirs; Name: "{userappdata}\{#MyAppComp}\{#MyAppName}" 57 | Type: dirifempty; Name: "{userappdata}\{#MyAppComp}" 58 | 59 | [Run] 60 | Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent 61 | 62 | -------------------------------------------------------------------------------- /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 "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /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 | 8 | -------------------------------------------------------------------------------- /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/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/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/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/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/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/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/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/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/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/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/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/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/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/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/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/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/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/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/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/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/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/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/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/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/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/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/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/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/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/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/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/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 | Tcp Client 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | tcp_client 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 | -------------------------------------------------------------------------------- /lib/chat/chat_page.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 14:03:16 4 | * @LastEditTime : 2022-10-20 10:52:30 5 | * @Description : 6 | */ 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:flutter_bloc/flutter_bloc.dart'; 10 | import 'package:tcp_client/chat/cubit/chat_cubit.dart'; 11 | import 'package:tcp_client/chat/cubit/chat_state.dart'; 12 | import 'package:tcp_client/chat/view/history_tile.dart'; 13 | import 'package:tcp_client/chat/view/input_box/input_box.dart'; 14 | import 'package:tcp_client/common/username/username.dart'; 15 | import 'package:tcp_client/repositories/local_service_repository/local_service_repository.dart'; 16 | import 'package:tcp_client/repositories/tcp_repository/tcp_repository.dart'; 17 | import 'package:tcp_client/repositories/user_repository/user_repository.dart'; 18 | 19 | class ChatPage extends StatelessWidget { 20 | const ChatPage({ 21 | required this.userRepository, 22 | required this.localServiceRepository, 23 | required this.tcpRepository, 24 | required this.userID, 25 | super.key 26 | }); 27 | 28 | final int userID; 29 | final UserRepository userRepository; 30 | final LocalServiceRepository localServiceRepository; 31 | final TCPRepository tcpRepository; 32 | 33 | static Route route({ 34 | required UserRepository userRepository, 35 | required LocalServiceRepository localServiceRepository, 36 | required TCPRepository tcpRepository, 37 | required int userID 38 | }) => MaterialPageRoute(builder: (context) => ChatPage( 39 | userID: userID, 40 | userRepository: userRepository, 41 | localServiceRepository: localServiceRepository, 42 | tcpRepository: tcpRepository, 43 | )); 44 | 45 | @override 46 | Widget build(BuildContext context) { 47 | return RepositoryProvider.value( 48 | value: userRepository, 49 | child: BlocProvider( 50 | create: (context) => ChatCubit( 51 | userID: userID, 52 | localServiceRepository: localServiceRepository, 53 | tcpRepository: tcpRepository 54 | ), 55 | child: Scaffold( 56 | appBar: AppBar( 57 | title: UserNameText( 58 | userid: userID, 59 | fontWeight: FontWeight.bold, 60 | ) 61 | ), 62 | body: Column( 63 | children: [ 64 | Expanded( 65 | child: BlocBuilder( 66 | builder: (context, state) { 67 | return ListView.builder( 68 | physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), 69 | reverse: true, 70 | itemBuilder: (context, index) { 71 | if(index == state.chatHistory.length) { 72 | //Load more 73 | context.read().fetchHistory(); 74 | //Show loading indicator 75 | return const Align( 76 | alignment: Alignment.center, 77 | child: SizedBox( 78 | width: 24, 79 | height: 24, 80 | child: CircularProgressIndicator( 81 | color: Colors.blue, 82 | strokeWidth: 2.0, 83 | ), 84 | ), 85 | ); 86 | } 87 | else { 88 | //Return history tile 89 | return Padding( 90 | padding: const EdgeInsets.symmetric( 91 | horizontal: 24, 92 | vertical: 8 93 | ), 94 | child: HistoryTile( 95 | history: state.chatHistory[index], 96 | ), 97 | ); 98 | } 99 | }, 100 | itemCount: state.status == ChatStatus.full ? state.chatHistory.length : state.chatHistory.length + 1, 101 | ); 102 | }, 103 | ), 104 | ), 105 | InputBox() 106 | ] 107 | ), 108 | ) 109 | ), 110 | ); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /lib/chat/cubit/chat_state.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 14:03:52 4 | * @LastEditTime : 2022-10-14 23:04:07 5 | * @Description : 6 | */ 7 | 8 | import 'package:equatable/equatable.dart'; 9 | import 'package:tcp_client/chat/model/chat_history.dart'; 10 | 11 | enum ChatStatus { fetching, partial, full } 12 | 13 | class ChatState extends Equatable { 14 | final ChatStatus status; 15 | final List chatHistory; 16 | 17 | const ChatState({required this.chatHistory, required this.status}); 18 | 19 | static ChatState empty() => const ChatState(chatHistory: [], status: ChatStatus.fetching); 20 | 21 | ChatState copyWith({ 22 | ChatStatus? status, 23 | List? chatHistory 24 | }) { 25 | return ChatState( 26 | status: status ?? this.status, 27 | chatHistory: chatHistory ?? this.chatHistory 28 | ); 29 | } 30 | 31 | @override 32 | List get props => [...chatHistory, status]; 33 | } 34 | -------------------------------------------------------------------------------- /lib/chat/model/chat_history.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-14 14:55:20 4 | * @LastEditTime : 2022-10-20 11:01:03 5 | * @Description : 6 | */ 7 | 8 | import 'package:equatable/equatable.dart'; 9 | import 'package:flutter/material.dart'; 10 | import 'package:tcp_client/repositories/common_models/message.dart'; 11 | 12 | enum ChatHistoryType { outcome, income } 13 | enum ChatHistoryStatus { none, processing, sending, downloading, done, failed } 14 | 15 | class ChatHistory extends Equatable { 16 | final Message message; 17 | final ChatHistoryType type; 18 | final ChatHistoryStatus status; 19 | final Image? preCachedImage; 20 | 21 | const ChatHistory({ 22 | required this.message, 23 | required this.type, 24 | required this.status, 25 | this.preCachedImage, 26 | }); 27 | 28 | ChatHistory copyWith({ 29 | Message? message, 30 | ChatHistoryType? type, 31 | ChatHistoryStatus? status, 32 | Image? preCachedImage 33 | }) { 34 | return ChatHistory( 35 | message: message ?? this.message, 36 | type: type ?? this.type, 37 | status: status ?? this.status, 38 | preCachedImage: preCachedImage ?? this.preCachedImage 39 | ); 40 | } 41 | 42 | @override 43 | List get props => [message.contentmd5, type, status]; 44 | } 45 | -------------------------------------------------------------------------------- /lib/chat/view/common/file_box.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-14 17:07:13 4 | * @LastEditTime : 2022-10-18 15:44:34 5 | * @Description : 6 | */ 7 | 8 | import 'package:easy_debounce/easy_debounce.dart'; 9 | import 'package:flutter/material.dart'; 10 | import 'package:flutter_bloc/flutter_bloc.dart'; 11 | import 'package:loading_indicator/loading_indicator.dart'; 12 | import 'package:tcp_client/chat/cubit/chat_cubit.dart'; 13 | import 'package:tcp_client/chat/model/chat_history.dart'; 14 | 15 | class FileBox extends StatelessWidget { 16 | const FileBox({ 17 | required this.history, 18 | super.key 19 | }); 20 | 21 | final ChatHistory history; 22 | 23 | @override 24 | Widget build(BuildContext context) { 25 | return InkWell( 26 | onTap: (history.status == ChatHistoryStatus.downloading || history.status == ChatHistoryStatus.sending || history.status == ChatHistoryStatus.processing) ? null : () { 27 | EasyDebounce.debounce( 28 | 'findfile${history.message.contentmd5}', 29 | const Duration(milliseconds: 500), 30 | () { 31 | context.read().openFile( 32 | message: history.message 33 | ); 34 | } 35 | ); 36 | }, 37 | child: Padding( 38 | padding: const EdgeInsets.all(8.0), 39 | child: Row( 40 | mainAxisSize: MainAxisSize.min, 41 | children: [ 42 | Container( 43 | child: history.status == ChatHistoryStatus.none || history.status == ChatHistoryStatus.done ? 44 | Icon( 45 | Icons.file_present_rounded, 46 | size: 24, 47 | color: history.type == ChatHistoryType.income ? Colors.blue[800] : Colors.white.withOpacity(0.8), 48 | ) : history.status == ChatHistoryStatus.failed ? 49 | Icon( 50 | Icons.refresh_rounded, 51 | size: 24, 52 | color: history.type == ChatHistoryType.income ? Colors.red[800] : Colors.white.withOpacity(0.8), 53 | ) : history.status == ChatHistoryStatus.processing ? 54 | SizedBox( 55 | height: 18.0, 56 | width: 18.0, 57 | child: LoadingIndicator( 58 | indicatorType: Indicator.ballPulseSync, 59 | colors: [Colors.white.withOpacity(0.8)], 60 | ), 61 | ) : 62 | SizedBox( 63 | height: 18.0, 64 | width: 18.0, 65 | child: CircularProgressIndicator( 66 | color: history.type == ChatHistoryType.income ? Colors.blue[800] : Colors.white.withOpacity(0.8), 67 | strokeWidth: 3, 68 | ), 69 | ) 70 | ), 71 | const SizedBox(width: 18.0,), 72 | Flexible( 73 | child: Text( 74 | history.message.contentDecoded, 75 | softWrap: true, 76 | style: TextStyle( 77 | fontSize: 20.0, 78 | color: history.type == ChatHistoryType.income ? Colors.grey[900] : Colors.white 79 | ), 80 | ), 81 | ), 82 | ], 83 | ), 84 | ), 85 | ); 86 | } 87 | } -------------------------------------------------------------------------------- /lib/chat/view/common/image_box.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-14 17:04:20 4 | * @LastEditTime : 2022-10-20 13:47:29 5 | * @Description : 6 | */ 7 | 8 | import 'dart:convert'; 9 | 10 | import 'package:flutter/material.dart'; 11 | import 'package:tcp_client/chat/model/chat_history.dart'; 12 | 13 | class ImageBox extends StatelessWidget { 14 | const ImageBox({ 15 | required this.history, 16 | super.key 17 | }); 18 | 19 | final ChatHistory history; 20 | 21 | @override 22 | Widget build(BuildContext context) { 23 | return IntrinsicWidth( 24 | child: IntrinsicHeight( 25 | child: Stack( 26 | children: [ 27 | Container( 28 | constraints: const BoxConstraints(maxWidth: 500, maxHeight: 200), 29 | child: history.preCachedImage ?? Image.memory(base64Decode(history.message.contentDecoded)), 30 | ), 31 | Material( 32 | color: Colors.transparent, 33 | child: InkWell( 34 | splashColor: Colors.white.withOpacity(0.1), 35 | onTap: (){}, 36 | ) 37 | ), 38 | ] 39 | ), 40 | ), 41 | ); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /lib/chat/view/common/text_box.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-14 17:04:12 4 | * @LastEditTime : 2022-10-15 10:53:28 5 | * @Description : 6 | */ 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:flutter_bloc/flutter_bloc.dart'; 10 | import 'package:shared_preferences/shared_preferences.dart'; 11 | import 'package:tcp_client/chat/cubit/chat_cubit.dart'; 12 | import 'package:tcp_client/chat/model/chat_history.dart'; 13 | import 'package:tcp_client/repositories/tcp_repository/models/tcp_request.dart'; 14 | 15 | class TextBox extends StatelessWidget { 16 | const TextBox({ 17 | required this.history, 18 | super.key 19 | }); 20 | 21 | final ChatHistory history; 22 | 23 | @override 24 | Widget build(BuildContext context) { 25 | return InkWell( 26 | onTap: (){}, 27 | child: Padding( 28 | padding: const EdgeInsets.all(8.0), 29 | child: Row( 30 | crossAxisAlignment: CrossAxisAlignment.center, 31 | mainAxisSize: MainAxisSize.min, 32 | children: [ 33 | if(history.type == ChatHistoryType.outcome) 34 | ...[ 35 | if(history.status == ChatHistoryStatus.sending) 36 | ...[ 37 | SizedBox( 38 | height: 15.0, 39 | width: 15.0, 40 | child: CircularProgressIndicator( 41 | color: Colors.white.withOpacity(0.5), 42 | strokeWidth: 2.0, 43 | ), 44 | ), 45 | const SizedBox(width: 16.0,), 46 | ], 47 | if(history.status == ChatHistoryStatus.failed) 48 | ...[ 49 | ClipOval( 50 | child: Material( 51 | color: Colors.transparent, 52 | child: InkWell( 53 | child: Icon( 54 | Icons.error_rounded, 55 | color: Colors.white.withOpacity(0.5), 56 | size: 20, 57 | ), 58 | onTap: () async { 59 | context.read().tcpRepository.pushRequest(SendMessageRequest( 60 | message: history.message, 61 | token: (await SharedPreferences.getInstance()).getInt('token') 62 | )); 63 | }, 64 | ), 65 | ), 66 | ), 67 | const SizedBox(width: 8.0,), 68 | ], 69 | if(history.status == ChatHistoryStatus.done) 70 | ...[ 71 | Icon( 72 | Icons.check_rounded, 73 | color: Colors.white.withOpacity(0.5), 74 | size: 20, 75 | ), 76 | const SizedBox(width: 12.0,), 77 | ], 78 | ], 79 | Flexible( 80 | child: Text( 81 | history.message.contentDecoded, 82 | softWrap: true, 83 | style: TextStyle( 84 | fontSize: 18, 85 | color: history.type == ChatHistoryType.income ? Colors.grey[900] : Colors.white 86 | ), 87 | ), 88 | ), 89 | ] 90 | ) 91 | ), 92 | ); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /lib/chat/view/history_tile.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 14:03:45 4 | * @LastEditTime : 2022-10-15 10:52:30 5 | * @Description : 6 | */ 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:tcp_client/chat/model/chat_history.dart'; 10 | import 'package:tcp_client/chat/view/in_message_box.dart'; 11 | import 'package:tcp_client/chat/view/out_message_box.dart'; 12 | import 'package:tcp_client/common/avatar/avatar.dart'; 13 | 14 | class HistoryTile extends StatelessWidget { 15 | const HistoryTile({ 16 | required this.history, 17 | super.key 18 | }); 19 | 20 | final ChatHistory history; 21 | 22 | @override 23 | Widget build(BuildContext context) { 24 | return Row( 25 | crossAxisAlignment: CrossAxisAlignment.start, 26 | mainAxisSize: MainAxisSize.max, 27 | mainAxisAlignment: history.type == ChatHistoryType.income ? MainAxisAlignment.start : MainAxisAlignment.end, 28 | children: [ 29 | if(history.type == ChatHistoryType.income) 30 | ...[ 31 | Expanded( 32 | flex: 5, 33 | child: Row( 34 | crossAxisAlignment: CrossAxisAlignment.end, 35 | mainAxisSize: MainAxisSize.min, 36 | children: [ 37 | UserAvatar(userid: history.message.senderID), 38 | const SizedBox(width: 16.0,), 39 | Flexible( 40 | child: InMessageBox(history: history) 41 | ), 42 | ], 43 | ) 44 | ), 45 | const Spacer(flex: 1,), 46 | ], 47 | if(history.type == ChatHistoryType.outcome) 48 | ...[ 49 | const Spacer(flex: 1,), 50 | Expanded( 51 | flex: 5, 52 | child: Row( 53 | mainAxisAlignment: MainAxisAlignment.end, 54 | mainAxisSize: MainAxisSize.min, 55 | crossAxisAlignment: CrossAxisAlignment.end, 56 | children: [ 57 | Flexible( 58 | child: OutMessageBox(history: history), 59 | ), 60 | const SizedBox(width: 16.0,), 61 | UserAvatar(userid: history.message.senderID), 62 | ], 63 | ) 64 | ), 65 | ] 66 | ], 67 | ); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /lib/chat/view/in_message_box.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-14 13:49:47 4 | * @LastEditTime : 2022-10-20 13:56:20 5 | * @Description : 6 | */ 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:tcp_client/chat/model/chat_history.dart'; 10 | import 'package:tcp_client/chat/view/common/file_box.dart'; 11 | import 'package:tcp_client/chat/view/common/image_box.dart'; 12 | import 'package:tcp_client/chat/view/common/text_box.dart'; 13 | import 'package:tcp_client/repositories/common_models/message.dart'; 14 | 15 | class InMessageBox extends StatelessWidget { 16 | const InMessageBox({ 17 | required this.history, 18 | super.key 19 | }); 20 | 21 | final ChatHistory history; 22 | 23 | @override 24 | Widget build(BuildContext context) { 25 | return Column( 26 | mainAxisSize: MainAxisSize.min, 27 | crossAxisAlignment: CrossAxisAlignment.start, 28 | children: [ 29 | AnimatedContainer( 30 | key: ValueKey(history.message.contentmd5), 31 | duration: const Duration(milliseconds: 375), 32 | padding: history.message.type == MessageType.image ? 33 | const EdgeInsets.all(0) : 34 | const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0), 35 | decoration: BoxDecoration( 36 | color: Colors.grey[50], 37 | borderRadius: const BorderRadius.only( 38 | topLeft: Radius.circular(8.0), 39 | topRight: Radius.circular(8.0), 40 | bottomLeft: Radius.zero, 41 | bottomRight: Radius.circular(8.0) 42 | ), 43 | boxShadow: [BoxShadow(blurRadius: 5.0, color: Colors.grey.withOpacity(0.3))] 44 | ), 45 | child: ClipRRect( 46 | borderRadius: const BorderRadius.only( 47 | topLeft: Radius.circular(8.0), 48 | topRight: Radius.circular(8.0), 49 | bottomLeft: Radius.zero, 50 | bottomRight: Radius.circular(8.0) 51 | ), 52 | child: Column( 53 | crossAxisAlignment: CrossAxisAlignment.start, 54 | mainAxisSize: MainAxisSize.min, 55 | children: [ 56 | if(history.message.type == MessageType.file) 57 | FileBox(history: history), 58 | if(history.message.type == MessageType.image) 59 | ImageBox(history: history), 60 | if(history.message.type == MessageType.plaintext) 61 | TextBox(history: history), 62 | if(history.message.type != MessageType.image) 63 | ...[ 64 | const SizedBox(height: 4.0,), 65 | Text( 66 | _getTimeStamp(history.message.timeStamp), 67 | style: TextStyle( 68 | fontSize: 12, 69 | color: Colors.grey[400], 70 | ), 71 | ) 72 | ] 73 | ], 74 | ), 75 | ) 76 | ), 77 | if(history.message.type == MessageType.image) 78 | ...[ 79 | const SizedBox(height: 4.0,), 80 | Text( 81 | _getTimeStamp(history.message.timeStamp), 82 | style: TextStyle( 83 | fontSize: 12, 84 | color: Colors.grey[600], 85 | ), 86 | ), 87 | ] 88 | ] 89 | ); 90 | } 91 | 92 | String _getTimeStamp(int timeStamp) { 93 | var date = DateTime.fromMillisecondsSinceEpoch(timeStamp); 94 | var weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']; 95 | //If date is today, return time 96 | if(date.day == DateTime.now().day) { 97 | return '${date.hour}:${date.minute.toString().padLeft(2, '0')}'; 98 | } 99 | //If date is yesterday, return 'yesterday' 100 | if(date.day == DateTime.now().day - 1) { 101 | return 'yesterday ${date.hour}:${date.minute.toString().padLeft(2, '0')}'; 102 | } 103 | //If date is within this week, return the weekday in english 104 | if(date.weekday < DateTime.now().weekday) { 105 | return '${weekdays[date.weekday - 1]} ${date.hour}:${date.minute.toString().padLeft(2, '0')}'; 106 | } 107 | //Otherwise return the date in english 108 | return '${date.month}/${date.day} ${date.hour}:${date.minute.toString().padLeft(2, '0')}'; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /lib/chat/view/input_box/cubit/input_cubit.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-14 21:57:05 4 | * @LastEditTime : 2022-10-18 15:30:09 5 | * @Description : 6 | */ 7 | 8 | import 'package:bloc/bloc.dart'; 9 | import 'package:formz/formz.dart'; 10 | import 'package:shared_preferences/shared_preferences.dart'; 11 | import 'package:tcp_client/chat/cubit/chat_cubit.dart'; 12 | import 'package:tcp_client/chat/view/input_box/cubit/input_state.dart'; 13 | import 'package:tcp_client/chat/view/input_box/model/input.dart'; 14 | import 'package:tcp_client/repositories/common_models/message.dart'; 15 | 16 | class MessageInputCubit extends Cubit { 17 | MessageInputCubit({ 18 | required this.chatCubit, 19 | }): super(const MessageInputState()); 20 | 21 | final ChatCubit chatCubit; 22 | 23 | void onInputChange(MessageInput input) { 24 | emit(state.copyWith( 25 | status: Formz.validate([input]), 26 | input: input 27 | )); 28 | } 29 | 30 | Future onSubmission() async { 31 | chatCubit.addMessage(Message( 32 | userid: (await SharedPreferences.getInstance()).getInt('userid')!, 33 | targetid: chatCubit.userID, 34 | contenttype: MessageType.plaintext, 35 | content: state.input.value, 36 | )); 37 | emit(state.copyWith( 38 | status: FormzStatus.pure, 39 | input: const MessageInput.pure() 40 | )); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /lib/chat/view/input_box/cubit/input_state.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-14 21:56:53 4 | * @LastEditTime : 2022-10-14 21:59:51 5 | * @Description : 6 | */ 7 | 8 | import 'package:equatable/equatable.dart'; 9 | import 'package:formz/formz.dart'; 10 | import 'package:tcp_client/chat/view/input_box/model/input.dart'; 11 | 12 | class MessageInputState extends Equatable { 13 | final MessageInput input; 14 | 15 | final FormzStatus status; 16 | 17 | const MessageInputState({ 18 | this.status = FormzStatus.pure, 19 | this.input = const MessageInput.pure() 20 | }); 21 | 22 | MessageInputState copyWith({ 23 | FormzStatus? status, 24 | MessageInput? input 25 | }) { 26 | return MessageInputState( 27 | input: input ?? this.input, 28 | status: status ?? this.status 29 | ); 30 | } 31 | 32 | @override 33 | List get props => [status, input]; 34 | } -------------------------------------------------------------------------------- /lib/chat/view/input_box/model/input.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-14 21:57:44 4 | * @LastEditTime : 2022-10-14 21:57:44 5 | * @Description : 6 | */ 7 | 8 | import 'package:formz/formz.dart'; 9 | 10 | enum MessageInputValidationError { empty } 11 | 12 | class MessageInput extends FormzInput { 13 | const MessageInput.pure() : super.pure(''); 14 | const MessageInput.dirty([super.value = '']) : super.dirty(); 15 | 16 | @override 17 | MessageInputValidationError? validator(String? value) { 18 | return value?.isNotEmpty == true ? null : MessageInputValidationError.empty; 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /lib/chat/view/out_message_box.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-14 13:49:28 4 | * @LastEditTime : 2022-10-19 23:47:20 5 | * @Description : 6 | */ 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:tcp_client/chat/model/chat_history.dart'; 10 | import 'package:tcp_client/chat/view/common/file_box.dart'; 11 | import 'package:tcp_client/chat/view/common/image_box.dart'; 12 | import 'package:tcp_client/chat/view/common/text_box.dart'; 13 | import 'package:tcp_client/repositories/common_models/message.dart'; 14 | 15 | class OutMessageBox extends StatelessWidget { 16 | const OutMessageBox({ 17 | required this.history, 18 | super.key 19 | }); 20 | 21 | final ChatHistory history; 22 | 23 | @override 24 | Widget build(BuildContext context) { 25 | return Column( 26 | mainAxisSize: MainAxisSize.min, 27 | crossAxisAlignment: CrossAxisAlignment.end, 28 | children: [ 29 | AnimatedContainer( 30 | key: ValueKey(history.message.contentmd5), 31 | duration: const Duration(milliseconds: 375), 32 | padding: history.message.type == MessageType.image ? 33 | const EdgeInsets.all(0) : 34 | const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0), 35 | decoration: BoxDecoration( 36 | color: Colors.blue, 37 | borderRadius: const BorderRadius.only( 38 | topLeft: Radius.circular(8.0), 39 | topRight: Radius.circular(8.0), 40 | bottomLeft: Radius.circular(8.0), 41 | bottomRight: Radius.zero 42 | ), 43 | boxShadow: [BoxShadow(blurRadius: 5.0, color: Colors.grey.withOpacity(0.2))] 44 | ), 45 | child: ClipRRect( 46 | borderRadius: const BorderRadius.only( 47 | topLeft: Radius.circular(8.0), 48 | topRight: Radius.circular(8.0), 49 | bottomLeft: Radius.circular(8.0), 50 | bottomRight: Radius.zero 51 | ), 52 | child: Column( 53 | crossAxisAlignment: CrossAxisAlignment.end, 54 | mainAxisSize: MainAxisSize.min, 55 | children: [ 56 | if(history.message.type == MessageType.file) 57 | FileBox(history: history), 58 | if(history.message.type == MessageType.image) 59 | ImageBox(history: history), 60 | if(history.message.type == MessageType.plaintext) 61 | TextBox(history: history), 62 | if(history.message.type != MessageType.image) 63 | ...[ 64 | const SizedBox(height: 4.0,), 65 | Text( 66 | _getTimeStamp(history.message.timeStamp), 67 | style: TextStyle( 68 | fontSize: 12, 69 | color: Colors.grey[200], 70 | ), 71 | ) 72 | ], 73 | ], 74 | ), 75 | ) 76 | ), 77 | if(history.message.type == MessageType.image) 78 | ...[ 79 | const SizedBox(height: 4.0,), 80 | Text( 81 | _getTimeStamp(history.message.timeStamp), 82 | style: TextStyle( 83 | fontSize: 12, 84 | color: Colors.grey[800], 85 | ), 86 | ), 87 | ] 88 | ] 89 | ); 90 | } 91 | 92 | String _getTimeStamp(int timeStamp) { 93 | var date = DateTime.fromMillisecondsSinceEpoch(timeStamp); 94 | var weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']; 95 | //If date is today, return time 96 | if(date.day == DateTime.now().day) { 97 | return '${date.hour}:${date.minute.toString().padLeft(2, '0')}'; 98 | } 99 | //If date is yesterday, return 'yesterday' 100 | if(date.day == DateTime.now().day - 1) { 101 | return 'yesterday ${date.hour}:${date.minute.toString().padLeft(2, '0')}'; 102 | } 103 | //If date is within this week, return the weekday in english 104 | if(date.weekday < DateTime.now().weekday) { 105 | return '${weekdays[date.weekday - 1]} ${date.hour}:${date.minute.toString().padLeft(2, '0')}'; 106 | } 107 | //Otherwise return the date in english 108 | return '${date.month}/${date.day} ${date.hour}:${date.minute.toString().padLeft(2, '0')}'; 109 | } 110 | } -------------------------------------------------------------------------------- /lib/common/avatar/avatar.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 21:49:53 4 | * @LastEditTime : 2022-10-20 18:02:23 5 | * @Description : 6 | */ 7 | 8 | import 'dart:convert'; 9 | 10 | import 'package:flutter/material.dart'; 11 | import 'package:flutter_bloc/flutter_bloc.dart'; 12 | import 'package:tcp_client/common/avatar/cubit/avatar_cubit.dart'; 13 | import 'package:tcp_client/common/avatar/cubit/avatar_state.dart'; 14 | import 'package:tcp_client/repositories/user_repository/user_repository.dart'; 15 | 16 | class UserAvatar extends StatelessWidget { 17 | const UserAvatar({ 18 | required this.userid, 19 | this.size = 48, 20 | this.onTap, 21 | super.key 22 | }); 23 | 24 | final int userid; 25 | final double size; 26 | final void Function()? onTap; 27 | 28 | @override 29 | Widget build(BuildContext context) { 30 | return BlocBuilder( 31 | bloc: AvatarCubit( 32 | userid: userid, 33 | userRepository: context.read() 34 | ), 35 | builder: (context, state) { 36 | if(state.userInfo.avatarEncoded == null) { 37 | return Container( 38 | width: size, 39 | height: size, 40 | decoration: BoxDecoration( 41 | color: Colors.grey[600], 42 | borderRadius: BorderRadius.circular(5.0), 43 | boxShadow: [BoxShadow(blurRadius: 10.0, color: Colors.grey[850]!.withOpacity(0.15))] 44 | ), 45 | child: ClipRRect( 46 | borderRadius: BorderRadius.circular(5.0), 47 | child: Material( 48 | color: Colors.transparent, 49 | child: InkWell( 50 | onTap: onTap, 51 | child: Align( 52 | alignment: Alignment.center, 53 | child: Text( 54 | state.userInfo.userName[0].toUpperCase(), 55 | style: TextStyle( 56 | fontSize: 24 * (size / 48), 57 | fontWeight: FontWeight.w300, 58 | color: Colors.white, 59 | shadows: [Shadow(blurRadius: 5.0, color: Colors.white.withOpacity(0.15))] 60 | ), 61 | ), 62 | ), 63 | ), 64 | ), 65 | ), 66 | ); 67 | } 68 | else { 69 | return Container( 70 | width: size, 71 | height: size, 72 | decoration: BoxDecoration( 73 | borderRadius: BorderRadius.circular(5.0), 74 | boxShadow: [BoxShadow(blurRadius: 10.0, color: Colors.grey[850]!.withOpacity(0.15))] 75 | ), 76 | child: ClipRRect( 77 | borderRadius: BorderRadius.circular(5.0), 78 | child: Stack( 79 | fit: StackFit.passthrough, 80 | children: [ 81 | OverflowBox( 82 | alignment: Alignment.center, 83 | child: FittedBox( 84 | fit: BoxFit.cover, 85 | child: Image.memory(base64.decode(state.userInfo.avatarEncoded!)), 86 | ), 87 | ), 88 | Material( 89 | color: Colors.transparent, 90 | child: InkWell( 91 | onTap: onTap, 92 | ), 93 | ), 94 | ], 95 | ), 96 | ), 97 | ); 98 | } 99 | }, 100 | ); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /lib/common/avatar/cubit/avatar_cubit.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 21:50:14 4 | * @LastEditTime : 2022-10-20 18:03:54 5 | * @Description : 6 | */ 7 | 8 | import 'package:bloc/bloc.dart'; 9 | import 'package:tcp_client/common/avatar/cubit/avatar_state.dart'; 10 | import 'package:tcp_client/repositories/common_models/userinfo.dart'; 11 | import 'package:tcp_client/repositories/user_repository/user_repository.dart'; 12 | 13 | class AvatarCubit extends Cubit { 14 | AvatarCubit({ 15 | required int userid, 16 | required this.userRepository 17 | }): super(AvatarState(userInfo: userRepository.getUserInfo(userid: userid))) 18 | { 19 | userRepository.userInfoStreamBroadcast.listen(onFetchedUserInfo); 20 | } 21 | 22 | final UserRepository userRepository; 23 | 24 | void onFetchedUserInfo(UserInfo userInfo) { 25 | if(userInfo.userID == state.userInfo.userID) { 26 | emit(AvatarState( 27 | userInfo: userInfo 28 | )); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /lib/common/avatar/cubit/avatar_state.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 21:50:07 4 | * @LastEditTime : 2022-10-20 18:02:15 5 | * @Description : 6 | */ 7 | 8 | import 'package:equatable/equatable.dart'; 9 | import 'package:tcp_client/repositories/common_models/userinfo.dart'; 10 | 11 | class AvatarState extends Equatable { 12 | const AvatarState({ 13 | required this.userInfo, 14 | }); 15 | 16 | final UserInfo userInfo; 17 | 18 | @override 19 | List get props => [userInfo.userID, userInfo.avatarEncoded]; 20 | } 21 | -------------------------------------------------------------------------------- /lib/common/username/cubit/username_cubit.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 21:50:14 4 | * @LastEditTime : 2022-10-13 22:05:52 5 | * @Description : 6 | */ 7 | 8 | import 'package:bloc/bloc.dart'; 9 | import 'package:tcp_client/common/username/cubit/username_state.dart'; 10 | import 'package:tcp_client/repositories/common_models/userinfo.dart'; 11 | import 'package:tcp_client/repositories/user_repository/user_repository.dart'; 12 | 13 | class UsernameCubit extends Cubit { 14 | UsernameCubit({ 15 | required int userid, 16 | required this.userRepository 17 | }): super(UsernameState(userInfo: userRepository.getUserInfo(userid: userid))) { 18 | userRepository.userInfoStreamBroadcast.listen(onFetchedUserInfo); 19 | } 20 | 21 | final UserRepository userRepository; 22 | 23 | void onFetchedUserInfo(UserInfo userInfo) { 24 | if(userInfo.userID == state.userInfo.userID) { 25 | emit(UsernameState(userInfo: userInfo)); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /lib/common/username/cubit/username_state.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 21:50:07 4 | * @LastEditTime : 2022-10-13 22:05:43 5 | * @Description : 6 | */ 7 | 8 | import 'package:equatable/equatable.dart'; 9 | import 'package:tcp_client/repositories/common_models/userinfo.dart'; 10 | 11 | class UsernameState extends Equatable { 12 | const UsernameState({ 13 | required this.userInfo, 14 | }); 15 | 16 | final UserInfo userInfo; 17 | 18 | @override 19 | List get props => [userInfo.userID, userInfo.avatarEncoded]; 20 | } 21 | -------------------------------------------------------------------------------- /lib/common/username/username.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 22:05:12 4 | * @LastEditTime : 2022-10-14 12:10:46 5 | * @Description : 6 | */ 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:flutter_bloc/flutter_bloc.dart'; 10 | import 'package:tcp_client/common/username/cubit/username_cubit.dart'; 11 | import 'package:tcp_client/common/username/cubit/username_state.dart'; 12 | import 'package:tcp_client/repositories/user_repository/user_repository.dart'; 13 | 14 | class UserNameText extends StatelessWidget { 15 | const UserNameText({ 16 | required this.userid, 17 | this.fontWeight = FontWeight.normal, 18 | this.fontSize = 18, 19 | this.alignment = Alignment.centerLeft, 20 | super.key 21 | }); 22 | 23 | final int userid; 24 | final FontWeight fontWeight; 25 | final double fontSize; 26 | final Alignment alignment; 27 | 28 | @override 29 | Widget build(BuildContext context) { 30 | return BlocBuilder( 31 | bloc: UsernameCubit( 32 | userid: userid, 33 | userRepository: context.read() 34 | ), 35 | builder: (context, state) { 36 | return Align( 37 | alignment: alignment, 38 | child: Text( 39 | state.userInfo.userName, 40 | style: TextStyle( 41 | fontSize: fontSize, 42 | fontWeight: fontWeight 43 | ), 44 | ), 45 | ); 46 | } 47 | ); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lib/home/cubit/home_cubit.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 14:02:28 4 | * @LastEditTime : 2022-10-17 19:26:13 5 | * @Description : 6 | */ 7 | 8 | import 'dart:async'; 9 | 10 | import 'package:bloc/bloc.dart'; 11 | import 'package:flutter/cupertino.dart'; 12 | import 'package:tcp_client/home/cubit/home_state.dart'; 13 | import 'package:tcp_client/repositories/local_service_repository/local_service_repository.dart'; 14 | import 'package:tcp_client/repositories/tcp_repository/models/tcp_response.dart'; 15 | import 'package:tcp_client/repositories/tcp_repository/tcp_repository.dart'; 16 | 17 | class HomeCubit extends Cubit { 18 | HomeCubit({ 19 | required this.localServiceRepository, 20 | required this.tcpRepository, 21 | required this.pageController 22 | }): super(const HomeState(page: HomePagePosition.message)) { 23 | pageController.addListener(() { 24 | emit(state.copyWith(page: HomePagePosition.fromValue((pageController.page ?? 0).round()))); 25 | }); 26 | subscription = tcpRepository.responseStreamBroadcast.listen(_onTCPResponse); 27 | } 28 | 29 | final LocalServiceRepository localServiceRepository; 30 | final TCPRepository tcpRepository; 31 | final PageController pageController; 32 | late final StreamSubscription subscription; 33 | 34 | void switchPage(HomePagePosition newPage) { 35 | pageController.animateToPage( 36 | newPage.value, 37 | duration: const Duration(milliseconds: 500), 38 | curve: Curves.easeInOutCubicEmphasized 39 | ); 40 | } 41 | 42 | void _onTCPResponse(TCPResponse response) { 43 | switch(response.type) { 44 | case TCPResponseType.forwardMessage: { 45 | response as ForwardMessageResponse; 46 | localServiceRepository.storeMessages([response.message]); 47 | break; 48 | } 49 | case TCPResponseType.fetchMessage: { 50 | response as FetchMessageResponse; 51 | localServiceRepository.storeMessages(response.messages); 52 | break; 53 | } 54 | default: { 55 | break; 56 | } 57 | } 58 | } 59 | 60 | @override 61 | Future close() { 62 | subscription.cancel(); 63 | return super.close(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /lib/home/cubit/home_state.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 14:02:24 4 | * @LastEditTime : 2022-10-13 16:55:05 5 | * @Description : 6 | */ 7 | 8 | import 'package:equatable/equatable.dart'; 9 | 10 | enum HomePagePosition { 11 | message(0), 12 | contact(1), 13 | profile(2); 14 | 15 | const HomePagePosition(int value): _value = value; 16 | final int _value; 17 | final List _literals = const ['Messages', 'Contacts', 'Me']; 18 | int get value => _value; 19 | String get literal => _literals[value]; 20 | 21 | //Construct the enum type by value 22 | factory HomePagePosition.fromValue(int value) { 23 | return HomePagePosition.values.firstWhere((element) => element._value == value, orElse: () => HomePagePosition.message); 24 | } 25 | } 26 | 27 | class HomeState extends Equatable { 28 | final HomePagePosition page; 29 | 30 | const HomeState({required this.page}); 31 | 32 | HomeState copyWith({HomePagePosition? page}) { 33 | return HomeState(page: page ?? this.page); 34 | } 35 | 36 | @override 37 | List get props => [page]; 38 | } 39 | -------------------------------------------------------------------------------- /lib/home/view/bottom_bar.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 16:37:30 4 | * @LastEditTime : 2022-10-13 16:37:30 5 | * @Description : 6 | */ 7 | -------------------------------------------------------------------------------- /lib/home/view/contact_page/contact_page.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-12 23:36:07 4 | * @LastEditTime : 2022-10-20 17:04:52 5 | * @Description : 6 | */ 7 | 8 | import 'package:azlistview/azlistview.dart'; 9 | import 'package:flutter/material.dart'; 10 | import 'package:flutter_bloc/flutter_bloc.dart'; 11 | import 'package:tcp_client/home/view/contact_page/cubit/contact_cubit.dart'; 12 | import 'package:tcp_client/home/view/contact_page/cubit/contact_state.dart'; 13 | import 'package:tcp_client/home/view/contact_page/models/contact_model.dart'; 14 | import 'package:tcp_client/home/view/contact_page/view/contact_tile.dart'; 15 | 16 | class ContactPage extends StatelessWidget { 17 | const ContactPage({super.key}); 18 | 19 | @override 20 | Widget build(BuildContext context) { 21 | return BlocBuilder( 22 | builder: (context, state) { 23 | var indexedData = state.indexedData; 24 | return AzListView( 25 | data: indexedData, 26 | itemCount: indexedData.length, 27 | itemBuilder: (context, index) { 28 | return ContactTile( 29 | contactInfo: (indexedData[index] as ContactModel), 30 | ); 31 | }, 32 | physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), 33 | susItemBuilder: (context, index) { 34 | return Container( 35 | height: 40, 36 | width: MediaQuery.of(context).size.width, 37 | padding: const EdgeInsets.only(left: 16.0), 38 | color: Colors.grey[200], 39 | alignment: Alignment.centerLeft, 40 | child: Text( 41 | indexedData[index].getSuspensionTag() == '⨂' ? 'Pending for reply' : indexedData[index].getSuspensionTag() == '⊙' ? 'Requesting' : indexedData[index].getSuspensionTag(), 42 | softWrap: false, 43 | style: TextStyle( 44 | fontSize: 14.0, 45 | color: Colors.grey[700], 46 | ), 47 | ), 48 | ); 49 | }, 50 | ); 51 | }, 52 | ); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /lib/home/view/contact_page/cubit/contact_cubit.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 14:01:45 4 | * @LastEditTime : 2022-10-20 16:36:05 5 | * @Description : 6 | */ 7 | 8 | import 'dart:async'; 9 | 10 | import 'package:bloc/bloc.dart'; 11 | import 'package:shared_preferences/shared_preferences.dart'; 12 | import 'package:tcp_client/home/view/contact_page/cubit/contact_state.dart'; 13 | import 'package:tcp_client/repositories/local_service_repository/local_service_repository.dart'; 14 | import 'package:tcp_client/repositories/tcp_repository/models/tcp_request.dart'; 15 | import 'package:tcp_client/repositories/tcp_repository/models/tcp_response.dart'; 16 | import 'package:tcp_client/repositories/tcp_repository/tcp_repository.dart'; 17 | 18 | class ContactCubit extends Cubit { 19 | ContactCubit({ 20 | required this.localServiceRepository, 21 | required this.tcpRepository 22 | }): super(ContactState.empty()) { 23 | subscription = tcpRepository.responseStreamBroadcast.listen(_onResponse); 24 | updateContacts(); 25 | timer = Timer.periodic(const Duration(seconds: 20), (timer) {updateContacts();}); 26 | } 27 | 28 | final LocalServiceRepository localServiceRepository; 29 | final TCPRepository tcpRepository; 30 | late final StreamSubscription subscription; 31 | late final Timer timer; 32 | 33 | void _onResponse(TCPResponse response) { 34 | switch(response.type) { 35 | case TCPResponseType.fetchContact: { 36 | response as FetchContactResponse; 37 | emit(ContactState( 38 | contacts: response.addedContacts, 39 | pending: response.pendingContacts, 40 | requesting: response.requestingContacts 41 | )); 42 | break; 43 | } 44 | default: break; 45 | } 46 | } 47 | 48 | Future updateContacts() async { 49 | tcpRepository.pushRequest(FetchContactRequest(token: (await SharedPreferences.getInstance()).getInt('token'))); 50 | } 51 | 52 | //Override dispose to cancel the subscription 53 | @override 54 | Future close() { 55 | subscription.cancel(); 56 | timer.cancel(); 57 | return super.close(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /lib/home/view/contact_page/cubit/contact_state.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 14:01:39 4 | * @LastEditTime : 2022-10-20 16:09:50 5 | * @Description : 6 | */ 7 | 8 | import 'package:azlistview/azlistview.dart'; 9 | import 'package:equatable/equatable.dart'; 10 | import 'package:tcp_client/home/view/contact_page/models/contact_model.dart'; 11 | import 'package:tcp_client/repositories/common_models/userinfo.dart'; 12 | 13 | class ContactState extends Equatable { 14 | final List contacts; 15 | final List pending; 16 | final List requesting; 17 | 18 | const ContactState({ 19 | required this.contacts, 20 | required this.pending, 21 | required this.requesting 22 | }); 23 | 24 | static ContactState empty() => const ContactState(contacts: [], pending: [], requesting: []); 25 | 26 | List get indexedData { 27 | var indexedList = contacts.map((e) => ContactModel(userInfo: e, status: ContactStatus.added)).toList(); 28 | indexedList.sort((a, b) => a.getSuspensionTag().compareTo(b.getSuspensionTag())); 29 | //Add requesting contacts 30 | indexedList.insertAll(0, requesting.map((e) => ContactModel(userInfo: e, status: ContactStatus.requesting)).toList()); 31 | //Add pending contacts 32 | indexedList.insertAll(0, pending.map((e) => ContactModel(userInfo: e, status: ContactStatus.pending)).toList()); 33 | // SuspensionUtil.sortListBySuspensionTag(indexedList); 34 | SuspensionUtil.setShowSuspensionStatus(indexedList); 35 | return indexedList; 36 | } 37 | 38 | @override 39 | List get props => [...contacts, ...pending, ...requesting]; 40 | } 41 | -------------------------------------------------------------------------------- /lib/home/view/contact_page/models/contact_model.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 15:34:08 4 | * @LastEditTime : 2022-10-20 16:00:22 5 | * @Description : 6 | */ 7 | 8 | import 'package:azlistview/azlistview.dart'; 9 | import 'package:lpinyin/lpinyin.dart'; 10 | import 'package:tcp_client/repositories/common_models/userinfo.dart'; 11 | 12 | enum ContactStatus { added, pending, requesting } 13 | 14 | class ContactModel extends ISuspensionBean { 15 | final UserInfo userInfo; 16 | final ContactStatus status; 17 | 18 | ContactModel({required this.userInfo, required this.status}); 19 | 20 | @override 21 | String getSuspensionTag() { 22 | if(status == ContactStatus.pending) { 23 | return '⨂'; 24 | } 25 | else if(status == ContactStatus.requesting) { 26 | return '⊙'; 27 | } 28 | var pinyin = PinyinHelper.getPinyinE(userInfo.userName); 29 | var tag = pinyin.substring(0, 1).toUpperCase(); 30 | if(!RegExp('[A-Z]').hasMatch(tag)) { 31 | tag = '#'; 32 | } 33 | return tag; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/home/view/contact_page/view/contact_tile.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 14:02:00 4 | * @LastEditTime : 2022-10-20 16:26:33 5 | * @Description : 6 | */ 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:flutter_bloc/flutter_bloc.dart'; 10 | import 'package:loading_indicator/loading_indicator.dart'; 11 | import 'package:shared_preferences/shared_preferences.dart'; 12 | import 'package:tcp_client/chat/chat_page.dart'; 13 | import 'package:tcp_client/common/avatar/avatar.dart'; 14 | import 'package:tcp_client/common/username/username.dart'; 15 | import 'package:tcp_client/home/cubit/home_cubit.dart'; 16 | import 'package:tcp_client/home/cubit/home_state.dart'; 17 | import 'package:tcp_client/home/view/contact_page/cubit/contact_cubit.dart'; 18 | import 'package:tcp_client/home/view/contact_page/models/contact_model.dart'; 19 | import 'package:tcp_client/home/view/message_page/cubit/msg_list_cubit.dart'; 20 | import 'package:tcp_client/repositories/local_service_repository/local_service_repository.dart'; 21 | import 'package:tcp_client/repositories/tcp_repository/models/tcp_request.dart'; 22 | import 'package:tcp_client/repositories/tcp_repository/tcp_repository.dart'; 23 | import 'package:tcp_client/repositories/user_repository/user_repository.dart'; 24 | 25 | class ContactTile extends StatelessWidget { 26 | const ContactTile({ 27 | required this.contactInfo, 28 | super.key 29 | }); 30 | 31 | final ContactModel contactInfo; 32 | 33 | @override 34 | Widget build(BuildContext context) { 35 | return IntrinsicHeight( 36 | child: Stack( 37 | fit: StackFit.expand, 38 | children: [ 39 | InkWell( 40 | onTap: contactInfo.status == ContactStatus.added ? () { 41 | Navigator.of(context).push(ChatPage.route( 42 | userRepository: context.read(), 43 | localServiceRepository: context.read(), 44 | tcpRepository: context.read(), 45 | userID: contactInfo.userInfo.userID 46 | )); 47 | context.read().addEmptyMessageOf(targetUser: contactInfo.userInfo.userID); 48 | context.read().switchPage(HomePagePosition.message); 49 | } : (){}, 50 | ), 51 | Padding( 52 | padding: const EdgeInsets.symmetric( 53 | horizontal: 24, 54 | vertical: 16, 55 | ), 56 | child: Row( 57 | children: [ 58 | IgnorePointer( 59 | child: UserAvatar(userid: contactInfo.userInfo.userID), 60 | ), 61 | const SizedBox(width: 12,), 62 | Expanded( 63 | child: Padding( 64 | padding: const EdgeInsets.symmetric( 65 | vertical: 12.0 66 | ), 67 | child: IgnorePointer( 68 | child: UserNameText(userid: contactInfo.userInfo.userID,) 69 | ), 70 | ) 71 | ), 72 | Padding( 73 | padding: const EdgeInsets.symmetric(horizontal: 12.0), 74 | child: contactInfo.status == ContactStatus.added ? null : 75 | contactInfo.status == ContactStatus.pending ? 76 | SizedBox( 77 | width: 24, 78 | height: 24, 79 | child: LoadingIndicator( 80 | indicatorType: Indicator.ballPulse, 81 | colors: [Colors.blue.withOpacity(0.5)], 82 | ), 83 | ) : 84 | TextButton( 85 | onPressed: () async { 86 | context.read().tcpRepository.pushRequest(AddContactRequest( 87 | userid: contactInfo.userInfo.userID, 88 | token: (await SharedPreferences.getInstance()).getInt('token') 89 | )); 90 | }, 91 | child: const Text('Confirm'), 92 | ), 93 | ) 94 | ], 95 | ), 96 | ), 97 | ], 98 | ), 99 | ); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /lib/home/view/message_page/cubit/msg_list_state.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-12 23:37:49 4 | * @LastEditTime : 2022-10-17 13:10:49 5 | * @Description : 6 | */ 7 | 8 | import 'package:equatable/equatable.dart'; 9 | import 'package:tcp_client/home/view/message_page/models/message_info.dart'; 10 | 11 | class MessageListState extends Equatable { 12 | final List messageList; 13 | 14 | const MessageListState({ 15 | required this.messageList 16 | }); 17 | 18 | static MessageListState empty() => const MessageListState(messageList: []); 19 | 20 | MessageListState updateWithSingle({ 21 | required MessageInfo messageInfo 22 | }) { 23 | var newList = [messageInfo]; 24 | for(var msgInfo in messageList) { 25 | if(msgInfo.targetUser == messageInfo.targetUser) { 26 | continue; 27 | } 28 | newList.add(msgInfo); 29 | } 30 | return MessageListState(messageList: newList); 31 | } 32 | 33 | MessageListState updateWithList({ 34 | required List orderedNewMessages 35 | }) { 36 | var newList = []; 37 | Set addedUsers = {}; 38 | var insertListIndex = 0; 39 | var origListIndex = 0; 40 | while( 41 | insertListIndex < orderedNewMessages.length && 42 | origListIndex < messageList.length 43 | ) { 44 | if(addedUsers.contains(orderedNewMessages[insertListIndex].targetUser)) { 45 | insertListIndex += 1; 46 | continue; 47 | } 48 | if(addedUsers.contains(messageList[origListIndex].targetUser)) { 49 | origListIndex += 1; 50 | continue; 51 | } 52 | if( 53 | (messageList[origListIndex].message?.timeStamp ?? 0) > 54 | (orderedNewMessages[insertListIndex].message?.timeStamp ?? 0) 55 | ) { 56 | newList.add(messageList[origListIndex]); 57 | addedUsers.add(messageList[origListIndex].targetUser); 58 | origListIndex += 1; 59 | continue; 60 | } 61 | else { 62 | newList.add(orderedNewMessages[insertListIndex]); 63 | addedUsers.add(orderedNewMessages[insertListIndex].targetUser); 64 | insertListIndex += 1; 65 | continue; 66 | } 67 | } 68 | //Add the messages left 69 | while(origListIndex < messageList.length) { 70 | if(addedUsers.contains(messageList[origListIndex].targetUser)) { 71 | origListIndex += 1; 72 | continue; 73 | } 74 | newList.add(messageList[origListIndex]); 75 | addedUsers.add(messageList[origListIndex].targetUser); 76 | origListIndex += 1; 77 | continue; 78 | } 79 | while(insertListIndex < orderedNewMessages.length) { 80 | if(addedUsers.contains(orderedNewMessages[insertListIndex].targetUser)) { 81 | insertListIndex += 1; 82 | continue; 83 | } 84 | newList.add(orderedNewMessages[insertListIndex]); 85 | addedUsers.add(orderedNewMessages[insertListIndex].targetUser); 86 | insertListIndex += 1; 87 | continue; 88 | } 89 | 90 | return MessageListState(messageList: newList); 91 | } 92 | 93 | MessageListState deleteOf({ 94 | required MessageInfo messageInfo 95 | }) { 96 | var newList = []; 97 | for(var msgInfo in messageList) { 98 | if(msgInfo == messageInfo) { 99 | continue; 100 | } 101 | newList.add(msgInfo); 102 | } 103 | return MessageListState(messageList: newList); 104 | } 105 | 106 | @override 107 | List get props => [...messageList]; 108 | } 109 | -------------------------------------------------------------------------------- /lib/home/view/message_page/mesage_page.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-11 11:05:18 4 | * @LastEditTime : 2022-10-17 13:35:35 5 | * @Description : 6 | */ 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:flutter_bloc/flutter_bloc.dart'; 10 | import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart'; 11 | import 'package:tcp_client/home/view/message_page/cubit/msg_list_cubit.dart'; 12 | import 'package:tcp_client/home/view/message_page/cubit/msg_list_state.dart'; 13 | import 'package:tcp_client/home/view/message_page/view/message_tile.dart'; 14 | 15 | class MessagePage extends StatelessWidget { 16 | MessagePage({super.key}); 17 | 18 | final RefreshController _refreshController = RefreshController(initialRefresh: false); 19 | 20 | @override 21 | Widget build(BuildContext context) { 22 | return BlocBuilder( 23 | builder: (context, state) { 24 | return SmartRefresher( 25 | controller: _refreshController, 26 | onRefresh: () async { 27 | await context.read().refresh(); 28 | _refreshController.refreshCompleted(); 29 | }, 30 | child: ListView.separated( 31 | physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), 32 | itemBuilder: (context, index) { 33 | return MessageTile( 34 | userID: state.messageList[index].targetUser, 35 | message: state.messageList[index].message, 36 | ); 37 | }, 38 | separatorBuilder: (context, index) { 39 | return const Divider( 40 | height: 0.5, 41 | ); 42 | }, 43 | itemCount: state.messageList.length 44 | ), 45 | ); 46 | } 47 | ); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lib/home/view/message_page/models/message_info.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-12 23:48:54 4 | * @LastEditTime : 2022-10-18 11:25:36 5 | * @Description : 6 | */ 7 | 8 | import 'package:equatable/equatable.dart'; 9 | import 'package:tcp_client/repositories/common_models/message.dart'; 10 | 11 | class MessageInfo extends Equatable { 12 | final Message? message; 13 | final int targetUser; 14 | 15 | const MessageInfo({ 16 | this.message, 17 | required this.targetUser 18 | }); 19 | 20 | @override 21 | List get props => [message?.contentmd5 ?? '', targetUser]; 22 | } 23 | -------------------------------------------------------------------------------- /lib/home/view/profile_page/cubit/log_out_cubit.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-14 10:54:57 4 | * @LastEditTime : 2022-10-17 20:51:45 5 | * @Description : 6 | */ 7 | 8 | import 'dart:async'; 9 | 10 | import 'package:bloc/bloc.dart'; 11 | import 'package:shared_preferences/shared_preferences.dart'; 12 | import 'package:tcp_client/home/view/profile_page/cubit/log_out_state.dart'; 13 | import 'package:tcp_client/repositories/tcp_repository/models/tcp_request.dart'; 14 | import 'package:tcp_client/repositories/tcp_repository/models/tcp_response.dart'; 15 | import 'package:tcp_client/repositories/tcp_repository/tcp_repository.dart'; 16 | 17 | class LogOutCubit extends Cubit { 18 | LogOutCubit({ 19 | required this.tcpRepository 20 | }): super(LogOutStatus.none) { 21 | subscription = tcpRepository.responseStreamBroadcast.listen(_onResponse); 22 | } 23 | 24 | final TCPRepository tcpRepository; 25 | late final StreamSubscription subscription; 26 | 27 | void _onResponse(TCPResponse response) { 28 | if(response.type == TCPResponseType.logout) { 29 | if(response.status == TCPResponseStatus.ok) { 30 | emit(LogOutStatus.done); 31 | } 32 | else { 33 | emit(LogOutStatus.none); 34 | } 35 | } 36 | } 37 | 38 | void onLogout() async { 39 | emit(LogOutStatus.processing); 40 | tcpRepository.pushRequest(LogoutRequest(token: (await SharedPreferences.getInstance()).getInt('token'))); 41 | } 42 | 43 | //Override dispose to cancel the subscription 44 | @override 45 | Future close() { 46 | subscription.cancel(); 47 | return super.close(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lib/home/view/profile_page/cubit/log_out_state.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-14 10:54:38 4 | * @LastEditTime : 2022-10-14 10:56:04 5 | * @Description : 6 | */ 7 | 8 | enum LogOutStatus { none, processing, done } -------------------------------------------------------------------------------- /lib/home/view/profile_page/view/log_out_button.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-14 10:53:24 4 | * @LastEditTime : 2022-10-14 11:12:22 5 | * @Description : 6 | */ 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:flutter_bloc/flutter_bloc.dart'; 10 | import 'package:tcp_client/home/view/profile_page/cubit/log_out_cubit.dart'; 11 | 12 | class LogoutButton extends StatelessWidget { 13 | const LogoutButton({super.key}); 14 | 15 | @override 16 | Widget build(BuildContext context) { 17 | return TextButton( 18 | onPressed: () { 19 | context.read().onLogout(); 20 | }, 21 | style: ButtonStyle( 22 | elevation: MaterialStateProperty.all(0), 23 | shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))), 24 | minimumSize: MaterialStateProperty.all(const Size(300, 0)), 25 | backgroundColor: MaterialStateProperty.all(Colors.red[700]), 26 | overlayColor: MaterialStateProperty.all(Colors.red[900]!.withOpacity(0.2)), 27 | foregroundColor: MaterialStateProperty.all(Colors.white), 28 | ), 29 | child: const Padding( 30 | padding: EdgeInsets.symmetric( 31 | horizontal: 16, 32 | vertical: 12 33 | ), 34 | child: Text( 35 | 'Log Out', 36 | style: TextStyle( 37 | fontSize: 20 38 | ), 39 | ), 40 | ), 41 | ); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /lib/initialization/cubit/initialization_cubit.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-12 09:56:04 4 | * @LastEditTime : 2022-10-17 21:11:30 5 | * @Description : 6 | */ 7 | 8 | import 'package:bloc/bloc.dart'; 9 | import 'package:path_provider/path_provider.dart'; 10 | import 'package:shared_preferences/shared_preferences.dart'; 11 | import 'package:tcp_client/initialization/cubit/initialization_state.dart'; 12 | import 'package:tcp_client/repositories/local_service_repository/local_service_repository.dart'; 13 | import 'package:tcp_client/repositories/tcp_repository/models/tcp_request.dart'; 14 | import 'package:tcp_client/repositories/tcp_repository/models/tcp_response.dart'; 15 | import 'package:tcp_client/repositories/tcp_repository/tcp_repository.dart'; 16 | 17 | class InitializationCubit extends Cubit { 18 | InitializationCubit({ 19 | required String serverAddress, 20 | required int serverPort 21 | }): super(const InitializationState.init()) { 22 | TCPRepository? tcpRepository; 23 | LocalServiceRepository? localServiceRepository; 24 | Future(() async { 25 | localServiceRepository = await LocalServiceRepository.create( 26 | databaseFilePath: '${ 27 | (await getApplicationDocumentsDirectory()).path 28 | }/LChatClient/.data/database.db' 29 | ); 30 | }).then((_) { 31 | emit(state.copyWith( 32 | databaseStatus: InitializationStatus.done, 33 | localServiceRepository: localServiceRepository 34 | )); 35 | }); 36 | Future(() async { 37 | tcpRepository = await TCPRepository.create(serverAddress: serverAddress, serverPort: serverPort); 38 | }).then((_) { 39 | emit(state.copyWith( 40 | mainSocketStatus: InitializationStatus.done, 41 | tcpRepository: tcpRepository 42 | )); 43 | }); 44 | Future(() async { 45 | var tempConnection = await TCPRepository.create(serverAddress: serverAddress, serverPort: serverPort); 46 | var pref = await SharedPreferences.getInstance(); 47 | var tokenid = pref.getInt('token'); 48 | tempConnection.pushRequest(CheckStateRequest(token: tokenid)); 49 | await for(var response in tempConnection.responseStreamBroadcast) { 50 | if(response.type == TCPResponseType.token) { 51 | pref.setInt('token', (response as SetTokenReponse).token); 52 | } 53 | else if(response.type == TCPResponseType.checkState) { 54 | if(response.status == TCPResponseStatus.ok) { 55 | pref.setInt('userid', (response as CheckStateResponse).userInfo!.userID); 56 | } 57 | else { 58 | pref.remove('userid'); 59 | } 60 | break; 61 | } 62 | } 63 | tempConnection.dispose(); 64 | }).then((_) { 65 | emit(state.copyWith( 66 | tokenStatus: InitializationStatus.done 67 | )); 68 | }); 69 | } 70 | 71 | InitializationCubit.failed(): super(const InitializationState.init()); 72 | } -------------------------------------------------------------------------------- /lib/initialization/cubit/initialization_state.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-12 09:57:48 4 | * @LastEditTime : 2022-10-12 13:59:14 5 | * @Description : 6 | */ 7 | 8 | import 'package:equatable/equatable.dart'; 9 | import 'package:tcp_client/repositories/local_service_repository/local_service_repository.dart'; 10 | import 'package:tcp_client/repositories/tcp_repository/tcp_repository.dart'; 11 | 12 | enum InitializationStatus { pending, done } 13 | 14 | class InitializationState extends Equatable { 15 | const InitializationState({ 16 | required this.databaseStatus, 17 | required this.mainSocketStatus, 18 | required this.tokenStatus, 19 | this.localServiceRepository, 20 | this.tcpRepository 21 | }); 22 | 23 | const InitializationState.init(): this( 24 | databaseStatus: InitializationStatus.pending, 25 | mainSocketStatus: InitializationStatus.pending, 26 | tokenStatus: InitializationStatus.pending 27 | ); 28 | 29 | final InitializationStatus databaseStatus; 30 | final InitializationStatus mainSocketStatus; 31 | final InitializationStatus tokenStatus; 32 | final LocalServiceRepository? localServiceRepository; 33 | final TCPRepository? tcpRepository; 34 | 35 | InitializationState copyWith({ 36 | InitializationStatus? databaseStatus, 37 | InitializationStatus? mainSocketStatus, 38 | InitializationStatus? tokenStatus, 39 | LocalServiceRepository? localServiceRepository, 40 | TCPRepository? tcpRepository 41 | }) { 42 | return InitializationState( 43 | databaseStatus: databaseStatus ?? this.databaseStatus, 44 | mainSocketStatus: mainSocketStatus ?? this.mainSocketStatus, 45 | tokenStatus: tokenStatus ?? this.tokenStatus, 46 | localServiceRepository: localServiceRepository ?? this.localServiceRepository, 47 | tcpRepository: tcpRepository ?? this.tcpRepository 48 | ); 49 | } 50 | 51 | bool get isDone => databaseStatus == InitializationStatus.done && 52 | mainSocketStatus == InitializationStatus.done && 53 | tokenStatus == InitializationStatus.done; 54 | 55 | @override 56 | List get props => [databaseStatus, mainSocketStatus, tokenStatus]; 57 | } 58 | -------------------------------------------------------------------------------- /lib/login/cubit/login_cubit.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-12 15:38:07 4 | * @LastEditTime : 2022-10-20 20:51:09 5 | * @Description : 6 | */ 7 | 8 | import 'package:bloc/bloc.dart'; 9 | import 'package:formz/formz.dart'; 10 | import 'package:shared_preferences/shared_preferences.dart'; 11 | import 'package:tcp_client/login/cubit/login_state.dart'; 12 | import 'package:tcp_client/login/models/password.dart'; 13 | import 'package:tcp_client/login/models/username.dart'; 14 | import 'package:tcp_client/repositories/common_models/useridentity.dart'; 15 | import 'package:tcp_client/repositories/local_service_repository/local_service_repository.dart'; 16 | import 'package:tcp_client/repositories/tcp_repository/models/tcp_request.dart'; 17 | import 'package:tcp_client/repositories/tcp_repository/models/tcp_response.dart'; 18 | import 'package:tcp_client/repositories/tcp_repository/tcp_repository.dart'; 19 | 20 | class LoginCubit extends Cubit { 21 | LoginCubit({ 22 | required this.localServiceRepository, 23 | required this.tcpRepository 24 | }): super(const LoginState()); 25 | 26 | final LocalServiceRepository localServiceRepository; 27 | final TCPRepository tcpRepository; 28 | 29 | void onPasswordChange(Password password) { 30 | emit(state.copyWith( 31 | status: Formz.validate([state.username, password]), 32 | password: password 33 | )); 34 | } 35 | 36 | Future onUsernameChange(Username username) async { 37 | emit(state.copyWith( 38 | status: Formz.validate([username, state.password]), 39 | username: username, 40 | )); 41 | var userinfo = await localServiceRepository.fetchUserInfoViaUsername(username: username.value); 42 | emit(state.copyWith( 43 | avatar: userinfo?.avatarEncoded 44 | )); 45 | } 46 | 47 | Future onSubmission() async { 48 | if(state.status.isValidated) { 49 | emit(state.copyWith( 50 | status: FormzStatus.submissionInProgress, 51 | info: "" 52 | )); 53 | tcpRepository.pushRequest(LoginRequest( 54 | identity: UserIdentity( 55 | username: state.username.value, 56 | password: state.password.value 57 | ), 58 | token: (await SharedPreferences.getInstance()).getInt('token') 59 | )); 60 | await for(var response in tcpRepository.responseStreamBroadcast) { 61 | if(response.type == TCPResponseType.login) { 62 | if(response.status == TCPResponseStatus.ok) { 63 | var pref = await SharedPreferences.getInstance(); 64 | pref.setInt('userid', (response as LoginResponse).userInfo!.userID); 65 | emit(state.copyWith( 66 | status: FormzStatus.submissionSuccess 67 | )); 68 | } 69 | else { 70 | emit(state.copyWith( 71 | status: FormzStatus.submissionFailure, 72 | info: response.info?.replaceAll('Exception: ', ''), 73 | )); 74 | } 75 | break; 76 | } 77 | } 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /lib/login/cubit/login_state.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-12 15:38:13 4 | * @LastEditTime : 2022-10-20 20:49:43 5 | * @Description : 6 | */ 7 | 8 | import 'package:equatable/equatable.dart'; 9 | import 'package:formz/formz.dart'; 10 | import 'package:tcp_client/login/models/password.dart'; 11 | import 'package:tcp_client/login/models/username.dart'; 12 | 13 | class LoginState extends Equatable { 14 | final Username username; 15 | final Password password; 16 | final String avatar; 17 | 18 | final FormzStatus status; 19 | final String info; 20 | 21 | const LoginState({ 22 | this.status = FormzStatus.pure, 23 | this.username = const Username.pure(), 24 | this.password = const Password.pure(), 25 | this.avatar = "", 26 | this.info = "" 27 | }); 28 | 29 | LoginState copyWith({ 30 | FormzStatus? status, 31 | Username? username, 32 | Password? password, 33 | String? avatar, 34 | String? info, 35 | }) { 36 | return LoginState( 37 | status: status ?? this.status, 38 | username: username ?? this.username, 39 | password: password ?? this.password, 40 | avatar: avatar ?? this.avatar, 41 | info: info ?? this.info 42 | ); 43 | } 44 | 45 | @override 46 | List get props => [status, username, password, avatar, info]; 47 | } 48 | -------------------------------------------------------------------------------- /lib/login/models/password.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-12 15:37:29 4 | * @LastEditTime : 2022-10-12 15:46:38 5 | * @Description : 6 | */ 7 | 8 | import 'package:formz/formz.dart'; 9 | 10 | enum PasswordValidationError { empty } 11 | 12 | class Password extends FormzInput { 13 | const Password.pure() : super.pure(''); 14 | const Password.dirty([super.value = '']) : super.dirty(); 15 | 16 | @override 17 | PasswordValidationError? validator(String? value) { 18 | return value?.isNotEmpty == true ? null : PasswordValidationError.empty; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/login/models/username.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-12 15:37:34 4 | * @LastEditTime : 2022-10-12 15:45:11 5 | * @Description : 6 | */ 7 | 8 | import 'package:formz/formz.dart'; 9 | 10 | enum UsernameValidationError { empty } 11 | 12 | class Username extends FormzInput { 13 | const Username.pure(): super.pure(''); 14 | const Username.dirty([super.value = '']): super.dirty(); 15 | 16 | @override 17 | UsernameValidationError? validator(String? value) { 18 | return value?.isNotEmpty == true ? null : UsernameValidationError.empty; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/login/view/avatar_widget.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-12 15:37:19 4 | * @LastEditTime : 2022-10-12 17:10:58 5 | * @Description : 6 | */ 7 | -------------------------------------------------------------------------------- /lib/login/view/login_form.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-12 16:29:25 4 | * @LastEditTime : 2022-10-20 20:43:51 5 | * @Description : 6 | */ 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:flutter_bloc/flutter_bloc.dart'; 10 | import 'package:formz/formz.dart'; 11 | import 'package:tcp_client/login/cubit/login_cubit.dart'; 12 | import 'package:tcp_client/login/cubit/login_state.dart'; 13 | import 'package:tcp_client/login/models/password.dart'; 14 | import 'package:tcp_client/login/models/username.dart'; 15 | 16 | class LoginForm extends StatelessWidget { 17 | const LoginForm({super.key}); 18 | 19 | @override 20 | Widget build(BuildContext context) { 21 | return Column( 22 | mainAxisSize: MainAxisSize.min, 23 | mainAxisAlignment: MainAxisAlignment.center, 24 | children: const [ 25 | UsernameInput(), 26 | SizedBox(height: 8,), 27 | PasswordInput(), 28 | SizedBox(height: 28,), 29 | SubmitButton() 30 | ], 31 | ); 32 | } 33 | } 34 | 35 | class UsernameInput extends StatelessWidget { 36 | const UsernameInput({super.key}); 37 | 38 | @override 39 | Widget build(BuildContext context) { 40 | return BlocBuilder( 41 | buildWhen: (previous, current) => previous.username != current.username, 42 | builder: (context, state) { 43 | return TextField( 44 | onChanged: (username) { 45 | context.read().onUsernameChange(Username.dirty(username)); 46 | }, 47 | decoration: InputDecoration( 48 | labelText: 'Username', 49 | errorText: state.username.invalid ? 'Invalid username' : null 50 | ), 51 | ); 52 | }, 53 | ); 54 | } 55 | } 56 | 57 | class PasswordInput extends StatelessWidget { 58 | const PasswordInput({super.key}); 59 | 60 | @override 61 | Widget build(BuildContext context) { 62 | return BlocBuilder( 63 | buildWhen: (previous, current) => previous.password != current.password, 64 | builder: (context, state) { 65 | return TextField( 66 | onChanged: (password) { 67 | context.read().onPasswordChange(Password.dirty(password)); 68 | }, 69 | obscureText: true, 70 | decoration: InputDecoration( 71 | labelText: 'Password', 72 | errorText: state.password.invalid ? 'Invalid password' : null 73 | ), 74 | ); 75 | }, 76 | ); 77 | } 78 | } 79 | 80 | class SubmitButton extends StatelessWidget { 81 | const SubmitButton({super.key}); 82 | 83 | @override 84 | Widget build(BuildContext context) { 85 | return BlocBuilder( 86 | buildWhen: (previous, current) => previous.status != current.status, 87 | builder: (context, state) { 88 | return SizedBox( 89 | height: 40.0, 90 | width: 90.0, 91 | child: TextButton( 92 | style: ButtonStyle( 93 | shape: MaterialStateProperty.all(const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(5.0)))), 94 | backgroundColor: MaterialStateProperty.resolveWith((states) { 95 | switch(states) { 96 | case {MaterialState.disabled}: 97 | return Colors.grey; 98 | case {MaterialState.pressed}: 99 | return Colors.blue[800]; 100 | default: 101 | return Colors.blue[700]; 102 | } 103 | }), 104 | overlayColor: MaterialStateProperty.all(Colors.blue[900]!.withOpacity(0.2)) 105 | ), 106 | onPressed: () { 107 | if( 108 | state.status == FormzStatus.valid || 109 | state.status == FormzStatus.submissionFailure 110 | ) { 111 | context.read().onSubmission(); 112 | } 113 | }, 114 | child: state.status == FormzStatus.submissionInProgress ? 115 | const SizedBox( 116 | height: 14.0, 117 | width: 14.0, 118 | child: CircularProgressIndicator( 119 | color: Colors.white, 120 | strokeWidth: 3, 121 | ), 122 | ) : 123 | const Text( 124 | 'LOGIN', 125 | style: TextStyle( 126 | color: Colors.white 127 | ), 128 | ) 129 | ) 130 | ); 131 | }, 132 | ); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /lib/profile/cubit/user_profile_cubit.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-14 08:54:32 4 | * @LastEditTime : 2022-10-20 16:45:19 5 | * @Description : 6 | */ 7 | 8 | import 'package:bloc/bloc.dart'; 9 | import 'package:shared_preferences/shared_preferences.dart'; 10 | import 'package:tcp_client/profile/cubit/user_profile_state.dart'; 11 | import 'package:tcp_client/repositories/tcp_repository/models/tcp_request.dart'; 12 | import 'package:tcp_client/repositories/tcp_repository/models/tcp_response.dart'; 13 | import 'package:tcp_client/repositories/tcp_repository/tcp_repository.dart'; 14 | 15 | class UserProfileCubit extends Cubit { 16 | UserProfileCubit({ 17 | required this.userID, 18 | required this.tcpRepository 19 | }): super(const UserProfileState(status: ContactStatus.none)) { 20 | updateContactStatus(); 21 | } 22 | 23 | final int userID; 24 | final TCPRepository tcpRepository; 25 | 26 | Future updateContactStatus() async { 27 | if(userID == (await SharedPreferences.getInstance()).getInt('userid')) { 28 | emit(const UserProfileState(status: ContactStatus.none)); 29 | return; 30 | } 31 | tcpRepository.pushRequest(FetchContactRequest(token: (await SharedPreferences.getInstance()).getInt('token'))); 32 | await for(var response in tcpRepository.responseStreamBroadcast) { 33 | if(response.type == TCPResponseType.fetchContact) { 34 | response as FetchContactResponse; 35 | if(response.addedContacts.any((element) => element.userID == userID)) { 36 | emit(const UserProfileState(status: ContactStatus.isContact)); 37 | } 38 | else if(response.pendingContacts.any((element) => element.userID == userID)) { 39 | emit(const UserProfileState(status: ContactStatus.pendingReply)); 40 | } 41 | else { 42 | emit(const UserProfileState(status: ContactStatus.notContact)); 43 | } 44 | break; 45 | } 46 | } 47 | } 48 | 49 | Future addContact() async { 50 | emit(const UserProfileState(status: ContactStatus.consulting)); 51 | var clonedTCPRepository = await tcpRepository.clone(); 52 | clonedTCPRepository.pushRequest(AddContactRequest( 53 | userid: userID, 54 | token: (await SharedPreferences.getInstance()).getInt('token') 55 | )); 56 | await for(var response in clonedTCPRepository.responseStreamBroadcast) { 57 | if(response.type == TCPResponseType.addContact) { 58 | break; 59 | } 60 | } 61 | clonedTCPRepository.dispose(); 62 | updateContactStatus(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /lib/profile/cubit/user_profile_state.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-14 08:54:25 4 | * @LastEditTime : 2022-10-14 09:11:04 5 | * @Description : 6 | */ 7 | 8 | import 'package:equatable/equatable.dart'; 9 | 10 | enum ContactStatus { isContact, pendingReply, notContact, consulting, none } 11 | 12 | class UserProfileState extends Equatable { 13 | final ContactStatus status; 14 | 15 | const UserProfileState({required this.status}); 16 | 17 | @override 18 | List get props => [status]; 19 | } 20 | -------------------------------------------------------------------------------- /lib/profile/user_profile_page.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 17:04:44 4 | * @LastEditTime : 2022-10-14 12:11:26 5 | * @Description : 6 | */ 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:flutter_bloc/flutter_bloc.dart'; 10 | import 'package:tcp_client/common/avatar/avatar.dart'; 11 | import 'package:tcp_client/common/username/username.dart'; 12 | import 'package:tcp_client/profile/cubit/user_profile_cubit.dart'; 13 | import 'package:tcp_client/profile/view/add_contact_button.dart'; 14 | import 'package:tcp_client/repositories/local_service_repository/local_service_repository.dart'; 15 | import 'package:tcp_client/repositories/tcp_repository/tcp_repository.dart'; 16 | import 'package:tcp_client/repositories/user_repository/user_repository.dart'; 17 | 18 | class ProfilePage extends StatelessWidget { 19 | const ProfilePage({ 20 | required this.userID, 21 | required this.localServiceRepository, 22 | required this.tcpRepository, 23 | required this.userRepository, 24 | super.key 25 | }); 26 | 27 | static Route route({ 28 | required int userID, 29 | required LocalServiceRepository localServiceRepository, 30 | required TCPRepository tcpRepository, 31 | required UserRepository userRepository 32 | }) => MaterialPageRoute(builder: (context) => ProfilePage( 33 | userID: userID, 34 | localServiceRepository: localServiceRepository, 35 | tcpRepository: tcpRepository, 36 | userRepository: userRepository, 37 | )); 38 | 39 | final int userID; 40 | final LocalServiceRepository localServiceRepository; 41 | final TCPRepository tcpRepository; 42 | final UserRepository userRepository; 43 | 44 | @override 45 | Widget build(BuildContext context) { 46 | return MultiRepositoryProvider( 47 | providers: [ 48 | RepositoryProvider.value( 49 | value: userRepository, 50 | ), 51 | RepositoryProvider.value( 52 | value: localServiceRepository, 53 | ), 54 | RepositoryProvider.value( 55 | value: tcpRepository, 56 | ) 57 | ], 58 | child: BlocProvider( 59 | create: (context) => UserProfileCubit( 60 | userID: userID, 61 | tcpRepository: tcpRepository, 62 | ), 63 | child: Scaffold( 64 | appBar: AppBar(), 65 | body: Container( 66 | alignment: Alignment.center, 67 | padding: const EdgeInsets.all(60), 68 | child: Column( 69 | mainAxisAlignment: MainAxisAlignment.center, 70 | crossAxisAlignment: CrossAxisAlignment.center, 71 | children: [ 72 | UserAvatar(userid: userID, size: 96,), 73 | const SizedBox(height: 48,), 74 | UserNameText( 75 | userid: userID, 76 | fontWeight: FontWeight.bold, 77 | fontSize: 22, 78 | alignment: Alignment.center, 79 | ), 80 | const SizedBox(height: 48,), 81 | AddContactButton(userID: userID) 82 | ], 83 | ), 84 | ), 85 | ), 86 | ), 87 | ); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /lib/register/cubit/register_cubit.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-12 15:38:07 4 | * @LastEditTime : 2022-10-20 20:53:03 5 | * @Description : 6 | */ 7 | 8 | import 'package:bloc/bloc.dart'; 9 | import 'package:formz/formz.dart'; 10 | import 'package:shared_preferences/shared_preferences.dart'; 11 | import 'package:tcp_client/register/cubit/register_state.dart'; 12 | import 'package:tcp_client/register/models/password.dart'; 13 | import 'package:tcp_client/register/models/username.dart'; 14 | import 'package:tcp_client/repositories/common_models/useridentity.dart'; 15 | import 'package:tcp_client/repositories/local_service_repository/local_service_repository.dart'; 16 | import 'package:tcp_client/repositories/tcp_repository/models/tcp_request.dart'; 17 | import 'package:tcp_client/repositories/tcp_repository/models/tcp_response.dart'; 18 | import 'package:tcp_client/repositories/tcp_repository/tcp_repository.dart'; 19 | 20 | class RegisterCubit extends Cubit { 21 | RegisterCubit({ 22 | required this.localServiceRepository, 23 | required this.tcpRepository 24 | }): super(const RegisterState()); 25 | 26 | final LocalServiceRepository localServiceRepository; 27 | final TCPRepository tcpRepository; 28 | 29 | void onPasswordChange(Password password) { 30 | emit(state.copyWith( 31 | status: Formz.validate([state.username, password]), 32 | password: password 33 | )); 34 | } 35 | 36 | Future onUsernameChange(Username username) async { 37 | emit(state.copyWith( 38 | status: Formz.validate([username, state.password]), 39 | username: username, 40 | )); 41 | var userinfo = await localServiceRepository.fetchUserInfoViaUsername(username: username.value); 42 | emit(state.copyWith( 43 | avatar: userinfo?.avatarEncoded 44 | )); 45 | } 46 | 47 | Future onSubmission() async { 48 | if(state.status.isValidated) { 49 | emit(state.copyWith( 50 | status: FormzStatus.submissionInProgress, 51 | info: "" 52 | )); 53 | tcpRepository.pushRequest(RegisterRequest( 54 | identity: UserIdentity( 55 | username: state.username.value, 56 | password: state.password.value 57 | ), 58 | token: (await SharedPreferences.getInstance()).getInt('token') 59 | )); 60 | await for(var response in tcpRepository.responseStreamBroadcast) { 61 | if(response.type == TCPResponseType.register) { 62 | if(response.status == TCPResponseStatus.ok) { 63 | var pref = await SharedPreferences.getInstance(); 64 | pref.setInt('userid', (response as RegisterResponse).userInfo!.userID); 65 | emit(state.copyWith( 66 | status: FormzStatus.submissionSuccess 67 | )); 68 | } 69 | else { 70 | emit(state.copyWith( 71 | status: FormzStatus.submissionFailure, 72 | info: response.info?.replaceAll('Exception: ', ''), 73 | )); 74 | } 75 | break; 76 | } 77 | } 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /lib/register/cubit/register_state.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-12 15:38:13 4 | * @LastEditTime : 2022-10-20 20:52:19 5 | * @Description : 6 | */ 7 | 8 | import 'package:equatable/equatable.dart'; 9 | import 'package:formz/formz.dart'; 10 | import 'package:tcp_client/register/models/password.dart'; 11 | import 'package:tcp_client/register/models/username.dart'; 12 | 13 | class RegisterState extends Equatable { 14 | final Username username; 15 | final Password password; 16 | final String avatar; 17 | 18 | final FormzStatus status; 19 | final String info; 20 | 21 | const RegisterState({ 22 | this.status = FormzStatus.pure, 23 | this.username = const Username.pure(), 24 | this.password = const Password.pure(), 25 | this.avatar = "", 26 | this.info = "" 27 | }); 28 | 29 | RegisterState copyWith({ 30 | FormzStatus? status, 31 | Username? username, 32 | Password? password, 33 | String? avatar, 34 | String? info, 35 | }) { 36 | return RegisterState( 37 | status: status ?? this.status, 38 | username: username ?? this.username, 39 | password: password ?? this.password, 40 | avatar: avatar ?? this.avatar, 41 | info: info ?? this.info 42 | ); 43 | } 44 | 45 | @override 46 | List get props => [status, username, password, avatar, info]; 47 | } 48 | -------------------------------------------------------------------------------- /lib/register/models/password.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-12 15:37:29 4 | * @LastEditTime : 2022-10-12 15:46:38 5 | * @Description : 6 | */ 7 | 8 | import 'package:formz/formz.dart'; 9 | 10 | enum PasswordValidationError { empty } 11 | 12 | class Password extends FormzInput { 13 | const Password.pure() : super.pure(''); 14 | const Password.dirty([super.value = '']) : super.dirty(); 15 | 16 | @override 17 | PasswordValidationError? validator(String? value) { 18 | return value?.isNotEmpty == true ? null : PasswordValidationError.empty; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/register/models/username.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-12 15:37:34 4 | * @LastEditTime : 2022-10-12 15:45:11 5 | * @Description : 6 | */ 7 | 8 | import 'package:formz/formz.dart'; 9 | 10 | enum UsernameValidationError { empty } 11 | 12 | class Username extends FormzInput { 13 | const Username.pure(): super.pure(''); 14 | const Username.dirty([super.value = '']): super.dirty(); 15 | 16 | @override 17 | UsernameValidationError? validator(String? value) { 18 | return value?.isNotEmpty == true ? null : UsernameValidationError.empty; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/repositories/common_models/json_encodable.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-11 15:18:49 4 | * @LastEditTime : 2022-10-11 15:22:13 5 | * @Description : 6 | */ 7 | 8 | abstract class JSONEncodable { 9 | const JSONEncodable(); 10 | 11 | Map get jsonObject; 12 | } -------------------------------------------------------------------------------- /lib/repositories/common_models/useridentity.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-11 15:06:42 4 | * @LastEditTime : 2022-10-11 15:39:38 5 | * @Description : 6 | */ 7 | import 'dart:convert'; 8 | 9 | import 'package:crypto/crypto.dart'; 10 | import 'package:tcp_client/repositories/common_models/json_encodable.dart'; 11 | 12 | class UserIdentity extends JSONEncodable { 13 | final String _username; 14 | final String _oldPasswd; 15 | final String? _newPasswd; 16 | 17 | UserIdentity({ 18 | required String username, 19 | required String password, 20 | String? newPassword 21 | }): 22 | _username = base64.encode(utf8.encode(username)), 23 | _oldPasswd = md5.convert(password.codeUnits).toString(), 24 | _newPasswd = newPassword != null ? 25 | md5.convert(newPassword.codeUnits).toString() : null; 26 | 27 | UserIdentity.fromJSONObject({ 28 | required Map jsonObject 29 | }): 30 | _username = jsonObject['username'] as String, 31 | _oldPasswd = jsonObject['passwd'] as String, 32 | _newPasswd = jsonObject['newPasswd'] as String?; 33 | 34 | String get userName => utf8.decode(base64.decode(_username)); 35 | String get password => _oldPasswd; 36 | String? get newPassword => _newPasswd; 37 | 38 | @override 39 | Map get jsonObject => { 40 | 'username': _username, 41 | 'passwd': _oldPasswd, 42 | 'newPasswd': _newPasswd 43 | }; 44 | } -------------------------------------------------------------------------------- /lib/repositories/common_models/userinfo.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-11 14:30:10 4 | * @LastEditTime : 2022-10-13 15:38:18 5 | * @Description : 6 | */ 7 | 8 | import 'dart:convert'; 9 | 10 | import 'package:tcp_client/repositories/common_models/json_encodable.dart'; 11 | 12 | class UserInfo extends JSONEncodable { 13 | final int _userid; 14 | final String _username; 15 | final String? _avatar; 16 | 17 | const UserInfo({ 18 | required int userid, 19 | required String username, 20 | String? avatar 21 | }): 22 | _userid = userid, 23 | _username = username, 24 | _avatar = avatar; 25 | 26 | UserInfo.fromJSONObject({ 27 | required Map jsonObject 28 | }): 29 | _userid = jsonObject['userid'] as int, 30 | _username = utf8.decode(base64.decode(jsonObject['username'] as String)), 31 | _avatar = jsonObject['avatar'] as String?; 32 | 33 | int get userID => _userid; 34 | String get userName => _username; 35 | String? get avatarEncoded => _avatar; 36 | 37 | @override 38 | Map get jsonObject => { 39 | 'userid': _userid, 40 | 'username': base64.encode(utf8.encode(_username)), 41 | 'avatar': _avatar 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /lib/repositories/local_service_repository/models/local_file.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-11 10:55:36 4 | * @LastEditTime : 2022-10-12 09:19:50 5 | * @Description : Local File Model 6 | */ 7 | 8 | import 'dart:io'; 9 | 10 | import 'package:equatable/equatable.dart'; 11 | 12 | class LocalFile extends Equatable { 13 | final File file; 14 | final String filemd5; 15 | 16 | const LocalFile({required this.file, required this.filemd5}); 17 | 18 | @override 19 | List get props => [filemd5]; 20 | } 21 | -------------------------------------------------------------------------------- /lib/repositories/user_repository/user_repository.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 20:18:14 4 | * @LastEditTime : 2022-10-20 11:50:26 5 | * @Description : Repository to cache user info 6 | */ 7 | 8 | import 'dart:async'; 9 | 10 | import 'package:shared_preferences/shared_preferences.dart'; 11 | import 'package:tcp_client/repositories/common_models/userinfo.dart'; 12 | import 'package:tcp_client/repositories/local_service_repository/local_service_repository.dart'; 13 | import 'package:tcp_client/repositories/tcp_repository/models/tcp_request.dart'; 14 | import 'package:tcp_client/repositories/tcp_repository/models/tcp_response.dart'; 15 | import 'package:tcp_client/repositories/tcp_repository/tcp_repository.dart'; 16 | 17 | class UserRepository { 18 | final Map users = {}; 19 | final LocalServiceRepository localServiceRepository; 20 | final TCPRepository tcpRepository; 21 | 22 | final StreamController _userInfoStreamController = StreamController(); 23 | Stream? _userInfoStreamBroadcast; 24 | Stream get userInfoStreamBroadcast { 25 | _userInfoStreamBroadcast ??= _userInfoStreamController.stream.asBroadcastStream(); 26 | return _userInfoStreamBroadcast!; 27 | } 28 | 29 | UserRepository({ 30 | required this.localServiceRepository, 31 | required this.tcpRepository 32 | }) { 33 | tcpRepository.responseStreamBroadcast.listen(_onResponse); 34 | } 35 | 36 | Future _onResponse(TCPResponse response) async { 37 | if(response.type == TCPResponseType.profile && response.status == TCPResponseStatus.ok) { 38 | response as GetProfileResponse; 39 | users.update(response.userInfo!.userID, (value) => response.userInfo!, ifAbsent: () => response.userInfo!); 40 | _userInfoStreamController.add(response.userInfo!); 41 | localServiceRepository.storeUserInfo(userInfo: response.userInfo!); 42 | } 43 | else if(response.type == TCPResponseType.modifyProfile && response.status == TCPResponseStatus.ok) { 44 | response as ModifyProfileResponse; 45 | users.update(response.userInfo!.userID, (value) => response.userInfo!, ifAbsent: () => response.userInfo!); 46 | _userInfoStreamController.add(response.userInfo!); 47 | localServiceRepository.storeUserInfo(userInfo: response.userInfo!); 48 | } 49 | } 50 | 51 | //Fetch user info 52 | //1. Check if the user info is in the map 53 | // if so, return the user, otherwise consult the database 54 | //2. If the database has the user info 55 | // add it to the map and stream, otherwise consult the tcp repository 56 | //3. Pass the control to tcp response handler 57 | UserInfo getUserInfo({required int userid}) { 58 | if(users.containsKey(userid)) { 59 | return users[userid]!; 60 | } 61 | Future(() async { 62 | //Consult the database for info 63 | return await localServiceRepository.fetchUserInfoViaID(userid: userid); 64 | }).then((userInfo) async { 65 | if(userInfo == null) { 66 | //Consult the tcp server for info 67 | tcpRepository.pushRequest(GetProfileRequest( 68 | userid: userid, 69 | token: (await SharedPreferences.getInstance()).getInt('token') 70 | )); 71 | } 72 | else { 73 | //Add to map 74 | users.update(userid, (value) => userInfo, ifAbsent: () => userInfo); 75 | //Push to stream 76 | _userInfoStreamController.add(userInfo); 77 | } 78 | }); 79 | //Return a mock userinfo 80 | return UserInfo( 81 | userid: userid, 82 | username: userid.toString(), 83 | ); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /lib/search/cubit/search_cubit.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 17:09:25 4 | * @LastEditTime : 2022-10-13 23:25:20 5 | * @Description : 6 | */ 7 | 8 | import 'dart:async'; 9 | 10 | import 'package:bloc/bloc.dart'; 11 | import 'package:easy_debounce/easy_debounce.dart'; 12 | import 'package:shared_preferences/shared_preferences.dart'; 13 | import 'package:tcp_client/repositories/local_service_repository/local_service_repository.dart'; 14 | import 'package:tcp_client/repositories/tcp_repository/models/tcp_request.dart'; 15 | import 'package:tcp_client/repositories/tcp_repository/models/tcp_response.dart'; 16 | import 'package:tcp_client/repositories/tcp_repository/tcp_repository.dart'; 17 | import 'package:tcp_client/search/cubit/search_state.dart'; 18 | import 'package:tcp_client/search/model/history_result.dart'; 19 | import 'package:tcp_client/search/model/user_result.dart'; 20 | 21 | class SearchCubit extends Cubit { 22 | SearchCubit({ 23 | required this.localServiceRepository, 24 | required this.tcpRepository 25 | }): super(const SearchState.empty()) { 26 | subscription = tcpRepository.responseStreamBroadcast.listen(_onResponse); 27 | } 28 | 29 | final LocalServiceRepository localServiceRepository; 30 | final TCPRepository tcpRepository; 31 | late final StreamSubscription subscription; 32 | 33 | void onKeyChanged(String newKey) { 34 | EasyDebounce.debounce( 35 | 'Search', 36 | const Duration(milliseconds: 500), 37 | () => _performSearch(newKey) 38 | ); 39 | } 40 | 41 | Future _performSearch(String newKey) async { 42 | tcpRepository.pushRequest(SearchUserRequest( 43 | username: newKey, 44 | token: (await SharedPreferences.getInstance()).getInt('token') 45 | )); 46 | var histories = await localServiceRepository.findMessages(pattern: newKey); 47 | var currentUserID = (await SharedPreferences.getInstance()).getInt('userid'); 48 | var historyResults = histories.map((msg) { 49 | var targetID = msg.senderID == currentUserID ? msg.recieverID : msg.senderID; 50 | return HistorySearchResult(contact: targetID, message: msg); 51 | }).toList(); 52 | emit(state.copyWith(historyResults: historyResults)); 53 | } 54 | 55 | Future _onResponse(TCPResponse response) async { 56 | switch(response.type) { 57 | case TCPResponseType.searchUser: { 58 | response as SearchUserResponse; 59 | //TODO: Maybe server search should be ambigious 60 | var userInfo = response.userInfo; 61 | emit(state.copyWith( 62 | userResults: [ 63 | if(userInfo != null) UserSearchResult(userInfo: userInfo) 64 | ] 65 | )); 66 | break; 67 | } 68 | default: break; 69 | } 70 | } 71 | 72 | //Override dispose to cancel the subscription 73 | @override 74 | Future close() { 75 | subscription.cancel(); 76 | return super.close(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /lib/search/cubit/search_state.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 17:08:56 4 | * @LastEditTime : 2022-10-13 17:42:33 5 | * @Description : 6 | */ 7 | 8 | import 'package:equatable/equatable.dart'; 9 | import 'package:tcp_client/search/model/history_result.dart'; 10 | import 'package:tcp_client/search/model/user_result.dart'; 11 | 12 | class SearchState extends Equatable { 13 | const SearchState({ 14 | required this.historyResults, 15 | required this.userResults 16 | }); 17 | const SearchState.empty(): historyResults = const [], userResults = const []; 18 | 19 | final List historyResults; 20 | final List userResults; 21 | 22 | SearchState copyWith({ 23 | List? historyResults, 24 | List? userResults 25 | }) { 26 | return SearchState( 27 | historyResults: historyResults ?? this.historyResults, 28 | userResults: userResults ?? this.userResults 29 | ); 30 | } 31 | 32 | @override 33 | List get props => [historyResults, userResults]; 34 | } 35 | -------------------------------------------------------------------------------- /lib/search/model/history_result.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 17:30:26 4 | * @LastEditTime : 2022-10-13 21:28:46 5 | * @Description : 6 | */ 7 | 8 | import 'package:equatable/equatable.dart'; 9 | import 'package:tcp_client/repositories/common_models/message.dart'; 10 | 11 | class HistorySearchResult extends Equatable { 12 | final int contact; 13 | final Message message; 14 | 15 | const HistorySearchResult({ 16 | required this.contact, 17 | required this.message 18 | }); 19 | 20 | @override 21 | List get props => [contact, message.contentmd5]; 22 | } 23 | -------------------------------------------------------------------------------- /lib/search/model/user_result.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 17:30:36 4 | * @LastEditTime : 2022-10-13 22:39:25 5 | * @Description : 6 | */ 7 | 8 | import 'package:equatable/equatable.dart'; 9 | import 'package:tcp_client/repositories/common_models/userinfo.dart'; 10 | 11 | class UserSearchResult extends Equatable { 12 | final UserInfo userInfo; 13 | 14 | const UserSearchResult({required this.userInfo}); 15 | 16 | @override 17 | List get props => [userInfo.userID]; 18 | } 19 | -------------------------------------------------------------------------------- /lib/search/view/history_tile.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 21:41:49 4 | * @LastEditTime : 2022-10-17 22:23:46 5 | * @Description : 6 | */ 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:tcp_client/common/avatar/avatar.dart'; 10 | import 'package:tcp_client/common/username/username.dart'; 11 | import 'package:tcp_client/repositories/common_models/message.dart'; 12 | 13 | class HistoryTile extends StatelessWidget { 14 | const HistoryTile({ 15 | required this.userID, 16 | required this.message, 17 | super.key 18 | }); 19 | 20 | final int userID; 21 | final Message message; 22 | 23 | @override 24 | Widget build(BuildContext context) { 25 | return Padding( 26 | padding: const EdgeInsets.symmetric( 27 | vertical: 16.0, 28 | horizontal: 36.0 29 | ), 30 | child: IntrinsicHeight( 31 | child: Row( 32 | mainAxisSize: MainAxisSize.max, 33 | crossAxisAlignment: CrossAxisAlignment.center, 34 | children: [ 35 | UserAvatar(userid: userID), 36 | const SizedBox(width: 12,), 37 | Expanded( 38 | child: Column( 39 | crossAxisAlignment: CrossAxisAlignment.start, 40 | children: [ 41 | Padding( 42 | padding: const EdgeInsets.symmetric( 43 | vertical: 8.0, 44 | horizontal: 0 45 | ), 46 | child: UserNameText(userid: userID, fontWeight: FontWeight.bold,) 47 | ), 48 | const Spacer(), 49 | Padding( 50 | padding: const EdgeInsets.symmetric( 51 | vertical: 4.0 52 | ), 53 | child: Text( 54 | message.contentDecoded, 55 | maxLines: 1, 56 | overflow: TextOverflow.ellipsis, 57 | style: const TextStyle( 58 | fontSize: 16, 59 | ), 60 | ), 61 | ) 62 | ], 63 | ), 64 | ), 65 | Padding( 66 | padding: const EdgeInsets.symmetric( 67 | vertical: 8.0, 68 | horizontal: 0 69 | ), 70 | child: Align( 71 | alignment: Alignment.topCenter, 72 | child: Text( 73 | getTimeStamp(message.timeStamp) 74 | ), 75 | ), 76 | ), 77 | ], 78 | ), 79 | ), 80 | ); 81 | } 82 | 83 | String getTimeStamp(int timeStamp) { 84 | var date = DateTime.fromMillisecondsSinceEpoch(timeStamp); 85 | var weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']; 86 | //If date is today, return time 87 | if(date.day == DateTime.now().day) { 88 | return '${date.hour}:${date.minute}'; 89 | } 90 | //If date is yesterday, return 'yesterday' 91 | if(date.day == DateTime.now().day - 1) { 92 | return 'yesterday'; 93 | } 94 | //If date is within this week, return the weekday in english 95 | if(date.weekday < DateTime.now().weekday) { 96 | return weekdays[date.weekday - 1]; 97 | } 98 | //Otherwise return the date in english 99 | return '${date.month}/${date.day}'; 100 | } 101 | } -------------------------------------------------------------------------------- /lib/search/view/search_bar.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 17:06:52 4 | * @LastEditTime : 2022-10-20 17:30:37 5 | * @Description : 6 | */ 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:flutter_bloc/flutter_bloc.dart'; 10 | import 'package:tcp_client/search/cubit/search_cubit.dart'; 11 | 12 | class SearchBar extends StatelessWidget { 13 | const SearchBar({super.key}); 14 | 15 | @override 16 | Widget build(BuildContext context) { 17 | return Padding( 18 | padding: const EdgeInsets.symmetric(vertical: 2.0), 19 | child: TextField( 20 | onChanged: (value) { 21 | context.read().onKeyChanged(value); 22 | }, 23 | style: const TextStyle( 24 | color: Colors.white, 25 | fontSize: 18.0 26 | ), 27 | showCursor: true, 28 | cursorColor: Colors.white, 29 | decoration: const InputDecoration( 30 | border: InputBorder.none 31 | // errorBorder: UnderlineInputBorder( 32 | // borderSide: BorderSide(color: Colors.red, width: 2.0) 33 | // ), 34 | // disabledBorder: InputBorder.none, 35 | // enabledBorder: UnderlineInputBorder( 36 | // borderSide: BorderSide(color: Colors.blue, width: 2.0) 37 | // ), 38 | // focusedBorder: UnderlineInputBorder( 39 | // borderSide: BorderSide(color: Colors.white, width: 2.0) 40 | // ) 41 | ), 42 | ), 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/search/view/user_tile.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author : Linloir 3 | * @Date : 2022-10-13 21:41:41 4 | * @LastEditTime : 2022-10-18 11:28:17 5 | * @Description : 6 | */ 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:flutter_bloc/flutter_bloc.dart'; 10 | import 'package:tcp_client/common/avatar/avatar.dart'; 11 | import 'package:tcp_client/common/username/username.dart'; 12 | import 'package:tcp_client/profile/user_profile_page.dart'; 13 | import 'package:tcp_client/repositories/common_models/userinfo.dart'; 14 | import 'package:tcp_client/repositories/user_repository/user_repository.dart'; 15 | import 'package:tcp_client/search/cubit/search_cubit.dart'; 16 | 17 | class UserTile extends StatelessWidget { 18 | const UserTile({ 19 | required this.userInfo, 20 | super.key 21 | }); 22 | 23 | final UserInfo userInfo; 24 | 25 | @override 26 | Widget build(BuildContext context) { 27 | return InkWell( 28 | onTap: () { 29 | Navigator.of(context).push(ProfilePage.route( 30 | userID: userInfo.userID, 31 | localServiceRepository: context.read().localServiceRepository, 32 | tcpRepository: context.read().tcpRepository, 33 | userRepository: context.read() 34 | )); 35 | }, 36 | child: Padding( 37 | padding: const EdgeInsets.symmetric( 38 | horizontal: 36, 39 | vertical: 16, 40 | ), 41 | child: Row( 42 | children: [ 43 | UserAvatar(userid: userInfo.userID), 44 | const SizedBox(width: 12,), 45 | Expanded( 46 | child: Padding( 47 | padding: const EdgeInsets.symmetric( 48 | vertical: 12.0 49 | ), 50 | child: UserNameText( 51 | userid: userInfo.userID, 52 | ) 53 | ) 54 | ), 55 | ], 56 | ), 57 | ), 58 | ); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /linux/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.10) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | 12 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...), 13 | # which isn't available in 3.10. 14 | function(list_prepend LIST_NAME PREFIX) 15 | set(NEW_LIST "") 16 | foreach(element ${${LIST_NAME}}) 17 | list(APPEND NEW_LIST "${PREFIX}${element}") 18 | endforeach(element) 19 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) 20 | endfunction() 21 | 22 | # === Flutter Library === 23 | # System-level dependencies. 24 | find_package(PkgConfig REQUIRED) 25 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 26 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) 27 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) 28 | 29 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") 30 | 31 | # Published to parent scope for install step. 32 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 33 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 34 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 35 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) 36 | 37 | list(APPEND FLUTTER_LIBRARY_HEADERS 38 | "fl_basic_message_channel.h" 39 | "fl_binary_codec.h" 40 | "fl_binary_messenger.h" 41 | "fl_dart_project.h" 42 | "fl_engine.h" 43 | "fl_json_message_codec.h" 44 | "fl_json_method_codec.h" 45 | "fl_message_codec.h" 46 | "fl_method_call.h" 47 | "fl_method_channel.h" 48 | "fl_method_codec.h" 49 | "fl_method_response.h" 50 | "fl_plugin_registrar.h" 51 | "fl_plugin_registry.h" 52 | "fl_standard_message_codec.h" 53 | "fl_standard_method_codec.h" 54 | "fl_string_codec.h" 55 | "fl_value.h" 56 | "fl_view.h" 57 | "flutter_linux.h" 58 | ) 59 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") 60 | add_library(flutter INTERFACE) 61 | target_include_directories(flutter INTERFACE 62 | "${EPHEMERAL_DIR}" 63 | ) 64 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") 65 | target_link_libraries(flutter INTERFACE 66 | PkgConfig::GTK 67 | PkgConfig::GLIB 68 | PkgConfig::GIO 69 | ) 70 | add_dependencies(flutter flutter_assemble) 71 | 72 | # === Flutter tool backend === 73 | # _phony_ is a non-existent file to force this command to run every time, 74 | # since currently there's no way to get a full input/output list from the 75 | # flutter tool. 76 | add_custom_command( 77 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 78 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_ 79 | COMMAND ${CMAKE_COMMAND} -E env 80 | ${FLUTTER_TOOL_ENVIRONMENT} 81 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" 82 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} 83 | VERBATIM 84 | ) 85 | add_custom_target(flutter_assemble DEPENDS 86 | "${FLUTTER_LIBRARY}" 87 | ${FLUTTER_LIBRARY_HEADERS} 88 | ) 89 | -------------------------------------------------------------------------------- /linux/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | #include 10 | #include 11 | 12 | void fl_register_plugins(FlPluginRegistry* registry) { 13 | g_autoptr(FlPluginRegistrar) screen_retriever_registrar = 14 | fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin"); 15 | screen_retriever_plugin_register_with_registrar(screen_retriever_registrar); 16 | g_autoptr(FlPluginRegistrar) window_manager_registrar = 17 | fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin"); 18 | window_manager_plugin_register_with_registrar(window_manager_registrar); 19 | } 20 | -------------------------------------------------------------------------------- /linux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void fl_register_plugins(FlPluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /linux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | screen_retriever 7 | window_manager 8 | ) 9 | 10 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 11 | ) 12 | 13 | set(PLUGIN_BUNDLED_LIBRARIES) 14 | 15 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 16 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) 17 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 18 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 19 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 20 | endforeach(plugin) 21 | 22 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 23 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) 24 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 25 | endforeach(ffi_plugin) 26 | -------------------------------------------------------------------------------- /linux/main.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | int main(int argc, char** argv) { 4 | g_autoptr(MyApplication) app = my_application_new(); 5 | return g_application_run(G_APPLICATION(app), argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /linux/my_application.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | #include 4 | #ifdef GDK_WINDOWING_X11 5 | #include 6 | #endif 7 | 8 | #include "flutter/generated_plugin_registrant.h" 9 | 10 | struct _MyApplication { 11 | GtkApplication parent_instance; 12 | char** dart_entrypoint_arguments; 13 | }; 14 | 15 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) 16 | 17 | // Implements GApplication::activate. 18 | static void my_application_activate(GApplication* application) { 19 | MyApplication* self = MY_APPLICATION(application); 20 | GtkWindow* window = 21 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); 22 | 23 | // Use a header bar when running in GNOME as this is the common style used 24 | // by applications and is the setup most users will be using (e.g. Ubuntu 25 | // desktop). 26 | // If running on X and not using GNOME then just use a traditional title bar 27 | // in case the window manager does more exotic layout, e.g. tiling. 28 | // If running on Wayland assume the header bar will work (may need changing 29 | // if future cases occur). 30 | gboolean use_header_bar = TRUE; 31 | #ifdef GDK_WINDOWING_X11 32 | GdkScreen* screen = gtk_window_get_screen(window); 33 | if (GDK_IS_X11_SCREEN(screen)) { 34 | const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); 35 | if (g_strcmp0(wm_name, "GNOME Shell") != 0) { 36 | use_header_bar = FALSE; 37 | } 38 | } 39 | #endif 40 | if (use_header_bar) { 41 | GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); 42 | gtk_widget_show(GTK_WIDGET(header_bar)); 43 | gtk_header_bar_set_title(header_bar, "tcp_client"); 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, "tcp_client"); 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 "ephemeral/Flutter-Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /macos/Flutter/Flutter-Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "ephemeral/Flutter-Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /macos/Flutter/GeneratedPluginRegistrant.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | import FlutterMacOS 6 | import Foundation 7 | 8 | import path_provider_macos 9 | import screen_retriever 10 | import shared_preferences_macos 11 | import sqflite 12 | import window_manager 13 | 14 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { 15 | PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) 16 | ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin")) 17 | SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) 18 | SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) 19 | WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin")) 20 | } 21 | -------------------------------------------------------------------------------- /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/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/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 = tcp_client 9 | 10 | // The application's bundle identifier 11 | PRODUCT_BUNDLE_IDENTIFIER = com.example.tcpClient 12 | 13 | // The copyright displayed in application information 14 | PRODUCT_COPYRIGHT = Copyright © 2022 com.example. 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 | -------------------------------------------------------------------------------- /web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/web/favicon.png -------------------------------------------------------------------------------- /web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/web/icons/Icon-192.png -------------------------------------------------------------------------------- /web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/web/icons/Icon-512.png -------------------------------------------------------------------------------- /web/icons/Icon-maskable-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/web/icons/Icon-maskable-192.png -------------------------------------------------------------------------------- /web/icons/Icon-maskable-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/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 | tcp_client 33 | 34 | 35 | 39 | 40 | 41 | 42 | 43 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tcp_client", 3 | "short_name": "tcp_client", 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(tcp_client 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 "LChatClient") 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 | #include 10 | #include 11 | 12 | void RegisterPlugins(flutter::PluginRegistry* registry) { 13 | ScreenRetrieverPluginRegisterWithRegistrar( 14 | registry->GetRegistrarForPlugin("ScreenRetrieverPlugin")); 15 | WindowManagerPluginRegisterWithRegistrar( 16 | registry->GetRegistrarForPlugin("WindowManagerPlugin")); 17 | } 18 | -------------------------------------------------------------------------------- /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 | screen_retriever 7 | window_manager 8 | ) 9 | 10 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 11 | ) 12 | 13 | set(PLUGIN_BUNDLED_LIBRARIES) 14 | 15 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 16 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 17 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 18 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 19 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 20 | endforeach(plugin) 21 | 22 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 23 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) 24 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 25 | endforeach(ffi_plugin) 26 | -------------------------------------------------------------------------------- /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_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 37 | 38 | # Run the Flutter tool portions of the build. This must not be removed. 39 | add_dependencies(${BINARY_NAME} flutter_assemble) 40 | -------------------------------------------------------------------------------- /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.linloir" "\0" 93 | VALUE "FileDescription", "LChatClient" "\0" 94 | VALUE "FileVersion", VERSION_AS_STRING "\0" 95 | VALUE "InternalName", "LChatClient" "\0" 96 | VALUE "LegalCopyright", "Copyright (C) 2022 com.linloir. All rights reserved." "\0" 97 | VALUE "OriginalFilename", "LChatClient.exe" "\0" 98 | VALUE "ProductName", "LChatClient" "\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 | return true; 30 | } 31 | 32 | void FlutterWindow::OnDestroy() { 33 | if (flutter_controller_) { 34 | flutter_controller_ = nullptr; 35 | } 36 | 37 | Win32Window::OnDestroy(); 38 | } 39 | 40 | LRESULT 41 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message, 42 | WPARAM const wparam, 43 | LPARAM const lparam) noexcept { 44 | // Give Flutter, including plugins, an opportunity to handle window messages. 45 | if (flutter_controller_) { 46 | std::optional result = 47 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, 48 | lparam); 49 | if (result) { 50 | return *result; 51 | } 52 | } 53 | 54 | switch (message) { 55 | case WM_FONTCHANGE: 56 | flutter_controller_->engine()->ReloadSystemFonts(); 57 | break; 58 | } 59 | 60 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam); 61 | } 62 | -------------------------------------------------------------------------------- /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.CreateAndShow(L"tcp_client", 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/Linloir/Simple-TCP-Client/26f330f962128b82ee65b2b811486f03ac25e0d1/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 and shows a win32 window with |title| and position and size using 32 | // |origin| and |size|. New windows are created on the default monitor. Window 33 | // sizes are specified to the OS in physical pixels, hence to ensure a 34 | // consistent size to will treat the width height passed in to this function 35 | // as logical pixels and scale to appropriate for the default monitor. Returns 36 | // true if the window was created successfully. 37 | bool CreateAndShow(const std::wstring& title, 38 | const Point& origin, 39 | const Size& size); 40 | 41 | // Release OS resources associated with window. 42 | void Destroy(); 43 | 44 | // Inserts |content| into the window tree. 45 | void SetChildContent(HWND content); 46 | 47 | // Returns the backing Window handle to enable clients to set icon and other 48 | // window properties. Returns nullptr if the window has been destroyed. 49 | HWND GetHandle(); 50 | 51 | // If true, closing this window will quit the application. 52 | void SetQuitOnClose(bool quit_on_close); 53 | 54 | // Return a RECT representing the bounds of the current client area. 55 | RECT GetClientArea(); 56 | 57 | protected: 58 | // Processes and route salient window messages for mouse handling, 59 | // size change and DPI. Delegates handling of these to member overloads that 60 | // inheriting classes can handle. 61 | virtual LRESULT MessageHandler(HWND window, 62 | UINT const message, 63 | WPARAM const wparam, 64 | LPARAM const lparam) noexcept; 65 | 66 | // Called when CreateAndShow is called, allowing subclass window-related 67 | // setup. Subclasses should return false if setup fails. 68 | virtual bool OnCreate(); 69 | 70 | // Called when Destroy is called. 71 | virtual void OnDestroy(); 72 | 73 | private: 74 | friend class WindowClassRegistrar; 75 | 76 | // OS callback called by message pump. Handles the WM_NCCREATE message which 77 | // is passed when the non-client area is being created and enables automatic 78 | // non-client DPI scaling so that the non-client area automatically 79 | // responsponds to changes in DPI. All other messages are handled by 80 | // MessageHandler. 81 | static LRESULT CALLBACK WndProc(HWND const window, 82 | UINT const message, 83 | WPARAM const wparam, 84 | LPARAM const lparam) noexcept; 85 | 86 | // Retrieves a class instance pointer for |window| 87 | static Win32Window* GetThisFromHandle(HWND const window) noexcept; 88 | 89 | bool quit_on_close_ = false; 90 | 91 | // window handle for top level window. 92 | HWND window_handle_ = nullptr; 93 | 94 | // window handle for hosted content. 95 | HWND child_content_ = nullptr; 96 | }; 97 | 98 | #endif // RUNNER_WIN32_WINDOW_H_ 99 | --------------------------------------------------------------------------------