├── .gitignore ├── .metadata ├── .vscode └── launch.json ├── README.md ├── analysis_options.yaml ├── android ├── .gitignore ├── app │ ├── build.gradle │ └── src │ │ ├── debug │ │ └── AndroidManifest.xml │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── kotlin │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── flutter_chat_app │ │ │ │ └── MainActivity.kt │ │ └── res │ │ │ ├── drawable-v21 │ │ │ └── launch_background.xml │ │ │ ├── drawable │ │ │ └── launch_background.xml │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── values-night │ │ │ └── styles.xml │ │ │ └── values │ │ │ └── styles.xml │ │ └── profile │ │ └── AndroidManifest.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ └── gradle-wrapper.properties └── settings.gradle ├── assets └── images │ └── chat.png ├── 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 ├── blocs │ ├── auth │ │ ├── auth_bloc.dart │ │ ├── auth_bloc.freezed.dart │ │ ├── auth_event.dart │ │ └── auth_state.dart │ ├── blocs.dart │ ├── chat │ │ ├── chat_bloc.dart │ │ ├── chat_bloc.freezed.dart │ │ ├── chat_event.dart │ │ └── chat_state.dart │ └── user │ │ ├── user_bloc.dart │ │ ├── user_bloc.freezed.dart │ │ ├── user_event.dart │ │ └── user_state.dart ├── cubits │ ├── cubits.dart │ └── guest │ │ ├── guest_cubit.dart │ │ ├── guest_cubit.freezed.dart │ │ └── guest_state.dart ├── enums │ ├── data_status.dart │ └── enums.dart ├── main.dart ├── models │ ├── app_response.dart │ ├── app_response.g.dart │ ├── chat_message_model.dart │ ├── chat_message_model.freezed.dart │ ├── chat_message_model.g.dart │ ├── chat_model.dart │ ├── chat_model.freezed.dart │ ├── chat_model.g.dart │ ├── chat_participant_model.dart │ ├── chat_participant_model.freezed.dart │ ├── chat_participant_model.g.dart │ ├── models.dart │ ├── requests │ │ ├── create_chat_message_request.dart │ │ ├── create_chat_message_request.freezed.dart │ │ ├── create_chat_message_request.g.dart │ │ ├── create_chat_request.dart │ │ ├── create_chat_request.freezed.dart │ │ ├── create_chat_request.g.dart │ │ ├── login_request.dart │ │ ├── login_request.freezed.dart │ │ ├── login_request.g.dart │ │ ├── register_request.dart │ │ ├── register_request.freezed.dart │ │ ├── register_request.g.dart │ │ └── requests.dart │ ├── user_model.dart │ ├── user_model.freezed.dart │ └── user_model.g.dart ├── repositories │ ├── auth │ │ ├── auth_repository.dart │ │ └── base_auth_repository.dart │ ├── chat │ │ ├── base_chat_repository.dart │ │ └── chat_respository.dart │ ├── chat_message │ │ ├── base_chat_message_repository.dart │ │ └── chat_message_repository.dart │ ├── core │ │ └── endpoints.dart │ ├── repositories.dart │ └── user │ │ ├── base_user_repository.dart │ │ └── user_repository.dart ├── screens │ ├── chat │ │ ├── chat_screen.dart │ │ └── data.dart │ ├── chat_list │ │ ├── chat_list_item.dart │ │ └── chat_list_screen.dart │ ├── guest │ │ └── guest_screen.dart │ ├── screens.dart │ └── splash │ │ └── splash_screen.dart ├── utils │ ├── chat.dart │ ├── dio_client │ │ ├── app_interceptors.dart │ │ └── dio_client.dart │ ├── formatting.dart │ ├── laravel_echo │ │ └── laravel_echo.dart │ ├── logger.dart │ ├── onesignal │ │ └── onesignal.dart │ └── utils.dart └── widgets │ ├── blank_content.dart │ ├── startup_container.dart │ └── widgets.dart ├── linux ├── .gitignore ├── CMakeLists.txt ├── flutter │ ├── CMakeLists.txt │ ├── generated_plugin_registrant.cc │ ├── generated_plugin_registrant.h │ └── generated_plugins.cmake ├── main.cc ├── my_application.cc └── my_application.h ├── macos ├── .gitignore ├── Flutter │ ├── Flutter-Debug.xcconfig │ ├── Flutter-Release.xcconfig │ └── GeneratedPluginRegistrant.swift ├── Runner.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── xcshareddata │ │ └── xcschemes │ │ └── Runner.xcscheme ├── Runner.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── Runner │ ├── AppDelegate.swift │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── app_icon_1024.png │ │ ├── app_icon_128.png │ │ ├── app_icon_16.png │ │ ├── app_icon_256.png │ │ ├── app_icon_32.png │ │ ├── app_icon_512.png │ │ └── app_icon_64.png │ ├── Base.lproj │ └── MainMenu.xib │ ├── Configs │ ├── AppInfo.xcconfig │ ├── Debug.xcconfig │ ├── Release.xcconfig │ └── Warnings.xcconfig │ ├── DebugProfile.entitlements │ ├── Info.plist │ ├── MainFlutterWindow.swift │ └── Release.entitlements ├── pubspec.lock ├── pubspec.yaml ├── test └── widget_test.dart ├── web ├── favicon.png ├── icons │ ├── Icon-192.png │ ├── Icon-512.png │ ├── Icon-maskable-192.png │ └── Icon-maskable-512.png ├── index.html └── manifest.json └── windows ├── .gitignore ├── CMakeLists.txt ├── flutter ├── CMakeLists.txt ├── generated_plugin_registrant.cc ├── generated_plugin_registrant.h └── generated_plugins.cmake └── runner ├── CMakeLists.txt ├── Runner.rc ├── flutter_window.cpp ├── flutter_window.h ├── main.cpp ├── resource.h ├── resources └── app_icon.ico ├── runner.exe.manifest ├── utils.cpp ├── utils.h ├── win32_window.cpp └── win32_window.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .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 | -------------------------------------------------------------------------------- /.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: ffccd96b62ee8cec7740dab303538c5fc26ac543 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: ffccd96b62ee8cec7740dab303538c5fc26ac543 17 | base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543 18 | - platform: android 19 | create_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543 20 | base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543 21 | - platform: ios 22 | create_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543 23 | base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543 24 | - platform: linux 25 | create_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543 26 | base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543 27 | - platform: macos 28 | create_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543 29 | base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543 30 | - platform: web 31 | create_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543 32 | base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543 33 | - platform: windows 34 | create_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543 35 | base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543 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 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "flutter_chat_app", 9 | "request": "launch", 10 | "type": "dart" 11 | }, 12 | { 13 | "name": "AndroidFirst", 14 | "request": "launch", 15 | "type": "dart", 16 | "deviceId": "emulator-5554" 17 | // "flutterMode": "profile" 18 | }, 19 | { 20 | "name": "AndroidSecond", 21 | "request": "launch", 22 | "type": "dart", 23 | "deviceId": "emulator-5556" 24 | // "flutterMode": "release" 25 | } 26 | ], 27 | "compounds": [ 28 | { 29 | "name": "All Devices", 30 | "configurations": ["AndroidFirst", "AndroidSecond"] 31 | } 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # flutter_chat_app 2 | 3 | A new Flutter project. 4 | 5 | ## Getting Started 6 | 7 | This project is a starting point for a Flutter application. 8 | 9 | A few resources to get you started if this is your first Flutter project: 10 | 11 | - [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) 12 | - [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) 13 | 14 | For help getting started with Flutter development, view the 15 | [online documentation](https://docs.flutter.dev/), which offers tutorials, 16 | samples, guidance on mobile development, and a full API reference. 17 | -------------------------------------------------------------------------------- /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 | analyzer: 31 | errors: 32 | invalid_annotation_target: ignore 33 | -------------------------------------------------------------------------------- /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.flutter_chat_app" 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 | multiDexEnabled true 55 | } 56 | 57 | buildTypes { 58 | release { 59 | // TODO: Add your own signing config for the release build. 60 | // Signing with the debug keys for now, so `flutter run --release` works. 61 | signingConfig signingConfigs.debug 62 | } 63 | } 64 | } 65 | 66 | flutter { 67 | source '../..' 68 | } 69 | 70 | dependencies { 71 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 72 | } 73 | -------------------------------------------------------------------------------- /android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 16 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 31 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /android/app/src/main/kotlin/com/example/flutter_chat_app/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.flutter_chat_app 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/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/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 | -------------------------------------------------------------------------------- /assets/images/chat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/assets/images/chat.png -------------------------------------------------------------------------------- /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/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/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/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/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/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/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/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/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/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/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/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/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/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/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/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/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/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/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/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/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/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/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/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/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/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/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/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/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/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/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/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/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 | Flutter Chat App 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | flutter_chat_app 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/blocs/auth/auth_bloc.dart: -------------------------------------------------------------------------------- 1 | import 'package:freezed_annotation/freezed_annotation.dart'; 2 | import 'package:hydrated_bloc/hydrated_bloc.dart'; 3 | import 'package:flutter_chat_app/models/models.dart'; 4 | 5 | part 'auth_event.dart'; 6 | part 'auth_state.dart'; 7 | part 'auth_bloc.freezed.dart'; 8 | 9 | class AuthBloc extends HydratedBloc { 10 | AuthBloc() : super(AuthState.initial()) { 11 | on((event, emit) { 12 | emit(state.copyWith( 13 | isAuthenticated: event.isAuthenticated, 14 | user: event.user, 15 | token: event.token, 16 | )); 17 | }); 18 | } 19 | 20 | @override 21 | AuthState? fromJson(Map json) { 22 | return AuthState( 23 | isAuthenticated: json['isAuthenticated'], 24 | user: json['user'] != null ? UserEntity.fromJson(json['user']) : null, 25 | token: json['token'], 26 | ); 27 | } 28 | 29 | @override 30 | Map? toJson(AuthState state) { 31 | return { 32 | 'isAuthenticated': state.isAuthenticated, 33 | 'token': state.token, 34 | 'user': state.user != null ? state.user!.toJson() : null, 35 | }; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/blocs/auth/auth_event.dart: -------------------------------------------------------------------------------- 1 | part of 'auth_bloc.dart'; 2 | 3 | @freezed 4 | class AuthEvent with _$AuthEvent { 5 | const factory AuthEvent.authenticate({ 6 | UserEntity? user, 7 | String? token, 8 | required bool isAuthenticated, 9 | }) = Authenticated; 10 | } 11 | -------------------------------------------------------------------------------- /lib/blocs/auth/auth_state.dart: -------------------------------------------------------------------------------- 1 | part of 'auth_bloc.dart'; 2 | 3 | @freezed 4 | class AuthState with _$AuthState { 5 | const factory AuthState({ 6 | required bool isAuthenticated, 7 | UserEntity? user, 8 | String? token, 9 | }) = _AuthState; 10 | 11 | factory AuthState.initial() { 12 | return const AuthState( 13 | isAuthenticated: false, 14 | user: null, 15 | token: null, 16 | ); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lib/blocs/blocs.dart: -------------------------------------------------------------------------------- 1 | export "auth/auth_bloc.dart"; 2 | -------------------------------------------------------------------------------- /lib/blocs/chat/chat_bloc.dart: -------------------------------------------------------------------------------- 1 | import 'package:dash_chat_2/dash_chat_2.dart'; 2 | import 'package:flutter_bloc/flutter_bloc.dart'; 3 | import 'package:flutter_chat_app/models/requests/requests.dart'; 4 | import 'package:flutter_chat_app/repositories/chat_message/chat_message_repository.dart'; 5 | import 'package:freezed_annotation/freezed_annotation.dart'; 6 | import 'package:flutter_chat_app/enums/enums.dart'; 7 | import 'package:flutter_chat_app/models/models.dart'; 8 | import 'package:flutter_chat_app/repositories/chat/chat_respository.dart'; 9 | 10 | part 'chat_event.dart'; 11 | part 'chat_state.dart'; 12 | part 'chat_bloc.freezed.dart'; 13 | 14 | class ChatBloc extends Bloc { 15 | final ChatRepository _chatRepository; 16 | final ChatMessageRepository _chatMessageRepository; 17 | 18 | ChatBloc({ 19 | required ChatRepository chatRepository, 20 | required ChatMessageRepository chatMessageRepository, 21 | }) : _chatRepository = chatRepository, 22 | _chatMessageRepository = chatMessageRepository, 23 | super(ChatState.initial()) { 24 | on((event, emit) async { 25 | if (state.status.isLoading) return; 26 | 27 | emit(state.copyWith(status: DataStatus.loading)); 28 | 29 | final result = await _chatRepository.getChats(); 30 | 31 | emit(state.copyWith( 32 | status: DataStatus.loaded, 33 | chats: result.success ? result.data ?? [] : [], 34 | )); 35 | }); 36 | on((event, emit) { 37 | emit(state.copyWith( 38 | chatMessages: [], 39 | message: '', 40 | status: DataStatus.initial, 41 | selectedChat: null, 42 | otherUserId: null, 43 | isLastPage: false, 44 | page: 1, 45 | notificationChatId: null, 46 | chats: (event.shouldResetChat != null && event.shouldResetChat!) 47 | ? [] 48 | : state.chats, 49 | )); 50 | }); 51 | on((event, emit) { 52 | emit(state.copyWith( 53 | otherUserId: event.user.id, 54 | )); 55 | }); 56 | on((event, emit) async { 57 | if (state.status.isFetching) return; 58 | 59 | emit(state.copyWith(status: DataStatus.fetching)); 60 | 61 | ChatEntity? chat; 62 | 63 | if (state.isSearchChat) { 64 | final chatResult = await _chatRepository.createChat( 65 | CreateChatRequest(userId: state.otherUserId!), 66 | ); 67 | 68 | if (chatResult.success) { 69 | chat = chatResult.data; 70 | } 71 | } else if (state.isListChat) { 72 | chat = state.selectedChat; 73 | } else if (state.isNotificationChat) { 74 | final chatResult = 75 | await _chatRepository.getSingleChat(state.notificationChatId!); 76 | 77 | if (chatResult.success) { 78 | chat = chatResult.data; 79 | } 80 | } 81 | 82 | if (chat == null) { 83 | emit(state.copyWith( 84 | chatMessages: [], 85 | status: DataStatus.loaded, 86 | )); 87 | return; 88 | } 89 | 90 | final result = await _chatMessageRepository.getChatMessages( 91 | chatId: chat.id, 92 | page: 1, 93 | ); 94 | 95 | if (result.success) { 96 | emit(state.copyWith( 97 | chatMessages: result.data ?? [], 98 | status: DataStatus.loaded, 99 | selectedChat: chat, 100 | )); 101 | } else { 102 | emit(state.copyWith( 103 | chatMessages: [], 104 | status: DataStatus.error, 105 | message: result.message, 106 | )); 107 | } 108 | }); 109 | on((event, emit) async { 110 | if (state.status.isSubmitting) return; 111 | emit(state.copyWith(status: DataStatus.submitting)); 112 | 113 | final result = await _chatMessageRepository.createChatMessage( 114 | CreateChatMessageRequest( 115 | chatId: event.chatId, 116 | message: event.message.text, 117 | ), 118 | event.socketId, 119 | ); 120 | 121 | if (result.success) { 122 | final messages = [result.data!, ...state.chatMessages]; 123 | 124 | emit( 125 | state.copyWith( 126 | chatMessages: messages, 127 | status: DataStatus.loaded, 128 | ), 129 | ); 130 | } else { 131 | emit(state.copyWith( 132 | status: DataStatus.loaded, 133 | )); 134 | } 135 | }); 136 | 137 | on((event, emit) async { 138 | if (state.status.isLoadingMore || state.isLastPage) return; 139 | 140 | emit(state.copyWith(status: DataStatus.loadingMore)); 141 | 142 | final newPage = state.page + 1; 143 | final result = await _chatMessageRepository.getChatMessages( 144 | chatId: state.selectedChat!.id, 145 | page: newPage, 146 | ); 147 | 148 | if (result.success) { 149 | final newMessages = result.data ?? []; 150 | 151 | if (newMessages.isNotEmpty) { 152 | emit(state.copyWith( 153 | chatMessages: [...state.chatMessages, ...newMessages], 154 | status: DataStatus.loaded, 155 | page: newPage, 156 | )); 157 | } else { 158 | emit(state.copyWith( 159 | status: DataStatus.loaded, 160 | isLastPage: true, 161 | )); 162 | } 163 | } else { 164 | emit(state.copyWith( 165 | message: result.message, 166 | status: DataStatus.error, 167 | )); 168 | } 169 | }); 170 | 171 | on((event, emit) { 172 | emit(state.copyWith(selectedChat: event.chat)); 173 | }); 174 | on((event, emit) { 175 | emit(state.copyWith( 176 | chatMessages: [event.message, ...state.chatMessages], 177 | )); 178 | }); 179 | on((event, emit) { 180 | emit(state.copyWith(notificationChatId: event.chatId)); 181 | }); 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /lib/blocs/chat/chat_event.dart: -------------------------------------------------------------------------------- 1 | part of 'chat_bloc.dart'; 2 | 3 | @freezed 4 | class ChatEvent with _$ChatEvent { 5 | const factory ChatEvent.started() = ChatStarted; 6 | const factory ChatEvent.reset({bool? shouldResetChat}) = ChatReset; 7 | const factory ChatEvent.userSelected(UserEntity user) = UserSelected; 8 | const factory ChatEvent.getChatMessage() = GetChatMessage; 9 | const factory ChatEvent.loadMoreChatMessage() = LoadMoreChatMessage; 10 | const factory ChatEvent.sendMessage( 11 | int chatId, 12 | ChatMessage message, { 13 | required String socketId, 14 | }) = SendMessage; 15 | const factory ChatEvent.chatSelected(ChatEntity chat) = ChatSelected; 16 | const factory ChatEvent.addNewMessage(ChatMessageEntity message) = 17 | AddNewMessage; 18 | const factory ChatEvent.chatNotificationOpened(int chatId) = 19 | ChatNotificationOpened; 20 | } 21 | -------------------------------------------------------------------------------- /lib/blocs/chat/chat_state.dart: -------------------------------------------------------------------------------- 1 | part of 'chat_bloc.dart'; 2 | 3 | @freezed 4 | class ChatState with _$ChatState { 5 | const ChatState._(); 6 | 7 | const factory ChatState({ 8 | required List chats, 9 | required List chatMessages, 10 | ChatEntity? selectedChat, 11 | required DataStatus status, 12 | required String message, 13 | int? otherUserId, 14 | required bool isLastPage, 15 | required int page, 16 | int? notificationChatId, 17 | }) = _ChatState; 18 | 19 | factory ChatState.initial() { 20 | return const ChatState( 21 | chats: [], 22 | selectedChat: null, 23 | status: DataStatus.initial, 24 | message: "", 25 | otherUserId: null, 26 | chatMessages: [], 27 | isLastPage: false, 28 | page: 1, 29 | notificationChatId: null, 30 | ); 31 | } 32 | 33 | bool get isSearchChat => otherUserId != null && selectedChat == null; 34 | 35 | bool get isListChat => otherUserId == null && selectedChat != null; 36 | 37 | bool get isNotificationChat => 38 | otherUserId == null && selectedChat == null && notificationChatId != null; 39 | 40 | List get uiChatMessages { 41 | return chatMessages.map((e) => e.toChatMessage).toList(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /lib/blocs/user/user_bloc.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_bloc/flutter_bloc.dart'; 2 | import 'package:freezed_annotation/freezed_annotation.dart'; 3 | import 'package:flutter_chat_app/models/models.dart'; 4 | import 'package:flutter_chat_app/repositories/user/user_repository.dart'; 5 | 6 | part 'user_event.dart'; 7 | part 'user_state.dart'; 8 | part 'user_bloc.freezed.dart'; 9 | 10 | class UserBloc extends Bloc { 11 | final UserRepository _userRepository; 12 | 13 | UserBloc({ 14 | required UserRepository userRepository, 15 | }) : _userRepository = userRepository, 16 | super(const Initial()) { 17 | on((event, emit) async { 18 | final result = await _userRepository.getUsers(); 19 | emit(Loaded(result.data ?? [])); 20 | }); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lib/blocs/user/user_event.dart: -------------------------------------------------------------------------------- 1 | part of 'user_bloc.dart'; 2 | 3 | @freezed 4 | class UserEvent with _$UserEvent { 5 | const factory UserEvent.started() = UserStarted; 6 | } 7 | -------------------------------------------------------------------------------- /lib/blocs/user/user_state.dart: -------------------------------------------------------------------------------- 1 | part of 'user_bloc.dart'; 2 | 3 | @freezed 4 | class UserState with _$UserState { 5 | const factory UserState.initial() = Initial; 6 | const factory UserState.loaded(List users) = Loaded; 7 | } 8 | -------------------------------------------------------------------------------- /lib/cubits/cubits.dart: -------------------------------------------------------------------------------- 1 | export "guest/guest_cubit.dart"; 2 | -------------------------------------------------------------------------------- /lib/cubits/guest/guest_cubit.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_bloc/flutter_bloc.dart'; 2 | import 'package:flutter_chat_app/models/requests/login_request.dart'; 3 | import 'package:flutter_chat_app/models/requests/register_request.dart'; 4 | import 'package:freezed_annotation/freezed_annotation.dart'; 5 | import 'package:flutter_chat_app/blocs/blocs.dart'; 6 | import 'package:flutter_chat_app/repositories/auth/auth_repository.dart'; 7 | import 'package:flutter_login/flutter_login.dart'; 8 | 9 | part 'guest_state.dart'; 10 | part 'guest_cubit.freezed.dart'; 11 | 12 | class GuestCubit extends Cubit { 13 | final AuthRepository _authRepository; 14 | final AuthBloc _authBloc; 15 | 16 | GuestCubit({ 17 | required AuthRepository authRepository, 18 | required AuthBloc authBloc, 19 | }) : _authRepository = authRepository, 20 | _authBloc = authBloc, 21 | super( 22 | const GuestState.initial(), 23 | ); 24 | 25 | Future signIn(LoginData data) async { 26 | final response = await _authRepository.login( 27 | LoginRequest(email: data.name, password: data.password), 28 | ); 29 | if (response.success) { 30 | _authBloc.add(Authenticated( 31 | isAuthenticated: true, 32 | token: response.data!.token, 33 | user: response.data!.user, 34 | )); 35 | 36 | return null; 37 | } 38 | 39 | return response.message; 40 | } 41 | 42 | Future signUp(SignupData data) async { 43 | final response = await _authRepository.register( 44 | RegisterRequest( 45 | email: data.name!, 46 | password: data.password!, 47 | passwordConfirmation: data.password!), 48 | ); 49 | if (response.success) { 50 | _authBloc.add(Authenticated( 51 | isAuthenticated: true, 52 | token: response.data!.token, 53 | user: response.data!.user, 54 | )); 55 | 56 | return null; 57 | } 58 | 59 | return response.message; 60 | } 61 | 62 | Future signOut() async { 63 | _authRepository.logout(); 64 | _authBloc.add(const Authenticated( 65 | isAuthenticated: false, 66 | user: null, 67 | token: null, 68 | )); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /lib/cubits/guest/guest_cubit.freezed.dart: -------------------------------------------------------------------------------- 1 | // coverage:ignore-file 2 | // GENERATED CODE - DO NOT MODIFY BY HAND 3 | // ignore_for_file: type=lint 4 | // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target 5 | 6 | part of 'guest_cubit.dart'; 7 | 8 | // ************************************************************************** 9 | // FreezedGenerator 10 | // ************************************************************************** 11 | 12 | T _$identity(T value) => value; 13 | 14 | final _privateConstructorUsedError = UnsupportedError( 15 | 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); 16 | 17 | /// @nodoc 18 | mixin _$GuestState { 19 | @optionalTypeArgs 20 | TResult when({ 21 | required TResult Function() initial, 22 | }) => 23 | throw _privateConstructorUsedError; 24 | @optionalTypeArgs 25 | TResult? whenOrNull({ 26 | TResult Function()? initial, 27 | }) => 28 | throw _privateConstructorUsedError; 29 | @optionalTypeArgs 30 | TResult maybeWhen({ 31 | TResult Function()? initial, 32 | required TResult orElse(), 33 | }) => 34 | throw _privateConstructorUsedError; 35 | @optionalTypeArgs 36 | TResult map({ 37 | required TResult Function(_Initial value) initial, 38 | }) => 39 | throw _privateConstructorUsedError; 40 | @optionalTypeArgs 41 | TResult? mapOrNull({ 42 | TResult Function(_Initial value)? initial, 43 | }) => 44 | throw _privateConstructorUsedError; 45 | @optionalTypeArgs 46 | TResult maybeMap({ 47 | TResult Function(_Initial value)? initial, 48 | required TResult orElse(), 49 | }) => 50 | throw _privateConstructorUsedError; 51 | } 52 | 53 | /// @nodoc 54 | abstract class $GuestStateCopyWith<$Res> { 55 | factory $GuestStateCopyWith( 56 | GuestState value, $Res Function(GuestState) then) = 57 | _$GuestStateCopyWithImpl<$Res>; 58 | } 59 | 60 | /// @nodoc 61 | class _$GuestStateCopyWithImpl<$Res> implements $GuestStateCopyWith<$Res> { 62 | _$GuestStateCopyWithImpl(this._value, this._then); 63 | 64 | final GuestState _value; 65 | // ignore: unused_field 66 | final $Res Function(GuestState) _then; 67 | } 68 | 69 | /// @nodoc 70 | abstract class _$$_InitialCopyWith<$Res> { 71 | factory _$$_InitialCopyWith( 72 | _$_Initial value, $Res Function(_$_Initial) then) = 73 | __$$_InitialCopyWithImpl<$Res>; 74 | } 75 | 76 | /// @nodoc 77 | class __$$_InitialCopyWithImpl<$Res> extends _$GuestStateCopyWithImpl<$Res> 78 | implements _$$_InitialCopyWith<$Res> { 79 | __$$_InitialCopyWithImpl(_$_Initial _value, $Res Function(_$_Initial) _then) 80 | : super(_value, (v) => _then(v as _$_Initial)); 81 | 82 | @override 83 | _$_Initial get _value => super._value as _$_Initial; 84 | } 85 | 86 | /// @nodoc 87 | 88 | class _$_Initial implements _Initial { 89 | const _$_Initial(); 90 | 91 | @override 92 | String toString() { 93 | return 'GuestState.initial()'; 94 | } 95 | 96 | @override 97 | bool operator ==(dynamic other) { 98 | return identical(this, other) || 99 | (other.runtimeType == runtimeType && other is _$_Initial); 100 | } 101 | 102 | @override 103 | int get hashCode => runtimeType.hashCode; 104 | 105 | @override 106 | @optionalTypeArgs 107 | TResult when({ 108 | required TResult Function() initial, 109 | }) { 110 | return initial(); 111 | } 112 | 113 | @override 114 | @optionalTypeArgs 115 | TResult? whenOrNull({ 116 | TResult Function()? initial, 117 | }) { 118 | return initial?.call(); 119 | } 120 | 121 | @override 122 | @optionalTypeArgs 123 | TResult maybeWhen({ 124 | TResult Function()? initial, 125 | required TResult orElse(), 126 | }) { 127 | if (initial != null) { 128 | return initial(); 129 | } 130 | return orElse(); 131 | } 132 | 133 | @override 134 | @optionalTypeArgs 135 | TResult map({ 136 | required TResult Function(_Initial value) initial, 137 | }) { 138 | return initial(this); 139 | } 140 | 141 | @override 142 | @optionalTypeArgs 143 | TResult? mapOrNull({ 144 | TResult Function(_Initial value)? initial, 145 | }) { 146 | return initial?.call(this); 147 | } 148 | 149 | @override 150 | @optionalTypeArgs 151 | TResult maybeMap({ 152 | TResult Function(_Initial value)? initial, 153 | required TResult orElse(), 154 | }) { 155 | if (initial != null) { 156 | return initial(this); 157 | } 158 | return orElse(); 159 | } 160 | } 161 | 162 | abstract class _Initial implements GuestState { 163 | const factory _Initial() = _$_Initial; 164 | } 165 | -------------------------------------------------------------------------------- /lib/cubits/guest/guest_state.dart: -------------------------------------------------------------------------------- 1 | part of 'guest_cubit.dart'; 2 | 3 | @freezed 4 | class GuestState with _$GuestState { 5 | const factory GuestState.initial() = _Initial; 6 | } 7 | -------------------------------------------------------------------------------- /lib/enums/data_status.dart: -------------------------------------------------------------------------------- 1 | enum DataStatus { 2 | initial, 3 | fetching, 4 | loading, 5 | loaded, 6 | refreshing, 7 | submitting, 8 | deleting, 9 | success, 10 | error, 11 | loadingMore, 12 | updating; 13 | 14 | bool get isLoading => this == DataStatus.loading; 15 | bool get isFetching => this == DataStatus.fetching; 16 | bool get isLoaded => this == DataStatus.loaded; 17 | bool get isRefreshing => this == DataStatus.refreshing; 18 | bool get isSubmitting => this == DataStatus.submitting; 19 | bool get isDeleting => this == DataStatus.deleting; 20 | bool get isUpdating => this == DataStatus.updating; 21 | bool get isError => this == DataStatus.error; 22 | bool get isSuccess => this == DataStatus.success; 23 | bool get isInitial => this == DataStatus.initial; 24 | bool get isLoadingMore => this == DataStatus.loadingMore; 25 | } 26 | -------------------------------------------------------------------------------- /lib/enums/enums.dart: -------------------------------------------------------------------------------- 1 | export "data_status.dart"; 2 | -------------------------------------------------------------------------------- /lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:dash_chat_2/dash_chat_2.dart'; 2 | import 'package:flutter/foundation.dart'; 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_bloc/flutter_bloc.dart'; 5 | import 'package:flutter_chat_app/blocs/blocs.dart'; 6 | import 'package:flutter_chat_app/blocs/chat/chat_bloc.dart'; 7 | import 'package:flutter_chat_app/blocs/user/user_bloc.dart'; 8 | import 'package:flutter_chat_app/cubits/cubits.dart'; 9 | import 'package:flutter_chat_app/repositories/auth/auth_repository.dart'; 10 | import 'package:flutter_chat_app/repositories/chat/chat_respository.dart'; 11 | import 'package:flutter_chat_app/repositories/chat_message/chat_message_repository.dart'; 12 | import 'package:flutter_chat_app/repositories/user/user_repository.dart'; 13 | import 'package:flutter_chat_app/screens/chat/chat_screen.dart'; 14 | import 'package:flutter_chat_app/screens/guest/guest_screen.dart'; 15 | import 'package:flutter_chat_app/screens/screens.dart'; 16 | import 'package:flutter_chat_app/screens/splash/splash_screen.dart'; 17 | import 'package:hydrated_bloc/hydrated_bloc.dart'; 18 | import 'package:path_provider/path_provider.dart'; 19 | 20 | void main() async { 21 | WidgetsFlutterBinding.ensureInitialized(); 22 | HydratedBloc.storage = await HydratedStorage.build( 23 | storageDirectory: kIsWeb 24 | ? HydratedStorage.webStorageDirectory 25 | : await getTemporaryDirectory(), 26 | ); 27 | runApp(const MyApp()); 28 | } 29 | 30 | class MyApp extends StatelessWidget { 31 | const MyApp({super.key}); 32 | 33 | // This widget is the root of your application. 34 | @override 35 | Widget build(BuildContext context) { 36 | return MultiRepositoryProvider( 37 | providers: [ 38 | RepositoryProvider( 39 | create: (_) => AuthRepository(), 40 | ), 41 | RepositoryProvider( 42 | create: (_) => ChatRepository(), 43 | ), 44 | RepositoryProvider( 45 | create: (_) => ChatMessageRepository(), 46 | ), 47 | RepositoryProvider( 48 | create: (_) => UserRepository(), 49 | ), 50 | ], 51 | child: MultiBlocProvider( 52 | providers: [ 53 | BlocProvider(create: (_) => AuthBloc()), 54 | BlocProvider( 55 | create: (context) => GuestCubit( 56 | authRepository: context.read(), 57 | authBloc: context.read(), 58 | ), 59 | ), 60 | BlocProvider( 61 | create: (context) => ChatBloc( 62 | chatRepository: context.read(), 63 | chatMessageRepository: context.read(), 64 | ), 65 | ), 66 | BlocProvider( 67 | create: (context) => 68 | UserBloc(userRepository: context.read()), 69 | ), 70 | ], 71 | child: MaterialApp( 72 | debugShowCheckedModeBanner: false, 73 | title: 'Chat App', 74 | theme: ThemeData( 75 | primarySwatch: Colors.blue, 76 | ), 77 | initialRoute: SplashScreen.routeName, 78 | routes: { 79 | SplashScreen.routeName: (_) => const SplashScreen(), 80 | GuestScreen.routeName: (_) => const GuestScreen(), 81 | ChatListScreen.routeName: (_) => const ChatListScreen(), 82 | ChatScreen.routeName: (_) => const ChatScreen(), 83 | }, 84 | ), 85 | ), 86 | ); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /lib/models/app_response.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | import 'package:json_annotation/json_annotation.dart'; 3 | 4 | part 'app_response.g.dart'; 5 | 6 | @JsonSerializable(explicitToJson: true, genericArgumentFactories: true) 7 | class AppResponse extends Equatable { 8 | /// The boolean indicates the AppResponse is success or failed 9 | final bool success; 10 | 11 | /// The message of AppResponse description 12 | final String message; 13 | 14 | /// The AppResponse data 15 | final T? data; 16 | 17 | /// StatusCode added by response status code (Not from server) 18 | final int statusCode; 19 | 20 | /// statusMessage added by http response (Not from server) 21 | final String statusMessage; 22 | 23 | const AppResponse._({ 24 | required this.success, 25 | required this.message, 26 | required this.statusCode, 27 | required this.statusMessage, 28 | this.data, 29 | }); 30 | 31 | factory AppResponse({ 32 | required bool success, 33 | required String message, 34 | int? statusCode, 35 | String? statusMessage, 36 | T? data, 37 | }) { 38 | return AppResponse._( 39 | success: success, 40 | message: message, 41 | statusCode: statusCode ?? 200, 42 | statusMessage: statusMessage ?? "The request has succeeded.", 43 | data: data, 44 | ); 45 | } 46 | 47 | @override 48 | List get props { 49 | return [ 50 | success, 51 | message, 52 | data ?? "", 53 | ]; 54 | } 55 | 56 | factory AppResponse.fromJson( 57 | Map json, 58 | T Function(Object? json) fromJsonT, 59 | ) { 60 | return _$AppResponseFromJson(json, fromJsonT); 61 | } 62 | 63 | Map toJson( 64 | Object? Function(T? value) toJsonT, 65 | ) { 66 | return _$AppResponseToJson(this, toJsonT); 67 | } 68 | 69 | @override 70 | bool get stringify => true; 71 | } 72 | -------------------------------------------------------------------------------- /lib/models/app_response.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'app_response.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | AppResponse _$AppResponseFromJson( 10 | Map json, 11 | T Function(Object? json) fromJsonT, 12 | ) => 13 | AppResponse( 14 | success: json['success'] as bool, 15 | message: json['message'] as String, 16 | statusCode: json['statusCode'] as int?, 17 | statusMessage: json['statusMessage'] as String?, 18 | data: _$nullableGenericFromJson(json['data'], fromJsonT), 19 | ); 20 | 21 | Map _$AppResponseToJson( 22 | AppResponse instance, 23 | Object? Function(T value) toJsonT, 24 | ) => 25 | { 26 | 'success': instance.success, 27 | 'message': instance.message, 28 | 'data': _$nullableGenericToJson(instance.data, toJsonT), 29 | 'statusCode': instance.statusCode, 30 | 'statusMessage': instance.statusMessage, 31 | }; 32 | 33 | T? _$nullableGenericFromJson( 34 | Object? input, 35 | T Function(Object? json) fromJson, 36 | ) => 37 | input == null ? null : fromJson(input); 38 | 39 | Object? _$nullableGenericToJson( 40 | T? input, 41 | Object? Function(T value) toJson, 42 | ) => 43 | input == null ? null : toJson(input); 44 | -------------------------------------------------------------------------------- /lib/models/chat_message_model.dart: -------------------------------------------------------------------------------- 1 | import 'package:freezed_annotation/freezed_annotation.dart'; 2 | import 'package:dash_chat_2/dash_chat_2.dart'; 3 | import 'package:flutter_chat_app/models/user_model.dart'; 4 | import 'package:flutter_chat_app/utils/utils.dart'; 5 | 6 | part 'chat_message_model.freezed.dart'; 7 | part 'chat_message_model.g.dart'; 8 | 9 | @freezed 10 | class ChatMessageEntity with _$ChatMessageEntity { 11 | const ChatMessageEntity._(); 12 | 13 | factory ChatMessageEntity({ 14 | required int id, 15 | @JsonKey(name: "chat_id") required int chatId, 16 | @JsonKey(name: "user_id") required int userId, 17 | required String message, 18 | @JsonKey(name: "created_at") required String createdAt, 19 | @JsonKey(name: "updated_at") required String updatedAt, 20 | required UserEntity user, 21 | }) = _ChatMessageEntity; 22 | 23 | factory ChatMessageEntity.fromJson(Map json) => 24 | _$ChatMessageEntityFromJson(json); 25 | 26 | ChatMessage get toChatMessage { 27 | return ChatMessage( 28 | user: user.toChatUser, 29 | text: message, 30 | createdAt: parseDateTime(createdAt), 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/models/chat_message_model.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'chat_message_model.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | _$_ChatMessageEntity _$$_ChatMessageEntityFromJson(Map json) => 10 | _$_ChatMessageEntity( 11 | id: json['id'] as int, 12 | chatId: json['chat_id'] as int, 13 | userId: json['user_id'] as int, 14 | message: json['message'] as String, 15 | createdAt: json['created_at'] as String, 16 | updatedAt: json['updated_at'] as String, 17 | user: UserEntity.fromJson(json['user'] as Map), 18 | ); 19 | 20 | Map _$$_ChatMessageEntityToJson( 21 | _$_ChatMessageEntity instance) => 22 | { 23 | 'id': instance.id, 24 | 'chat_id': instance.chatId, 25 | 'user_id': instance.userId, 26 | 'message': instance.message, 27 | 'created_at': instance.createdAt, 28 | 'updated_at': instance.updatedAt, 29 | 'user': instance.user, 30 | }; 31 | -------------------------------------------------------------------------------- /lib/models/chat_model.dart: -------------------------------------------------------------------------------- 1 | import 'package:freezed_annotation/freezed_annotation.dart'; 2 | import 'package:flutter_chat_app/models/chat_message_model.dart'; 3 | import 'package:flutter_chat_app/models/chat_participant_model.dart'; 4 | 5 | part 'chat_model.freezed.dart'; 6 | part 'chat_model.g.dart'; 7 | 8 | @freezed 9 | class ChatEntity with _$ChatEntity { 10 | factory ChatEntity({ 11 | required int id, 12 | String? name, 13 | @JsonKey(name: "is_private") required int isPrivate, 14 | @JsonKey(name: "created_at") required String createdAt, 15 | @JsonKey(name: "updated_at") required String updatedAt, 16 | @JsonKey(name: "last_message") ChatMessageEntity? lastMessage, 17 | required List participants, 18 | }) = _ChatEntity; 19 | 20 | factory ChatEntity.fromJson(Map json) => 21 | _$ChatEntityFromJson(json); 22 | } 23 | -------------------------------------------------------------------------------- /lib/models/chat_model.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'chat_model.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | _$_ChatEntity _$$_ChatEntityFromJson(Map json) => 10 | _$_ChatEntity( 11 | id: json['id'] as int, 12 | name: json['name'] as String?, 13 | isPrivate: json['is_private'] as int, 14 | createdAt: json['created_at'] as String, 15 | updatedAt: json['updated_at'] as String, 16 | lastMessage: json['last_message'] == null 17 | ? null 18 | : ChatMessageEntity.fromJson( 19 | json['last_message'] as Map), 20 | participants: (json['participants'] as List) 21 | .map((e) => ChatParticipantEntity.fromJson(e as Map)) 22 | .toList(), 23 | ); 24 | 25 | Map _$$_ChatEntityToJson(_$_ChatEntity instance) => 26 | { 27 | 'id': instance.id, 28 | 'name': instance.name, 29 | 'is_private': instance.isPrivate, 30 | 'created_at': instance.createdAt, 31 | 'updated_at': instance.updatedAt, 32 | 'last_message': instance.lastMessage, 33 | 'participants': instance.participants, 34 | }; 35 | -------------------------------------------------------------------------------- /lib/models/chat_participant_model.dart: -------------------------------------------------------------------------------- 1 | import 'package:freezed_annotation/freezed_annotation.dart'; 2 | import 'package:flutter_chat_app/models/user_model.dart'; 3 | 4 | part 'chat_participant_model.freezed.dart'; 5 | part 'chat_participant_model.g.dart'; 6 | 7 | @freezed 8 | class ChatParticipantEntity with _$ChatParticipantEntity { 9 | factory ChatParticipantEntity({ 10 | required int id, 11 | @JsonKey(name: "chat_id") required int chatId, 12 | @JsonKey(name: "user_id") required int userId, 13 | required UserEntity user, 14 | }) = _ChatParticipantEntity; 15 | 16 | factory ChatParticipantEntity.fromJson(Map json) => 17 | _$ChatParticipantEntityFromJson(json); 18 | } 19 | -------------------------------------------------------------------------------- /lib/models/chat_participant_model.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'chat_participant_model.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | _$_ChatParticipantEntity _$$_ChatParticipantEntityFromJson( 10 | Map json) => 11 | _$_ChatParticipantEntity( 12 | id: json['id'] as int, 13 | chatId: json['chat_id'] as int, 14 | userId: json['user_id'] as int, 15 | user: UserEntity.fromJson(json['user'] as Map), 16 | ); 17 | 18 | Map _$$_ChatParticipantEntityToJson( 19 | _$_ChatParticipantEntity instance) => 20 | { 21 | 'id': instance.id, 22 | 'chat_id': instance.chatId, 23 | 'user_id': instance.userId, 24 | 'user': instance.user, 25 | }; 26 | -------------------------------------------------------------------------------- /lib/models/models.dart: -------------------------------------------------------------------------------- 1 | export "app_response.dart"; 2 | export "chat_message_model.dart"; 3 | export "chat_participant_model.dart"; 4 | export "chat_model.dart"; 5 | export "user_model.dart"; 6 | -------------------------------------------------------------------------------- /lib/models/requests/create_chat_message_request.dart: -------------------------------------------------------------------------------- 1 | import 'package:freezed_annotation/freezed_annotation.dart'; 2 | 3 | part 'create_chat_message_request.freezed.dart'; 4 | part 'create_chat_message_request.g.dart'; 5 | 6 | @freezed 7 | class CreateChatMessageRequest with _$CreateChatMessageRequest { 8 | factory CreateChatMessageRequest({ 9 | @JsonKey(name: "chat_id") required int chatId, 10 | required String message, 11 | }) = _CreateChatMessageRequest; 12 | 13 | factory CreateChatMessageRequest.fromJson(Map json) => 14 | _$CreateChatMessageRequestFromJson(json); 15 | } 16 | -------------------------------------------------------------------------------- /lib/models/requests/create_chat_message_request.freezed.dart: -------------------------------------------------------------------------------- 1 | // coverage:ignore-file 2 | // GENERATED CODE - DO NOT MODIFY BY HAND 3 | // ignore_for_file: type=lint 4 | // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target 5 | 6 | part of 'create_chat_message_request.dart'; 7 | 8 | // ************************************************************************** 9 | // FreezedGenerator 10 | // ************************************************************************** 11 | 12 | T _$identity(T value) => value; 13 | 14 | final _privateConstructorUsedError = UnsupportedError( 15 | 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); 16 | 17 | CreateChatMessageRequest _$CreateChatMessageRequestFromJson( 18 | Map json) { 19 | return _CreateChatMessageRequest.fromJson(json); 20 | } 21 | 22 | /// @nodoc 23 | mixin _$CreateChatMessageRequest { 24 | @JsonKey(name: "chat_id") 25 | int get chatId => throw _privateConstructorUsedError; 26 | String get message => throw _privateConstructorUsedError; 27 | 28 | Map toJson() => throw _privateConstructorUsedError; 29 | @JsonKey(ignore: true) 30 | $CreateChatMessageRequestCopyWith get copyWith => 31 | throw _privateConstructorUsedError; 32 | } 33 | 34 | /// @nodoc 35 | abstract class $CreateChatMessageRequestCopyWith<$Res> { 36 | factory $CreateChatMessageRequestCopyWith(CreateChatMessageRequest value, 37 | $Res Function(CreateChatMessageRequest) then) = 38 | _$CreateChatMessageRequestCopyWithImpl<$Res>; 39 | $Res call({@JsonKey(name: "chat_id") int chatId, String message}); 40 | } 41 | 42 | /// @nodoc 43 | class _$CreateChatMessageRequestCopyWithImpl<$Res> 44 | implements $CreateChatMessageRequestCopyWith<$Res> { 45 | _$CreateChatMessageRequestCopyWithImpl(this._value, this._then); 46 | 47 | final CreateChatMessageRequest _value; 48 | // ignore: unused_field 49 | final $Res Function(CreateChatMessageRequest) _then; 50 | 51 | @override 52 | $Res call({ 53 | Object? chatId = freezed, 54 | Object? message = freezed, 55 | }) { 56 | return _then(_value.copyWith( 57 | chatId: chatId == freezed 58 | ? _value.chatId 59 | : chatId // ignore: cast_nullable_to_non_nullable 60 | as int, 61 | message: message == freezed 62 | ? _value.message 63 | : message // ignore: cast_nullable_to_non_nullable 64 | as String, 65 | )); 66 | } 67 | } 68 | 69 | /// @nodoc 70 | abstract class _$$_CreateChatMessageRequestCopyWith<$Res> 71 | implements $CreateChatMessageRequestCopyWith<$Res> { 72 | factory _$$_CreateChatMessageRequestCopyWith( 73 | _$_CreateChatMessageRequest value, 74 | $Res Function(_$_CreateChatMessageRequest) then) = 75 | __$$_CreateChatMessageRequestCopyWithImpl<$Res>; 76 | @override 77 | $Res call({@JsonKey(name: "chat_id") int chatId, String message}); 78 | } 79 | 80 | /// @nodoc 81 | class __$$_CreateChatMessageRequestCopyWithImpl<$Res> 82 | extends _$CreateChatMessageRequestCopyWithImpl<$Res> 83 | implements _$$_CreateChatMessageRequestCopyWith<$Res> { 84 | __$$_CreateChatMessageRequestCopyWithImpl(_$_CreateChatMessageRequest _value, 85 | $Res Function(_$_CreateChatMessageRequest) _then) 86 | : super(_value, (v) => _then(v as _$_CreateChatMessageRequest)); 87 | 88 | @override 89 | _$_CreateChatMessageRequest get _value => 90 | super._value as _$_CreateChatMessageRequest; 91 | 92 | @override 93 | $Res call({ 94 | Object? chatId = freezed, 95 | Object? message = freezed, 96 | }) { 97 | return _then(_$_CreateChatMessageRequest( 98 | chatId: chatId == freezed 99 | ? _value.chatId 100 | : chatId // ignore: cast_nullable_to_non_nullable 101 | as int, 102 | message: message == freezed 103 | ? _value.message 104 | : message // ignore: cast_nullable_to_non_nullable 105 | as String, 106 | )); 107 | } 108 | } 109 | 110 | /// @nodoc 111 | @JsonSerializable() 112 | class _$_CreateChatMessageRequest implements _CreateChatMessageRequest { 113 | _$_CreateChatMessageRequest( 114 | {@JsonKey(name: "chat_id") required this.chatId, required this.message}); 115 | 116 | factory _$_CreateChatMessageRequest.fromJson(Map json) => 117 | _$$_CreateChatMessageRequestFromJson(json); 118 | 119 | @override 120 | @JsonKey(name: "chat_id") 121 | final int chatId; 122 | @override 123 | final String message; 124 | 125 | @override 126 | String toString() { 127 | return 'CreateChatMessageRequest(chatId: $chatId, message: $message)'; 128 | } 129 | 130 | @override 131 | bool operator ==(dynamic other) { 132 | return identical(this, other) || 133 | (other.runtimeType == runtimeType && 134 | other is _$_CreateChatMessageRequest && 135 | const DeepCollectionEquality().equals(other.chatId, chatId) && 136 | const DeepCollectionEquality().equals(other.message, message)); 137 | } 138 | 139 | @JsonKey(ignore: true) 140 | @override 141 | int get hashCode => Object.hash( 142 | runtimeType, 143 | const DeepCollectionEquality().hash(chatId), 144 | const DeepCollectionEquality().hash(message)); 145 | 146 | @JsonKey(ignore: true) 147 | @override 148 | _$$_CreateChatMessageRequestCopyWith<_$_CreateChatMessageRequest> 149 | get copyWith => __$$_CreateChatMessageRequestCopyWithImpl< 150 | _$_CreateChatMessageRequest>(this, _$identity); 151 | 152 | @override 153 | Map toJson() { 154 | return _$$_CreateChatMessageRequestToJson( 155 | this, 156 | ); 157 | } 158 | } 159 | 160 | abstract class _CreateChatMessageRequest implements CreateChatMessageRequest { 161 | factory _CreateChatMessageRequest( 162 | {@JsonKey(name: "chat_id") required final int chatId, 163 | required final String message}) = _$_CreateChatMessageRequest; 164 | 165 | factory _CreateChatMessageRequest.fromJson(Map json) = 166 | _$_CreateChatMessageRequest.fromJson; 167 | 168 | @override 169 | @JsonKey(name: "chat_id") 170 | int get chatId; 171 | @override 172 | String get message; 173 | @override 174 | @JsonKey(ignore: true) 175 | _$$_CreateChatMessageRequestCopyWith<_$_CreateChatMessageRequest> 176 | get copyWith => throw _privateConstructorUsedError; 177 | } 178 | -------------------------------------------------------------------------------- /lib/models/requests/create_chat_message_request.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'create_chat_message_request.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | _$_CreateChatMessageRequest _$$_CreateChatMessageRequestFromJson( 10 | Map json) => 11 | _$_CreateChatMessageRequest( 12 | chatId: json['chat_id'] as int, 13 | message: json['message'] as String, 14 | ); 15 | 16 | Map _$$_CreateChatMessageRequestToJson( 17 | _$_CreateChatMessageRequest instance) => 18 | { 19 | 'chat_id': instance.chatId, 20 | 'message': instance.message, 21 | }; 22 | -------------------------------------------------------------------------------- /lib/models/requests/create_chat_request.dart: -------------------------------------------------------------------------------- 1 | import 'package:freezed_annotation/freezed_annotation.dart'; 2 | 3 | part 'create_chat_request.freezed.dart'; 4 | part 'create_chat_request.g.dart'; 5 | 6 | @freezed 7 | class CreateChatRequest with _$CreateChatRequest { 8 | factory CreateChatRequest({ 9 | @JsonKey(name: "user_id") required int userId, 10 | @JsonKey(name: "is_private") @Default(1) int? isPrivate, 11 | String? name, 12 | }) = _CreateChatRequest; 13 | 14 | factory CreateChatRequest.fromJson(Map json) => 15 | _$CreateChatRequestFromJson(json); 16 | } 17 | -------------------------------------------------------------------------------- /lib/models/requests/create_chat_request.freezed.dart: -------------------------------------------------------------------------------- 1 | // coverage:ignore-file 2 | // GENERATED CODE - DO NOT MODIFY BY HAND 3 | // ignore_for_file: type=lint 4 | // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target 5 | 6 | part of 'create_chat_request.dart'; 7 | 8 | // ************************************************************************** 9 | // FreezedGenerator 10 | // ************************************************************************** 11 | 12 | T _$identity(T value) => value; 13 | 14 | final _privateConstructorUsedError = UnsupportedError( 15 | 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); 16 | 17 | CreateChatRequest _$CreateChatRequestFromJson(Map json) { 18 | return _CreateChatRequest.fromJson(json); 19 | } 20 | 21 | /// @nodoc 22 | mixin _$CreateChatRequest { 23 | @JsonKey(name: "user_id") 24 | int get userId => throw _privateConstructorUsedError; 25 | @JsonKey(name: "is_private") 26 | int? get isPrivate => throw _privateConstructorUsedError; 27 | String? get name => throw _privateConstructorUsedError; 28 | 29 | Map toJson() => throw _privateConstructorUsedError; 30 | @JsonKey(ignore: true) 31 | $CreateChatRequestCopyWith get copyWith => 32 | throw _privateConstructorUsedError; 33 | } 34 | 35 | /// @nodoc 36 | abstract class $CreateChatRequestCopyWith<$Res> { 37 | factory $CreateChatRequestCopyWith( 38 | CreateChatRequest value, $Res Function(CreateChatRequest) then) = 39 | _$CreateChatRequestCopyWithImpl<$Res>; 40 | $Res call( 41 | {@JsonKey(name: "user_id") int userId, 42 | @JsonKey(name: "is_private") int? isPrivate, 43 | String? name}); 44 | } 45 | 46 | /// @nodoc 47 | class _$CreateChatRequestCopyWithImpl<$Res> 48 | implements $CreateChatRequestCopyWith<$Res> { 49 | _$CreateChatRequestCopyWithImpl(this._value, this._then); 50 | 51 | final CreateChatRequest _value; 52 | // ignore: unused_field 53 | final $Res Function(CreateChatRequest) _then; 54 | 55 | @override 56 | $Res call({ 57 | Object? userId = freezed, 58 | Object? isPrivate = freezed, 59 | Object? name = freezed, 60 | }) { 61 | return _then(_value.copyWith( 62 | userId: userId == freezed 63 | ? _value.userId 64 | : userId // ignore: cast_nullable_to_non_nullable 65 | as int, 66 | isPrivate: isPrivate == freezed 67 | ? _value.isPrivate 68 | : isPrivate // ignore: cast_nullable_to_non_nullable 69 | as int?, 70 | name: name == freezed 71 | ? _value.name 72 | : name // ignore: cast_nullable_to_non_nullable 73 | as String?, 74 | )); 75 | } 76 | } 77 | 78 | /// @nodoc 79 | abstract class _$$_CreateChatRequestCopyWith<$Res> 80 | implements $CreateChatRequestCopyWith<$Res> { 81 | factory _$$_CreateChatRequestCopyWith(_$_CreateChatRequest value, 82 | $Res Function(_$_CreateChatRequest) then) = 83 | __$$_CreateChatRequestCopyWithImpl<$Res>; 84 | @override 85 | $Res call( 86 | {@JsonKey(name: "user_id") int userId, 87 | @JsonKey(name: "is_private") int? isPrivate, 88 | String? name}); 89 | } 90 | 91 | /// @nodoc 92 | class __$$_CreateChatRequestCopyWithImpl<$Res> 93 | extends _$CreateChatRequestCopyWithImpl<$Res> 94 | implements _$$_CreateChatRequestCopyWith<$Res> { 95 | __$$_CreateChatRequestCopyWithImpl( 96 | _$_CreateChatRequest _value, $Res Function(_$_CreateChatRequest) _then) 97 | : super(_value, (v) => _then(v as _$_CreateChatRequest)); 98 | 99 | @override 100 | _$_CreateChatRequest get _value => super._value as _$_CreateChatRequest; 101 | 102 | @override 103 | $Res call({ 104 | Object? userId = freezed, 105 | Object? isPrivate = freezed, 106 | Object? name = freezed, 107 | }) { 108 | return _then(_$_CreateChatRequest( 109 | userId: userId == freezed 110 | ? _value.userId 111 | : userId // ignore: cast_nullable_to_non_nullable 112 | as int, 113 | isPrivate: isPrivate == freezed 114 | ? _value.isPrivate 115 | : isPrivate // ignore: cast_nullable_to_non_nullable 116 | as int?, 117 | name: name == freezed 118 | ? _value.name 119 | : name // ignore: cast_nullable_to_non_nullable 120 | as String?, 121 | )); 122 | } 123 | } 124 | 125 | /// @nodoc 126 | @JsonSerializable() 127 | class _$_CreateChatRequest implements _CreateChatRequest { 128 | _$_CreateChatRequest( 129 | {@JsonKey(name: "user_id") required this.userId, 130 | @JsonKey(name: "is_private") this.isPrivate = 1, 131 | this.name}); 132 | 133 | factory _$_CreateChatRequest.fromJson(Map json) => 134 | _$$_CreateChatRequestFromJson(json); 135 | 136 | @override 137 | @JsonKey(name: "user_id") 138 | final int userId; 139 | @override 140 | @JsonKey(name: "is_private") 141 | final int? isPrivate; 142 | @override 143 | final String? name; 144 | 145 | @override 146 | String toString() { 147 | return 'CreateChatRequest(userId: $userId, isPrivate: $isPrivate, name: $name)'; 148 | } 149 | 150 | @override 151 | bool operator ==(dynamic other) { 152 | return identical(this, other) || 153 | (other.runtimeType == runtimeType && 154 | other is _$_CreateChatRequest && 155 | const DeepCollectionEquality().equals(other.userId, userId) && 156 | const DeepCollectionEquality().equals(other.isPrivate, isPrivate) && 157 | const DeepCollectionEquality().equals(other.name, name)); 158 | } 159 | 160 | @JsonKey(ignore: true) 161 | @override 162 | int get hashCode => Object.hash( 163 | runtimeType, 164 | const DeepCollectionEquality().hash(userId), 165 | const DeepCollectionEquality().hash(isPrivate), 166 | const DeepCollectionEquality().hash(name)); 167 | 168 | @JsonKey(ignore: true) 169 | @override 170 | _$$_CreateChatRequestCopyWith<_$_CreateChatRequest> get copyWith => 171 | __$$_CreateChatRequestCopyWithImpl<_$_CreateChatRequest>( 172 | this, _$identity); 173 | 174 | @override 175 | Map toJson() { 176 | return _$$_CreateChatRequestToJson( 177 | this, 178 | ); 179 | } 180 | } 181 | 182 | abstract class _CreateChatRequest implements CreateChatRequest { 183 | factory _CreateChatRequest( 184 | {@JsonKey(name: "user_id") required final int userId, 185 | @JsonKey(name: "is_private") final int? isPrivate, 186 | final String? name}) = _$_CreateChatRequest; 187 | 188 | factory _CreateChatRequest.fromJson(Map json) = 189 | _$_CreateChatRequest.fromJson; 190 | 191 | @override 192 | @JsonKey(name: "user_id") 193 | int get userId; 194 | @override 195 | @JsonKey(name: "is_private") 196 | int? get isPrivate; 197 | @override 198 | String? get name; 199 | @override 200 | @JsonKey(ignore: true) 201 | _$$_CreateChatRequestCopyWith<_$_CreateChatRequest> get copyWith => 202 | throw _privateConstructorUsedError; 203 | } 204 | -------------------------------------------------------------------------------- /lib/models/requests/create_chat_request.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'create_chat_request.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | _$_CreateChatRequest _$$_CreateChatRequestFromJson(Map json) => 10 | _$_CreateChatRequest( 11 | userId: json['user_id'] as int, 12 | isPrivate: json['is_private'] as int? ?? 1, 13 | name: json['name'] as String?, 14 | ); 15 | 16 | Map _$$_CreateChatRequestToJson( 17 | _$_CreateChatRequest instance) => 18 | { 19 | 'user_id': instance.userId, 20 | 'is_private': instance.isPrivate, 21 | 'name': instance.name, 22 | }; 23 | -------------------------------------------------------------------------------- /lib/models/requests/login_request.dart: -------------------------------------------------------------------------------- 1 | import 'package:freezed_annotation/freezed_annotation.dart'; 2 | 3 | part 'login_request.freezed.dart'; 4 | part 'login_request.g.dart'; 5 | 6 | @freezed 7 | class LoginRequest with _$LoginRequest { 8 | factory LoginRequest({ 9 | required String email, 10 | required String password, 11 | }) = _LoginRequest; 12 | 13 | factory LoginRequest.fromJson(Map json) => 14 | _$LoginRequestFromJson(json); 15 | } 16 | -------------------------------------------------------------------------------- /lib/models/requests/login_request.freezed.dart: -------------------------------------------------------------------------------- 1 | // coverage:ignore-file 2 | // GENERATED CODE - DO NOT MODIFY BY HAND 3 | // ignore_for_file: type=lint 4 | // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target 5 | 6 | part of 'login_request.dart'; 7 | 8 | // ************************************************************************** 9 | // FreezedGenerator 10 | // ************************************************************************** 11 | 12 | T _$identity(T value) => value; 13 | 14 | final _privateConstructorUsedError = UnsupportedError( 15 | 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); 16 | 17 | LoginRequest _$LoginRequestFromJson(Map json) { 18 | return _LoginRequest.fromJson(json); 19 | } 20 | 21 | /// @nodoc 22 | mixin _$LoginRequest { 23 | String get email => throw _privateConstructorUsedError; 24 | String get password => throw _privateConstructorUsedError; 25 | 26 | Map toJson() => throw _privateConstructorUsedError; 27 | @JsonKey(ignore: true) 28 | $LoginRequestCopyWith get copyWith => 29 | throw _privateConstructorUsedError; 30 | } 31 | 32 | /// @nodoc 33 | abstract class $LoginRequestCopyWith<$Res> { 34 | factory $LoginRequestCopyWith( 35 | LoginRequest value, $Res Function(LoginRequest) then) = 36 | _$LoginRequestCopyWithImpl<$Res>; 37 | $Res call({String email, String password}); 38 | } 39 | 40 | /// @nodoc 41 | class _$LoginRequestCopyWithImpl<$Res> implements $LoginRequestCopyWith<$Res> { 42 | _$LoginRequestCopyWithImpl(this._value, this._then); 43 | 44 | final LoginRequest _value; 45 | // ignore: unused_field 46 | final $Res Function(LoginRequest) _then; 47 | 48 | @override 49 | $Res call({ 50 | Object? email = freezed, 51 | Object? password = freezed, 52 | }) { 53 | return _then(_value.copyWith( 54 | email: email == freezed 55 | ? _value.email 56 | : email // ignore: cast_nullable_to_non_nullable 57 | as String, 58 | password: password == freezed 59 | ? _value.password 60 | : password // ignore: cast_nullable_to_non_nullable 61 | as String, 62 | )); 63 | } 64 | } 65 | 66 | /// @nodoc 67 | abstract class _$$_LoginRequestCopyWith<$Res> 68 | implements $LoginRequestCopyWith<$Res> { 69 | factory _$$_LoginRequestCopyWith( 70 | _$_LoginRequest value, $Res Function(_$_LoginRequest) then) = 71 | __$$_LoginRequestCopyWithImpl<$Res>; 72 | @override 73 | $Res call({String email, String password}); 74 | } 75 | 76 | /// @nodoc 77 | class __$$_LoginRequestCopyWithImpl<$Res> 78 | extends _$LoginRequestCopyWithImpl<$Res> 79 | implements _$$_LoginRequestCopyWith<$Res> { 80 | __$$_LoginRequestCopyWithImpl( 81 | _$_LoginRequest _value, $Res Function(_$_LoginRequest) _then) 82 | : super(_value, (v) => _then(v as _$_LoginRequest)); 83 | 84 | @override 85 | _$_LoginRequest get _value => super._value as _$_LoginRequest; 86 | 87 | @override 88 | $Res call({ 89 | Object? email = freezed, 90 | Object? password = freezed, 91 | }) { 92 | return _then(_$_LoginRequest( 93 | email: email == freezed 94 | ? _value.email 95 | : email // ignore: cast_nullable_to_non_nullable 96 | as String, 97 | password: password == freezed 98 | ? _value.password 99 | : password // ignore: cast_nullable_to_non_nullable 100 | as String, 101 | )); 102 | } 103 | } 104 | 105 | /// @nodoc 106 | @JsonSerializable() 107 | class _$_LoginRequest implements _LoginRequest { 108 | _$_LoginRequest({required this.email, required this.password}); 109 | 110 | factory _$_LoginRequest.fromJson(Map json) => 111 | _$$_LoginRequestFromJson(json); 112 | 113 | @override 114 | final String email; 115 | @override 116 | final String password; 117 | 118 | @override 119 | String toString() { 120 | return 'LoginRequest(email: $email, password: $password)'; 121 | } 122 | 123 | @override 124 | bool operator ==(dynamic other) { 125 | return identical(this, other) || 126 | (other.runtimeType == runtimeType && 127 | other is _$_LoginRequest && 128 | const DeepCollectionEquality().equals(other.email, email) && 129 | const DeepCollectionEquality().equals(other.password, password)); 130 | } 131 | 132 | @JsonKey(ignore: true) 133 | @override 134 | int get hashCode => Object.hash( 135 | runtimeType, 136 | const DeepCollectionEquality().hash(email), 137 | const DeepCollectionEquality().hash(password)); 138 | 139 | @JsonKey(ignore: true) 140 | @override 141 | _$$_LoginRequestCopyWith<_$_LoginRequest> get copyWith => 142 | __$$_LoginRequestCopyWithImpl<_$_LoginRequest>(this, _$identity); 143 | 144 | @override 145 | Map toJson() { 146 | return _$$_LoginRequestToJson( 147 | this, 148 | ); 149 | } 150 | } 151 | 152 | abstract class _LoginRequest implements LoginRequest { 153 | factory _LoginRequest( 154 | {required final String email, 155 | required final String password}) = _$_LoginRequest; 156 | 157 | factory _LoginRequest.fromJson(Map json) = 158 | _$_LoginRequest.fromJson; 159 | 160 | @override 161 | String get email; 162 | @override 163 | String get password; 164 | @override 165 | @JsonKey(ignore: true) 166 | _$$_LoginRequestCopyWith<_$_LoginRequest> get copyWith => 167 | throw _privateConstructorUsedError; 168 | } 169 | -------------------------------------------------------------------------------- /lib/models/requests/login_request.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'login_request.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | _$_LoginRequest _$$_LoginRequestFromJson(Map json) => 10 | _$_LoginRequest( 11 | email: json['email'] as String, 12 | password: json['password'] as String, 13 | ); 14 | 15 | Map _$$_LoginRequestToJson(_$_LoginRequest instance) => 16 | { 17 | 'email': instance.email, 18 | 'password': instance.password, 19 | }; 20 | -------------------------------------------------------------------------------- /lib/models/requests/register_request.dart: -------------------------------------------------------------------------------- 1 | import 'package:freezed_annotation/freezed_annotation.dart'; 2 | 3 | part 'register_request.freezed.dart'; 4 | part 'register_request.g.dart'; 5 | 6 | @freezed 7 | class RegisterRequest with _$RegisterRequest { 8 | factory RegisterRequest({ 9 | required String email, 10 | required String password, 11 | @JsonKey(name: "password_confirmation") 12 | required String passwordConfirmation, 13 | }) = _RegisterRequest; 14 | 15 | factory RegisterRequest.fromJson(Map json) => 16 | _$RegisterRequestFromJson(json); 17 | } 18 | -------------------------------------------------------------------------------- /lib/models/requests/register_request.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'register_request.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | _$_RegisterRequest _$$_RegisterRequestFromJson(Map json) => 10 | _$_RegisterRequest( 11 | email: json['email'] as String, 12 | password: json['password'] as String, 13 | passwordConfirmation: json['password_confirmation'] as String, 14 | ); 15 | 16 | Map _$$_RegisterRequestToJson(_$_RegisterRequest instance) => 17 | { 18 | 'email': instance.email, 19 | 'password': instance.password, 20 | 'password_confirmation': instance.passwordConfirmation, 21 | }; 22 | -------------------------------------------------------------------------------- /lib/models/requests/requests.dart: -------------------------------------------------------------------------------- 1 | export "login_request.dart"; 2 | export "register_request.dart"; 3 | export "create_chat_request.dart"; 4 | export "create_chat_message_request.dart"; 5 | -------------------------------------------------------------------------------- /lib/models/user_model.dart: -------------------------------------------------------------------------------- 1 | import 'package:freezed_annotation/freezed_annotation.dart'; 2 | import 'package:dash_chat_2/dash_chat_2.dart'; 3 | 4 | part 'user_model.freezed.dart'; 5 | part 'user_model.g.dart'; 6 | 7 | @freezed 8 | class UserEntity with _$UserEntity { 9 | const UserEntity._(); 10 | 11 | factory UserEntity({ 12 | required int id, 13 | required String email, 14 | required String username, 15 | }) = _UserEntity; 16 | 17 | factory UserEntity.fromJson(Map json) => 18 | _$UserEntityFromJson(json); 19 | 20 | ChatUser get toChatUser { 21 | return ChatUser( 22 | id: id.toString(), 23 | firstName: username, 24 | ); 25 | } 26 | } 27 | 28 | @freezed 29 | class AuthUser with _$AuthUser { 30 | factory AuthUser({ 31 | required UserEntity user, 32 | required String token, 33 | }) = _AuthUser; 34 | 35 | factory AuthUser.fromJson(Map json) => 36 | _$AuthUserFromJson(json); 37 | } 38 | -------------------------------------------------------------------------------- /lib/models/user_model.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'user_model.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | _$_UserEntity _$$_UserEntityFromJson(Map json) => 10 | _$_UserEntity( 11 | id: json['id'] as int, 12 | email: json['email'] as String, 13 | username: json['username'] as String, 14 | ); 15 | 16 | Map _$$_UserEntityToJson(_$_UserEntity instance) => 17 | { 18 | 'id': instance.id, 19 | 'email': instance.email, 20 | 'username': instance.username, 21 | }; 22 | 23 | _$_AuthUser _$$_AuthUserFromJson(Map json) => _$_AuthUser( 24 | user: UserEntity.fromJson(json['user'] as Map), 25 | token: json['token'] as String, 26 | ); 27 | 28 | Map _$$_AuthUserToJson(_$_AuthUser instance) => 29 | { 30 | 'user': instance.user, 31 | 'token': instance.token, 32 | }; 33 | -------------------------------------------------------------------------------- /lib/repositories/auth/auth_repository.dart: -------------------------------------------------------------------------------- 1 | import 'package:dio/dio.dart'; 2 | import 'package:flutter_chat_app/models/user_model.dart'; 3 | import 'package:flutter_chat_app/models/requests/register_request.dart'; 4 | import 'package:flutter_chat_app/models/requests/login_request.dart'; 5 | import 'package:flutter_chat_app/models/app_response.dart'; 6 | import 'package:flutter_chat_app/repositories/auth/base_auth_repository.dart'; 7 | import 'package:flutter_chat_app/repositories/core/endpoints.dart'; 8 | import 'package:flutter_chat_app/utils/dio_client/dio_client.dart'; 9 | 10 | class AuthRepository extends BaseAuthRepository { 11 | AuthRepository({ 12 | Dio? dioClient, 13 | }) : _dioClient = dioClient ?? DioClient().instance; 14 | 15 | final Dio _dioClient; 16 | 17 | @override 18 | Future> login(LoginRequest request) async { 19 | final response = await _dioClient.post( 20 | Endpoints.login, 21 | data: request.toJson(), 22 | ); 23 | 24 | return AppResponse.fromJson( 25 | response.data, 26 | (dynamic json) => response.data['success'] && json != null 27 | ? AuthUser.fromJson(json) 28 | : null, 29 | ); 30 | } 31 | 32 | @override 33 | Future> loginWithToken() async { 34 | final response = await _dioClient.post( 35 | Endpoints.loginWithToken, 36 | ); 37 | 38 | return AppResponse.fromJson( 39 | response.data, 40 | (dynamic json) => response.data['success'] && json != null 41 | ? UserEntity.fromJson(json) 42 | : null, 43 | ); 44 | } 45 | 46 | @override 47 | Future logout() async { 48 | final response = await _dioClient.get( 49 | Endpoints.logout, 50 | ); 51 | 52 | return AppResponse.fromJson( 53 | response.data, 54 | (dynamic json) => null, 55 | ); 56 | } 57 | 58 | @override 59 | Future> register(RegisterRequest request) async { 60 | final response = await _dioClient.post( 61 | Endpoints.register, 62 | data: request.toJson(), 63 | ); 64 | 65 | return AppResponse.fromJson( 66 | response.data, 67 | (dynamic json) => response.data['success'] && json != null 68 | ? AuthUser.fromJson(json) 69 | : null, 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /lib/repositories/auth/base_auth_repository.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_chat_app/models/models.dart'; 2 | import 'package:flutter_chat_app/models/requests/requests.dart'; 3 | 4 | abstract class BaseAuthRepository { 5 | Future> register(RegisterRequest request); 6 | 7 | Future> login(LoginRequest request); 8 | 9 | Future> loginWithToken(); 10 | 11 | Future logout(); 12 | } 13 | -------------------------------------------------------------------------------- /lib/repositories/chat/base_chat_repository.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_chat_app/models/models.dart'; 2 | import 'package:flutter_chat_app/models/requests/requests.dart'; 3 | 4 | abstract class BaseChatRepository { 5 | Future>> getChats(); 6 | 7 | Future> createChat(CreateChatRequest request); 8 | 9 | Future> getSingleChat(int chatId); 10 | } 11 | -------------------------------------------------------------------------------- /lib/repositories/chat/chat_respository.dart: -------------------------------------------------------------------------------- 1 | import 'package:dio/dio.dart'; 2 | import 'package:flutter_chat_app/models/requests/create_chat_request.dart'; 3 | import 'package:flutter_chat_app/models/chat_model.dart'; 4 | import 'package:flutter_chat_app/models/app_response.dart'; 5 | import 'package:flutter_chat_app/repositories/chat/base_chat_repository.dart'; 6 | import 'package:flutter_chat_app/repositories/core/endpoints.dart'; 7 | import 'package:flutter_chat_app/utils/dio_client/dio_client.dart'; 8 | 9 | class ChatRepository extends BaseChatRepository { 10 | final Dio _dioClient; 11 | 12 | ChatRepository({ 13 | Dio? dioClient, 14 | }) : _dioClient = dioClient ?? DioClient().instance; 15 | 16 | @override 17 | Future> createChat(CreateChatRequest request) async { 18 | final response = 19 | await _dioClient.post(Endpoints.createChat, data: request.toJson()); 20 | 21 | return AppResponse.fromJson( 22 | response.data, 23 | (dynamic json) => response.data['success'] && json != null 24 | ? ChatEntity.fromJson(json) 25 | : null, 26 | ); 27 | } 28 | 29 | @override 30 | Future>> getChats() async { 31 | final response = await _dioClient.get(Endpoints.getChats); 32 | 33 | return AppResponse>.fromJson( 34 | response.data, 35 | (dynamic json) => response.data['success'] && json != null 36 | ? (json as List).map((e) => ChatEntity.fromJson(e)).toList() 37 | : [], 38 | ); 39 | } 40 | 41 | @override 42 | Future> getSingleChat(int chatId) async { 43 | final response = await _dioClient.get("${Endpoints.getSingleChat}$chatId"); 44 | 45 | return AppResponse.fromJson( 46 | response.data, 47 | (dynamic json) => response.data['success'] && json != null 48 | ? ChatEntity.fromJson(json) 49 | : null, 50 | ); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /lib/repositories/chat_message/base_chat_message_repository.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_chat_app/models/models.dart'; 2 | import 'package:flutter_chat_app/models/requests/requests.dart'; 3 | 4 | abstract class BaseChatMessageRepository { 5 | Future>> getChatMessages({ 6 | required int chatId, 7 | required int page, 8 | }); 9 | 10 | Future> createChatMessage( 11 | CreateChatMessageRequest request, 12 | String socketId, 13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /lib/repositories/chat_message/chat_message_repository.dart: -------------------------------------------------------------------------------- 1 | import 'package:dio/dio.dart'; 2 | import 'package:flutter_chat_app/models/requests/create_chat_message_request.dart'; 3 | import 'package:flutter_chat_app/models/chat_message_model.dart'; 4 | import 'package:flutter_chat_app/models/app_response.dart'; 5 | import 'package:flutter_chat_app/repositories/chat_message/base_chat_message_repository.dart'; 6 | import 'package:flutter_chat_app/repositories/core/endpoints.dart'; 7 | import 'package:flutter_chat_app/utils/utils.dart'; 8 | 9 | class ChatMessageRepository extends BaseChatMessageRepository { 10 | final Dio _dioClient; 11 | 12 | ChatMessageRepository({ 13 | Dio? dioClient, 14 | }) : _dioClient = dioClient ?? DioClient().instance; 15 | 16 | @override 17 | Future> createChatMessage( 18 | CreateChatMessageRequest request, 19 | String socketId, 20 | ) async { 21 | final response = await _dioClient.post( 22 | Endpoints.createChatMessage, 23 | data: request.toJson(), 24 | options: Options( 25 | headers: { 26 | 'X-Socket-ID': socketId, 27 | }, 28 | ), 29 | ); 30 | 31 | return AppResponse.fromJson( 32 | response.data, 33 | (dynamic json) => response.data['success'] && json != null 34 | ? ChatMessageEntity.fromJson(json) 35 | : null, 36 | ); 37 | } 38 | 39 | @override 40 | Future>> getChatMessages({ 41 | required int chatId, 42 | required int page, 43 | }) async { 44 | final response = await _dioClient.get( 45 | Endpoints.getChatMessages, 46 | queryParameters: { 47 | 'page': page, 48 | 'chat_id': chatId, 49 | }, 50 | ); 51 | 52 | return AppResponse>.fromJson( 53 | response.data, 54 | (dynamic json) => response.data['success'] && json != null 55 | ? (json as List) 56 | .map((e) => ChatMessageEntity.fromJson(e)) 57 | .toList() 58 | : [], 59 | ); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /lib/repositories/core/endpoints.dart: -------------------------------------------------------------------------------- 1 | class Endpoints { 2 | /// Current Api Version 3 | static const _apiVersion = "/api"; 4 | 5 | /// Auth 6 | static const _baseAuth = "$_apiVersion/auth"; 7 | 8 | static const register = "$_baseAuth/register"; 9 | static const login = "$_baseAuth/login"; 10 | static const loginWithToken = "$_baseAuth/login_with_token"; 11 | static const logout = "$_baseAuth/logout"; 12 | 13 | /// Chat 14 | static const _baseChat = "$_apiVersion/chat"; 15 | 16 | static const getChats = _baseChat; 17 | static const getSingleChat = "$_baseChat/"; 18 | static const createChat = _baseChat; 19 | 20 | /// Chat message 21 | static const _baseChatMessage = "$_apiVersion/chat_message"; 22 | 23 | static const getChatMessages = _baseChatMessage; 24 | static const createChatMessage = _baseChatMessage; 25 | 26 | /// User 27 | 28 | static const getUsers = "$_apiVersion/user"; 29 | } 30 | -------------------------------------------------------------------------------- /lib/repositories/repositories.dart: -------------------------------------------------------------------------------- 1 | export "auth/auth_repository.dart"; 2 | -------------------------------------------------------------------------------- /lib/repositories/user/base_user_repository.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_chat_app/models/models.dart'; 2 | 3 | abstract class BaseUserRepository { 4 | Future>> getUsers(); 5 | } 6 | -------------------------------------------------------------------------------- /lib/repositories/user/user_repository.dart: -------------------------------------------------------------------------------- 1 | import 'package:dio/dio.dart'; 2 | import 'package:flutter_chat_app/models/user_model.dart'; 3 | import 'package:flutter_chat_app/models/app_response.dart'; 4 | import 'package:flutter_chat_app/repositories/core/endpoints.dart'; 5 | import 'package:flutter_chat_app/repositories/user/base_user_repository.dart'; 6 | import 'package:flutter_chat_app/utils/utils.dart'; 7 | 8 | class UserRepository extends BaseUserRepository { 9 | final Dio _dioClient; 10 | 11 | UserRepository({ 12 | Dio? dioClient, 13 | }) : _dioClient = dioClient ?? DioClient().instance; 14 | 15 | @override 16 | Future>> getUsers() async { 17 | final response = await _dioClient.get(Endpoints.getUsers); 18 | 19 | return AppResponse>.fromJson( 20 | response.data, 21 | (dynamic json) { 22 | if (response.data['success'] && json != null) { 23 | return (json as List) 24 | .map((e) => UserEntity.fromJson(e)) 25 | .toList(); 26 | } 27 | return []; 28 | }, 29 | ); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/screens/chat/chat_screen.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:dash_chat_2/dash_chat_2.dart'; 4 | import 'package:flutter/material.dart'; 5 | import 'package:flutter_bloc/flutter_bloc.dart'; 6 | import 'package:flutter_chat_app/blocs/auth/auth_bloc.dart'; 7 | import 'package:flutter_chat_app/blocs/chat/chat_bloc.dart'; 8 | import 'package:flutter_chat_app/models/models.dart'; 9 | import 'package:flutter_chat_app/utils/chat.dart'; 10 | import 'package:flutter_chat_app/utils/utils.dart'; 11 | import 'package:flutter_chat_app/widgets/widgets.dart'; 12 | import 'package:pusher_client/pusher_client.dart'; 13 | 14 | class ChatScreen extends StatefulWidget { 15 | const ChatScreen({super.key}); 16 | 17 | static const routeName = "chat"; 18 | 19 | @override 20 | State createState() => _ChatScreenState(); 21 | } 22 | 23 | class _ChatScreenState extends State { 24 | void listenChatChannel(ChatEntity chat) { 25 | LaravelEcho.instance.private('chat.${chat.id}').listen('.message.sent', 26 | (e) { 27 | if (e is PusherEvent) { 28 | if (e.data != null) { 29 | vLog(jsonDecode(e.data!)); 30 | _handleNewMessage(jsonDecode(e.data!)); 31 | } 32 | } 33 | }).error((err) { 34 | eLog(err); 35 | }); 36 | } 37 | 38 | void leaveChatChannel(ChatEntity chat) { 39 | try { 40 | LaravelEcho.instance.leave('chat.${chat.id}'); 41 | } catch (err) { 42 | eLog(err); 43 | } 44 | } 45 | 46 | void _handleNewMessage(Map data) { 47 | final chatBloc = context.read(); 48 | final selectedChat = chatBloc.state.selectedChat!; 49 | if (selectedChat.id == data['chat_id']) { 50 | final chatMessage = ChatMessageEntity.fromJson(data['message']); 51 | chatBloc.add(AddNewMessage(chatMessage)); 52 | } 53 | } 54 | 55 | @override 56 | Widget build(BuildContext context) { 57 | final chatBloc = context.read(); 58 | final authBloc = context.read(); 59 | 60 | return StartUpContainer( 61 | onInit: () { 62 | /// create a chat and get chat messages 63 | chatBloc.add(const GetChatMessage()); 64 | if (chatBloc.state.selectedChat != null) { 65 | listenChatChannel(chatBloc.state.selectedChat!); 66 | } 67 | }, 68 | onDisposed: () { 69 | leaveChatChannel(chatBloc.state.selectedChat!); 70 | chatBloc.add(const ChatReset()); 71 | chatBloc.add(const ChatStarted()); 72 | }, 73 | child: Scaffold( 74 | appBar: AppBar( 75 | title: BlocConsumer( 76 | listener: (context, state) { 77 | if (state.selectedChat != null) { 78 | listenChatChannel(state.selectedChat!); 79 | } 80 | }, 81 | listenWhen: (previous, current) => 82 | previous.selectedChat != current.selectedChat, 83 | builder: (context, state) { 84 | final chat = state.selectedChat; 85 | return Text( 86 | chat == null 87 | ? "N/A" 88 | : getChatName( 89 | chat.participants, 90 | authBloc.state.user!, 91 | ), 92 | ); 93 | }, 94 | ), 95 | ), 96 | body: BlocBuilder( 97 | builder: (context, state) { 98 | eLog(LaravelEcho.instance.socketId()); 99 | 100 | return DashChat( 101 | currentUser: authBloc.state.user!.toChatUser, 102 | onSend: (ChatMessage chatMessage) { 103 | chatBloc.add(SendMessage( 104 | state.selectedChat!.id, 105 | chatMessage, 106 | socketId: LaravelEcho.socketId, 107 | )); 108 | }, 109 | messages: state.uiChatMessages, 110 | messageListOptions: MessageListOptions( 111 | onLoadEarlier: () async { 112 | chatBloc.add(const LoadMoreChatMessage()); 113 | 114 | /// Loads more messages 115 | }, 116 | ), 117 | ); 118 | }, 119 | ), 120 | ), 121 | ); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /lib/screens/chat/data.dart: -------------------------------------------------------------------------------- 1 | import 'package:dash_chat_2/dash_chat_2.dart'; 2 | 3 | String profileImage = 4 | 'https://firebasestorage.googleapis.com/v0/b/molteo-40978.appspot.com/o/1-intro-photo-final.jpeg?alt=media&token=daf78997-d8f0-49d1-9120-a9380bde48b5'; 5 | 6 | // We have all the possibilities for users 7 | ChatUser user = ChatUser(id: '0'); 8 | ChatUser user1 = ChatUser(id: '1'); 9 | ChatUser user2 = ChatUser(id: '2', firstName: 'Niki Lauda'); 10 | ChatUser user3 = ChatUser(id: '3', lastName: 'Clark'); 11 | ChatUser user4 = ChatUser(id: '4', profileImage: profileImage); 12 | ChatUser user5 = ChatUser(id: '5', firstName: 'Charles', lastName: 'Leclerc'); 13 | ChatUser user6 = 14 | ChatUser(id: '6', firstName: 'Max', profileImage: profileImage); 15 | ChatUser user7 = 16 | ChatUser(id: '7', lastName: 'Toto', profileImage: profileImage); 17 | ChatUser user8 = ChatUser( 18 | id: '8', firstName: 'Toto', lastName: 'Clark', profileImage: profileImage); 19 | 20 | List allUsersSample = [ 21 | ChatMessage( 22 | text: 'Test', 23 | user: user1, 24 | createdAt: DateTime(2021, 01, 30, 16, 45), 25 | ), 26 | ChatMessage( 27 | text: 'Test', 28 | user: user2, 29 | createdAt: DateTime(2021, 01, 30, 16, 45), 30 | ), 31 | ChatMessage( 32 | text: 'Test', 33 | user: user3, 34 | createdAt: DateTime(2021, 01, 30, 16, 45), 35 | ), 36 | ChatMessage( 37 | text: 'Test', 38 | user: user4, 39 | createdAt: DateTime(2021, 01, 30, 16, 45), 40 | ), 41 | ChatMessage( 42 | text: 'Test', 43 | user: user5, 44 | createdAt: DateTime(2021, 01, 30, 16, 45), 45 | ), 46 | ChatMessage( 47 | text: 'Test', 48 | user: user6, 49 | createdAt: DateTime(2021, 01, 30, 16, 45), 50 | ), 51 | ChatMessage( 52 | text: 'Test', 53 | user: user7, 54 | createdAt: DateTime(2021, 01, 30, 16, 45), 55 | ), 56 | ChatMessage( 57 | text: 'Test', 58 | user: user8, 59 | createdAt: DateTime(2021, 01, 30, 16, 45), 60 | ), 61 | ]; 62 | 63 | List basicSample = [ 64 | ChatMessage( 65 | text: 'google.com hello you @Marc is it &you okay?', 66 | user: user2, 67 | createdAt: DateTime(2021, 01, 31, 16, 45), 68 | mentions: [ 69 | Mention(title: '@Marc'), 70 | Mention(title: '&you'), 71 | ], 72 | ), 73 | ChatMessage( 74 | text: 'google.com', 75 | user: user2, 76 | createdAt: DateTime(2021, 01, 30, 16, 45), 77 | ), 78 | ChatMessage( 79 | text: "Oh what's up guys?", 80 | user: user2, 81 | createdAt: DateTime(2021, 01, 30, 16, 45), 82 | ), 83 | ChatMessage( 84 | text: 'How you doin?', 85 | user: user8, 86 | createdAt: DateTime(2021, 01, 30, 16, 34), 87 | ), 88 | ChatMessage( 89 | text: 'Hey!', 90 | user: user, 91 | createdAt: DateTime(2021, 01, 30, 15, 50), 92 | ), 93 | ChatMessage( 94 | text: 'Hey!', 95 | user: user, 96 | createdAt: DateTime(2021, 01, 28, 15, 50), 97 | ), 98 | ChatMessage( 99 | text: 'Hey!', 100 | user: user, 101 | createdAt: DateTime(2021, 01, 28, 15, 50), 102 | ), 103 | ]; 104 | 105 | List media = [ 106 | ChatMessage( 107 | medias: [ 108 | ChatMedia( 109 | url: 110 | 'https://firebasestorage.googleapis.com/v0/b/molteo-40978.appspot.com/o/memes%2F155512641_3864499247004975_4028017188079714246_n.jpg?alt=media&token=0b335455-93ed-4529-9055-9a2c741e0189', 111 | type: MediaType.image, 112 | fileName: 'image.png', 113 | isUploading: true, 114 | ), 115 | ChatMedia( 116 | url: 117 | 'https://firebasestorage.googleapis.com/v0/b/molteo-40978.appspot.com/o/memes%2F155512641_3864499247004975_4028017188079714246_n.jpg?alt=media&token=0b335455-93ed-4529-9055-9a2c741e0189', 118 | type: MediaType.image, 119 | fileName: 'image.png', 120 | ), 121 | ChatMedia( 122 | url: 123 | 'https://firebasestorage.googleapis.com/v0/b/molteo-40978.appspot.com/o/chat_medias%2F2GFlPkj94hKCqonpEdf1%2F20210526_162318.mp4?alt=media&token=01b814b9-d93a-4bf1-8be1-cf9a49058f97', 124 | type: MediaType.video, 125 | fileName: 'video.mp4', 126 | isUploading: false, 127 | ), 128 | ChatMedia( 129 | url: 130 | 'https://firebasestorage.googleapis.com/v0/b/molteo-40978.appspot.com/o/memes%2F155512641_3864499247004975_4028017188079714246_n.jpg?alt=media&token=0b335455-93ed-4529-9055-9a2c741e0189', 131 | type: MediaType.file, 132 | fileName: 'image.png', 133 | ), 134 | ChatMedia( 135 | url: 136 | 'https://firebasestorage.googleapis.com/v0/b/molteo-40978.appspot.com/o/memes%2F155512641_3864499247004975_4028017188079714246_n.jpg?alt=media&token=0b335455-93ed-4529-9055-9a2c741e0189', 137 | type: MediaType.image, 138 | fileName: 'image.png', 139 | ) 140 | ], 141 | user: user3, 142 | createdAt: DateTime(2021, 01, 30, 16, 34), 143 | ), 144 | ]; 145 | 146 | List quickReplies = [ 147 | ChatMessage( 148 | text: 'How you doin?', 149 | user: user3, 150 | createdAt: DateTime.now(), 151 | quickReplies: [ 152 | QuickReply(title: 'Great!'), 153 | QuickReply(title: 'Awesome'), 154 | ], 155 | ), 156 | ]; 157 | 158 | List mentionSample = [ 159 | ChatMessage( 160 | text: 'Hello @Niki, you should check #channel', 161 | user: user2, 162 | createdAt: DateTime(2021, 01, 31, 16, 45), 163 | mentions: [ 164 | Mention(title: '@Niki', customProperties: {'userId': user5.id}), 165 | Mention(title: '#channel'), 166 | ], 167 | ), 168 | ChatMessage( 169 | text: "Oh what's up guys?", 170 | user: user5, 171 | createdAt: DateTime(2021, 01, 30, 16, 45), 172 | ), 173 | ]; 174 | 175 | List d = []; 176 | -------------------------------------------------------------------------------- /lib/screens/chat_list/chat_list_item.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_chat_app/models/models.dart'; 3 | import 'package:flutter_chat_app/utils/chat.dart'; 4 | import 'package:flutter_chat_app/utils/utils.dart'; 5 | 6 | class ChatListItem extends StatelessWidget { 7 | const ChatListItem({ 8 | Key? key, 9 | required this.item, 10 | required this.currentUser, 11 | required this.onPressed, 12 | }) : super(key: key); 13 | 14 | final ChatEntity item; 15 | final UserEntity currentUser; 16 | final void Function(ChatEntity) onPressed; 17 | 18 | @override 19 | Widget build(BuildContext context) { 20 | return ListTile( 21 | leading: const Icon(Icons.account_circle, size: 50.0), 22 | title: Text( 23 | item.name ?? 24 | getChatName( 25 | item.participants, 26 | currentUser, 27 | ), 28 | ), 29 | subtitle: Row( 30 | mainAxisAlignment: MainAxisAlignment.spaceBetween, 31 | children: [ 32 | Expanded( 33 | child: Text( 34 | item.lastMessage?.message ?? "...", 35 | overflow: TextOverflow.ellipsis, 36 | maxLines: 1, 37 | ), 38 | ), 39 | Text(utcToLocal(item.updatedAt)), 40 | ], 41 | ), 42 | onTap: () => onPressed(item), 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/screens/guest/guest_screen.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_bloc/flutter_bloc.dart'; 3 | import 'package:flutter_chat_app/cubits/cubits.dart'; 4 | import 'package:flutter_chat_app/screens/screens.dart'; 5 | import 'package:flutter_login/flutter_login.dart'; 6 | 7 | class GuestScreen extends StatelessWidget { 8 | const GuestScreen({super.key}); 9 | 10 | static const routeName = "guest"; 11 | 12 | @override 13 | Widget build(BuildContext context) { 14 | final cubit = context.read(); 15 | 16 | return FlutterLogin( 17 | scrollable: true, 18 | hideForgotPasswordButton: true, 19 | title: 'Easy Chat App', 20 | theme: LoginTheme( 21 | titleStyle: const TextStyle( 22 | fontSize: 24, 23 | fontWeight: FontWeight.bold, 24 | ), 25 | pageColorDark: Colors.blue, 26 | pageColorLight: Colors.blue.shade300, 27 | ), 28 | logo: const AssetImage('assets/images/chat.png'), 29 | onLogin: cubit.signIn, 30 | onSignup: cubit.signUp, 31 | userValidator: (value) { 32 | if (value == null || !value.contains('@')) { 33 | return 'Please enter a valid email address'; 34 | } 35 | return null; 36 | }, 37 | passwordValidator: (value) { 38 | if (value == null || value.length < 5) { 39 | return "Please must be at least 5 chars"; 40 | } 41 | return null; 42 | }, 43 | onSubmitAnimationCompleted: () { 44 | Navigator.of(context).pushReplacementNamed(ChatListScreen.routeName); 45 | }, 46 | onRecoverPassword: (_) async => null, 47 | ); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lib/screens/screens.dart: -------------------------------------------------------------------------------- 1 | export "guest/guest_screen.dart"; 2 | export "chat_list/chat_list_screen.dart"; 3 | -------------------------------------------------------------------------------- /lib/screens/splash/splash_screen.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_bloc/flutter_bloc.dart'; 3 | import 'package:flutter_chat_app/blocs/blocs.dart'; 4 | import 'package:flutter_chat_app/screens/screens.dart'; 5 | import 'package:flutter_chat_app/utils/utils.dart'; 6 | import 'package:flutter_chat_app/widgets/widgets.dart'; 7 | 8 | class SplashScreen extends StatefulWidget { 9 | const SplashScreen({super.key}); 10 | 11 | static const routeName = "splash"; 12 | 13 | @override 14 | State createState() => _SplashScreenState(); 15 | } 16 | 17 | class _SplashScreenState extends State { 18 | bool _isInit = false; 19 | 20 | @override 21 | void didChangeDependencies() { 22 | _initialize(); 23 | super.didChangeDependencies(); 24 | } 25 | 26 | void _initialize() async { 27 | if (!_isInit) { 28 | await Future.delayed(const Duration(milliseconds: 500)); 29 | 30 | if (!mounted) return; 31 | 32 | final authState = context.read().state; 33 | 34 | final redirectScreen = authState.isAuthenticated 35 | ? ChatListScreen.routeName 36 | : GuestScreen.routeName; 37 | 38 | Navigator.of(context).pushReplacementNamed(redirectScreen); 39 | _isInit = true; 40 | } 41 | } 42 | 43 | @override 44 | Widget build(BuildContext context) { 45 | return const Scaffold( 46 | body: BlankContent( 47 | isLoading: true, 48 | ), 49 | ); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /lib/utils/chat.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_chat_app/models/models.dart'; 2 | 3 | String getChatName( 4 | List participants, UserEntity currentUser) { 5 | final otherParticipants = 6 | participants.where((el) => el.userId != currentUser.id).toList(); 7 | 8 | if (otherParticipants.isNotEmpty) { 9 | return otherParticipants[0].user.username; 10 | } 11 | 12 | return 'N/A'; 13 | } 14 | -------------------------------------------------------------------------------- /lib/utils/dio_client/app_interceptors.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import 'package:dio/dio.dart'; 4 | import 'package:flutter_chat_app/blocs/auth/auth_bloc.dart'; 5 | import 'package:flutter_chat_app/models/models.dart'; 6 | 7 | class AppInterceptors extends Interceptor { 8 | static AppInterceptors? _singleton; 9 | 10 | AppInterceptors._internal(); 11 | 12 | factory AppInterceptors() { 13 | return _singleton ??= AppInterceptors._internal(); 14 | } 15 | @override 16 | void onRequest( 17 | RequestOptions options, RequestInterceptorHandler handler) async { 18 | /// Tries to add Authorization header only if Authorization header not extisted 19 | if (!options.headers.containsKey(HttpHeaders.authorizationHeader)) { 20 | final state = AuthBloc().state; 21 | 22 | if (state.token != null) { 23 | options.headers[HttpHeaders.authorizationHeader] = 24 | 'Bearer ${state.token}'; 25 | } 26 | } 27 | 28 | return handler.next(options); 29 | } 30 | 31 | @override 32 | void onResponse(Response response, ResponseInterceptorHandler handler) { 33 | /// Maps custom response 34 | final responseData = mapResponseData( 35 | requestOptions: response.requestOptions, 36 | response: response, 37 | ); 38 | 39 | return handler.resolve(responseData); 40 | } 41 | 42 | @override 43 | void onError(DioError err, ErrorInterceptorHandler handler) { 44 | /// Gets custom error message 45 | final errorMessage = getErrorMessage(err.type, err.response?.statusCode); 46 | 47 | /// Maps custom response 48 | final responseData = mapResponseData( 49 | requestOptions: err.requestOptions, 50 | response: err.response, 51 | customMessage: errorMessage, 52 | isErrorResponse: true, 53 | ); 54 | 55 | return handler.resolve(responseData); 56 | } 57 | } 58 | 59 | String getErrorMessage(DioErrorType errorType, int? statusCode) { 60 | String errorMessage = ""; 61 | switch (errorType) { 62 | case DioErrorType.connectTimeout: 63 | case DioErrorType.sendTimeout: 64 | case DioErrorType.receiveTimeout: 65 | errorMessage = DioErrorMessage.deadlineExceededException; 66 | break; 67 | case DioErrorType.response: 68 | switch (statusCode) { 69 | case 400: 70 | errorMessage = DioErrorMessage.badRequestException; 71 | break; 72 | case 401: 73 | errorMessage = DioErrorMessage.unauthorizedException; 74 | break; 75 | case 404: 76 | errorMessage = DioErrorMessage.notFoundException; 77 | break; 78 | case 409: 79 | errorMessage = DioErrorMessage.conflictException; 80 | break; 81 | case 500: 82 | errorMessage = DioErrorMessage.internalServerErrorException; 83 | break; 84 | } 85 | break; 86 | case DioErrorType.cancel: 87 | break; 88 | case DioErrorType.other: 89 | errorMessage = DioErrorMessage.unexpectedException; 90 | break; 91 | } 92 | return errorMessage; 93 | } 94 | 95 | class DioErrorMessage { 96 | static const badRequestException = "Invalid request"; 97 | static const internalServerErrorException = 98 | "Unknown error occurred, please try again later."; 99 | static const conflictException = "Conflict occurred"; 100 | static const unauthorizedException = "Access denied"; 101 | static const notFoundException = 102 | "The requested information could not be found"; 103 | static const unexpectedException = "Unexpected error occurred."; 104 | static const noInternetConnectionException = 105 | "No internet connection detected, please try again."; 106 | static const deadlineExceededException = 107 | "The connection has timed out, please try again."; 108 | } 109 | 110 | Response mapResponseData({ 111 | Response? response, 112 | required RequestOptions requestOptions, 113 | String customMessage = "", 114 | bool isErrorResponse = false, 115 | }) { 116 | final bool hasResponseData = response?.data != null; 117 | 118 | Map? responseData = response?.data; 119 | 120 | if (hasResponseData) { 121 | responseData!.addAll({ 122 | "statusCode": response?.statusCode, 123 | "statusMessage": response?.statusMessage 124 | }); 125 | } 126 | 127 | return Response( 128 | requestOptions: requestOptions, 129 | data: hasResponseData 130 | ? responseData 131 | : AppResponse( 132 | message: customMessage, 133 | success: isErrorResponse ? false : true, 134 | statusCode: response?.statusCode, 135 | statusMessage: response?.statusMessage, 136 | ).toJson( 137 | (value) => null, 138 | ), 139 | ); 140 | } 141 | -------------------------------------------------------------------------------- /lib/utils/dio_client/dio_client.dart: -------------------------------------------------------------------------------- 1 | import 'package:dio/dio.dart'; 2 | import 'package:flutter_chat_app/utils/dio_client/app_interceptors.dart'; 3 | import 'package:pretty_dio_logger/pretty_dio_logger.dart'; 4 | 5 | class DioClient { 6 | static DioClient? _singleton; 7 | 8 | static late Dio _dio; 9 | 10 | DioClient._() { 11 | _dio = createDioClient(); 12 | } 13 | 14 | factory DioClient() { 15 | return _singleton ??= DioClient._(); 16 | } 17 | 18 | Dio get instance => _dio; 19 | 20 | Dio createDioClient() { 21 | final dio = Dio( 22 | BaseOptions( 23 | baseUrl: "http://10.0.2.2:8000", 24 | receiveTimeout: 15000, // 15 seconds 25 | connectTimeout: 15000, 26 | sendTimeout: 15000, 27 | headers: { 28 | Headers.acceptHeader: 'application/json', 29 | Headers.contentTypeHeader: 'application/json', 30 | }, 31 | ), 32 | ); 33 | 34 | dio.interceptors.addAll([ 35 | // PrettyDioLogger( 36 | // requestHeader: true, 37 | // requestBody: true, 38 | // responseBody: true, 39 | // responseHeader: true, 40 | // error: true, 41 | // compact: true, 42 | // maxWidth: 90, 43 | // ), 44 | AppInterceptors(), 45 | ]); 46 | 47 | return dio; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lib/utils/formatting.dart: -------------------------------------------------------------------------------- 1 | import 'package:intl/intl.dart'; 2 | 3 | String utcToLocal( 4 | String value, { 5 | bool hasTime = true, 6 | }) { 7 | try { 8 | DateTime parsed = parseDateTime(value); 9 | 10 | return hasTime 11 | ? DateFormat.yMd().add_jms().format(parsed) 12 | : DateFormat.yMd().format(parsed); 13 | } catch (_) { 14 | return 'Invalid DateTime'; 15 | } 16 | } 17 | 18 | DateTime parseDateTime(String value) { 19 | return DateFormat("yyyy-MM-ddTHH:mm:ssZ").parseUTC(value).toLocal(); 20 | } 21 | -------------------------------------------------------------------------------- /lib/utils/laravel_echo/laravel_echo.dart: -------------------------------------------------------------------------------- 1 | import 'package:laravel_echo/laravel_echo.dart'; 2 | import 'package:pusher_client/pusher_client.dart'; 3 | 4 | class LaravelEcho { 5 | static LaravelEcho? _singleton; 6 | static late Echo _echo; 7 | final String token; 8 | 9 | LaravelEcho._({ 10 | required this.token, 11 | }) { 12 | _echo = createLaravelEcho(token); 13 | } 14 | 15 | factory LaravelEcho.init({ 16 | required String token, 17 | }) { 18 | if (_singleton == null || token != _singleton?.token) { 19 | _singleton = LaravelEcho._(token: token); 20 | } 21 | 22 | return _singleton!; 23 | } 24 | 25 | static Echo get instance => _echo; 26 | 27 | static String get socketId => _echo.socketId() ?? "11111.11111111"; 28 | } 29 | 30 | class PusherConfig { 31 | static const appId = ""; 32 | static const key = ""; 33 | static const secret = ""; 34 | static const cluster = ""; 35 | static const hostEndPoint = ""; 36 | static const hostAuthEndPoint = "$hostEndPoint/api/broadcasting/auth"; 37 | static const port = 6001; 38 | } 39 | 40 | PusherClient createPusherClient(String token) { 41 | PusherOptions options = PusherOptions( 42 | wsPort: PusherConfig.port, 43 | encrypted: true, 44 | host: PusherConfig.hostEndPoint, 45 | cluster: PusherConfig.cluster, 46 | auth: PusherAuth( 47 | PusherConfig.hostAuthEndPoint, 48 | headers: { 49 | 'Authorization': "Bearer $token", 50 | 'Content-Type': "application/json", 51 | 'Accept': 'application/json' 52 | }, 53 | ), 54 | ); 55 | 56 | PusherClient pusherClient = PusherClient( 57 | PusherConfig.key, 58 | options, 59 | autoConnect: false, 60 | enableLogging: true, 61 | ); 62 | 63 | return pusherClient; 64 | } 65 | 66 | Echo createLaravelEcho(String token) { 67 | return Echo( 68 | client: createPusherClient(token), 69 | broadcaster: EchoBroadcasterType.Pusher, 70 | ); 71 | } 72 | -------------------------------------------------------------------------------- /lib/utils/logger.dart: -------------------------------------------------------------------------------- 1 | import 'package:logger/logger.dart'; 2 | 3 | final prettyLog = Logger( 4 | printer: PrettyPrinter( 5 | methodCount: 1, // number of method calls to be displayed 6 | errorMethodCount: 8, // number of method calls if stacktrace is provided 7 | lineLength: 120, // width of the output 8 | colors: true, // Colorful log messages 9 | printEmojis: true, // Print an emoji for each log message 10 | printTime: false, // Should each log print contain a timestamp 11 | ), 12 | //printer: PrefixPrinter(PrettyPrinter(colors: false)) 13 | ); 14 | 15 | final wLog = prettyLog.w; 16 | final vLog = prettyLog.v; 17 | final dLog = prettyLog.d; 18 | final iLog = prettyLog.i; 19 | final eLog = prettyLog.e; 20 | final wtfLog = prettyLog.wtf; 21 | -------------------------------------------------------------------------------- /lib/utils/onesignal/onesignal.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_chat_app/utils/utils.dart'; 2 | import 'package:onesignal_flutter/onesignal_flutter.dart'; 3 | 4 | const oneSignalAppId = ""; 5 | 6 | Future initOneSignal() async { 7 | final oneSignalShared = OneSignal.shared; 8 | 9 | oneSignalShared.setLogLevel(OSLogLevel.none, OSLogLevel.none); 10 | 11 | oneSignalShared.setRequiresUserPrivacyConsent(true); 12 | 13 | await oneSignalShared.setAppId(oneSignalAppId); 14 | } 15 | 16 | void registerOneSignalEventListener({ 17 | required Function(OSNotificationOpenedResult) onOpened, 18 | required Function(OSNotificationReceivedEvent) onReceivedInForeground, 19 | }) { 20 | final oneSignalShared = OneSignal.shared; 21 | 22 | oneSignalShared.setNotificationOpenedHandler(onOpened); 23 | 24 | oneSignalShared 25 | .setNotificationWillShowInForegroundHandler(onReceivedInForeground); 26 | } 27 | 28 | const tagName = "userId"; 29 | 30 | void sendUserTag(int userId) { 31 | OneSignal.shared.sendTag(tagName, userId.toString()).then((response) { 32 | vLog("Successfully sent tags with response: $response"); 33 | }).catchError((error) { 34 | vLog("Encountered an error sending tags: $error"); 35 | }); 36 | } 37 | 38 | void deleteUserTag() { 39 | OneSignal.shared.deleteTag(tagName).then((response) { 40 | vLog("Successfully deleted tags with response $response"); 41 | }).catchError((error) { 42 | vLog("Encountered error deleting tag: $error"); 43 | }); 44 | } 45 | -------------------------------------------------------------------------------- /lib/utils/utils.dart: -------------------------------------------------------------------------------- 1 | export "dio_client/dio_client.dart"; 2 | export "logger.dart"; 3 | export "formatting.dart"; 4 | export "laravel_echo/laravel_echo.dart"; 5 | export 'onesignal/onesignal.dart'; 6 | -------------------------------------------------------------------------------- /lib/widgets/blank_content.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class BlankContent extends StatelessWidget { 4 | const BlankContent({ 5 | Key? key, 6 | this.content, 7 | this.isLoading, 8 | this.icon, 9 | }) : super(key: key); 10 | final String? content; 11 | final bool? isLoading; 12 | final IconData? icon; 13 | 14 | @override 15 | Widget build(BuildContext context) { 16 | return SizedBox( 17 | height: double.infinity, 18 | width: double.infinity, 19 | child: Column( 20 | mainAxisAlignment: MainAxisAlignment.center, 21 | children: isLoading != null && isLoading == true 22 | ? const [ 23 | SizedBox( 24 | height: 100, 25 | width: 100, 26 | child: CircularProgressIndicator(), 27 | ), 28 | ] 29 | : [ 30 | Icon( 31 | icon ?? Icons.receipt, 32 | size: 80.0, 33 | color: Theme.of(context).hintColor.withOpacity(0.4), 34 | ), 35 | Text( 36 | content ?? "No Data Available", 37 | style: TextStyle( 38 | fontSize: 20.0, 39 | fontWeight: FontWeight.bold, 40 | color: Theme.of(context).hintColor.withOpacity(0.4), 41 | ), 42 | ) 43 | ], 44 | )); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /lib/widgets/startup_container.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class StartUpContainer extends StatefulWidget { 4 | const StartUpContainer({ 5 | Key? key, 6 | required this.onInit, 7 | required this.child, 8 | this.onDisposed, 9 | this.delayInitDuration, 10 | }) : super(key: key); 11 | 12 | final Function onInit; 13 | final Widget child; 14 | final Function? onDisposed; 15 | 16 | /// Delays in milliseconds 17 | final int? delayInitDuration; 18 | 19 | @override 20 | State createState() => _StartUpContainerState(); 21 | } 22 | 23 | class _StartUpContainerState extends State { 24 | bool _isInit = false; 25 | late BuildContext buildContext; 26 | 27 | @override 28 | void didChangeDependencies() { 29 | _initialize(); 30 | super.didChangeDependencies(); 31 | } 32 | 33 | _initialize() async { 34 | if (!_isInit) { 35 | final duration = widget.delayInitDuration ?? 200; 36 | if (duration > 0) { 37 | await Future.delayed(Duration(milliseconds: duration)); 38 | } 39 | 40 | if (!mounted) return; 41 | widget.onInit(); 42 | buildContext = context; 43 | _isInit = true; 44 | } 45 | } 46 | 47 | @override 48 | void dispose() { 49 | if (widget.onDisposed != null) { 50 | widget.onDisposed!(); 51 | } 52 | super.dispose(); 53 | } 54 | 55 | @override 56 | Widget build(BuildContext context) { 57 | return widget.child; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /lib/widgets/widgets.dart: -------------------------------------------------------------------------------- 1 | export "blank_content.dart"; 2 | export "startup_container.dart"; 3 | -------------------------------------------------------------------------------- /linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project-level configuration. 2 | cmake_minimum_required(VERSION 3.10) 3 | project(runner LANGUAGES CXX) 4 | 5 | # The name of the executable created for the application. Change this to change 6 | # the on-disk name of your application. 7 | set(BINARY_NAME "flutter_chat_app") 8 | # The unique GTK application identifier for this application. See: 9 | # https://wiki.gnome.org/HowDoI/ChooseApplicationID 10 | set(APPLICATION_ID "com.example.flutter_chat_app") 11 | 12 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 13 | # versions of CMake. 14 | cmake_policy(SET CMP0063 NEW) 15 | 16 | # Load bundled libraries from the lib/ directory relative to the binary. 17 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") 18 | 19 | # Root filesystem for cross-building. 20 | if(FLUTTER_TARGET_PLATFORM_SYSROOT) 21 | set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) 22 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) 23 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 24 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 25 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 26 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 27 | endif() 28 | 29 | # Define build configuration options. 30 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 31 | set(CMAKE_BUILD_TYPE "Debug" CACHE 32 | STRING "Flutter build mode" FORCE) 33 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 34 | "Debug" "Profile" "Release") 35 | endif() 36 | 37 | # Compilation settings that should be applied to most targets. 38 | # 39 | # Be cautious about adding new options here, as plugins use this function by 40 | # default. In most cases, you should add new options to specific targets instead 41 | # of modifying this function. 42 | function(APPLY_STANDARD_SETTINGS TARGET) 43 | target_compile_features(${TARGET} PUBLIC cxx_std_14) 44 | target_compile_options(${TARGET} PRIVATE -Wall -Werror) 45 | target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") 46 | target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") 47 | endfunction() 48 | 49 | # Flutter library and tool build rules. 50 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 51 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 52 | 53 | # System-level dependencies. 54 | find_package(PkgConfig REQUIRED) 55 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 56 | 57 | add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") 58 | 59 | # Define the application target. To change its name, change BINARY_NAME above, 60 | # not the value here, or `flutter run` will no longer work. 61 | # 62 | # Any new source files that you add to the application should be added here. 63 | add_executable(${BINARY_NAME} 64 | "main.cc" 65 | "my_application.cc" 66 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 67 | ) 68 | 69 | # Apply the standard set of build settings. This can be removed for applications 70 | # that need different build settings. 71 | apply_standard_settings(${BINARY_NAME}) 72 | 73 | # Add dependency libraries. Add any application-specific dependencies here. 74 | target_link_libraries(${BINARY_NAME} PRIVATE flutter) 75 | target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) 76 | 77 | # Run the Flutter tool portions of the build. This must not be removed. 78 | add_dependencies(${BINARY_NAME} flutter_assemble) 79 | 80 | # Only the install-generated bundle's copy of the executable will launch 81 | # correctly, since the resources must in the right relative locations. To avoid 82 | # people trying to run the unbundled copy, put it in a subdirectory instead of 83 | # the default top-level location. 84 | set_target_properties(${BINARY_NAME} 85 | PROPERTIES 86 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" 87 | ) 88 | 89 | # Generated plugin build rules, which manage building the plugins and adding 90 | # them to the application. 91 | include(flutter/generated_plugins.cmake) 92 | 93 | 94 | # === Installation === 95 | # By default, "installing" just makes a relocatable bundle in the build 96 | # directory. 97 | set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") 98 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 99 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 100 | endif() 101 | 102 | # Start with a clean build bundle directory every time. 103 | install(CODE " 104 | file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") 105 | " COMPONENT Runtime) 106 | 107 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 108 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") 109 | 110 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 111 | COMPONENT Runtime) 112 | 113 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 114 | COMPONENT Runtime) 115 | 116 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 117 | COMPONENT Runtime) 118 | 119 | foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) 120 | install(FILES "${bundled_library}" 121 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 122 | COMPONENT Runtime) 123 | endforeach(bundled_library) 124 | 125 | # Fully re-copy the assets directory on each build to avoid having stale files 126 | # from a previous install. 127 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 128 | install(CODE " 129 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 130 | " COMPONENT Runtime) 131 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 132 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 133 | 134 | # Install the AOT library on non-Debug builds only. 135 | if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") 136 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 137 | COMPONENT Runtime) 138 | endif() 139 | -------------------------------------------------------------------------------- /linux/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.10) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | 12 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...), 13 | # which isn't available in 3.10. 14 | function(list_prepend LIST_NAME PREFIX) 15 | set(NEW_LIST "") 16 | foreach(element ${${LIST_NAME}}) 17 | list(APPEND NEW_LIST "${PREFIX}${element}") 18 | endforeach(element) 19 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) 20 | endfunction() 21 | 22 | # === Flutter Library === 23 | # System-level dependencies. 24 | find_package(PkgConfig REQUIRED) 25 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 26 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) 27 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) 28 | 29 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") 30 | 31 | # Published to parent scope for install step. 32 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 33 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 34 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 35 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) 36 | 37 | list(APPEND FLUTTER_LIBRARY_HEADERS 38 | "fl_basic_message_channel.h" 39 | "fl_binary_codec.h" 40 | "fl_binary_messenger.h" 41 | "fl_dart_project.h" 42 | "fl_engine.h" 43 | "fl_json_message_codec.h" 44 | "fl_json_method_codec.h" 45 | "fl_message_codec.h" 46 | "fl_method_call.h" 47 | "fl_method_channel.h" 48 | "fl_method_codec.h" 49 | "fl_method_response.h" 50 | "fl_plugin_registrar.h" 51 | "fl_plugin_registry.h" 52 | "fl_standard_message_codec.h" 53 | "fl_standard_method_codec.h" 54 | "fl_string_codec.h" 55 | "fl_value.h" 56 | "fl_view.h" 57 | "flutter_linux.h" 58 | ) 59 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") 60 | add_library(flutter INTERFACE) 61 | target_include_directories(flutter INTERFACE 62 | "${EPHEMERAL_DIR}" 63 | ) 64 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") 65 | target_link_libraries(flutter INTERFACE 66 | PkgConfig::GTK 67 | PkgConfig::GLIB 68 | PkgConfig::GIO 69 | ) 70 | add_dependencies(flutter flutter_assemble) 71 | 72 | # === Flutter tool backend === 73 | # _phony_ is a non-existent file to force this command to run every time, 74 | # since currently there's no way to get a full input/output list from the 75 | # flutter tool. 76 | add_custom_command( 77 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 78 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_ 79 | COMMAND ${CMAKE_COMMAND} -E env 80 | ${FLUTTER_TOOL_ENVIRONMENT} 81 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" 82 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} 83 | VERBATIM 84 | ) 85 | add_custom_target(flutter_assemble DEPENDS 86 | "${FLUTTER_LIBRARY}" 87 | ${FLUTTER_LIBRARY_HEADERS} 88 | ) 89 | -------------------------------------------------------------------------------- /linux/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | #include 10 | 11 | void fl_register_plugins(FlPluginRegistry* registry) { 12 | g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar = 13 | fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin"); 14 | url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar); 15 | } 16 | -------------------------------------------------------------------------------- /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 | url_launcher_linux 7 | ) 8 | 9 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 10 | ) 11 | 12 | set(PLUGIN_BUNDLED_LIBRARIES) 13 | 14 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 15 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) 16 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 18 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 19 | endforeach(plugin) 20 | 21 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 22 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) 23 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 24 | endforeach(ffi_plugin) 25 | -------------------------------------------------------------------------------- /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, "flutter_chat_app"); 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, "flutter_chat_app"); 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 sqflite 10 | import url_launcher_macos 11 | 12 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { 13 | PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) 14 | SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) 15 | UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) 16 | } 17 | -------------------------------------------------------------------------------- /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/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/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 = flutter_chat_app 9 | 10 | // The application's bundle identifier 11 | PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterChatApp 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 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_chat_app 2 | description: A new Flutter project. 3 | 4 | # The following line prevents the package from being accidentally published to 5 | # pub.dev using `flutter pub publish`. This is preferred for private packages. 6 | publish_to: "none" # Remove this line if you wish to publish to pub.dev 7 | 8 | # The following defines the version and build number for your application. 9 | # A version number is three numbers separated by dots, like 1.2.43 10 | # followed by an optional build number separated by a +. 11 | # Both the version and the builder number may be overridden in flutter 12 | # build by specifying --build-name and --build-number, respectively. 13 | # In Android, build-name is used as versionName while build-number used as versionCode. 14 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning 15 | # In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. 16 | # Read more about iOS versioning at 17 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html 18 | # In Windows, build-name is used as the major, minor, and patch parts 19 | # of the product and file versions while build-number is used as the build suffix. 20 | version: 1.0.0+1 21 | 22 | environment: 23 | sdk: ">=2.18.0 <3.0.0" 24 | 25 | # Dependencies specify other packages that your package needs in order to work. 26 | # To automatically upgrade your package dependencies to the latest versions 27 | # consider running `flutter pub upgrade --major-versions`. Alternatively, 28 | # dependencies can be manually updated by changing the version numbers below to 29 | # the latest version available on pub.dev. To see which dependencies have newer 30 | # versions available, run `flutter pub outdated`. 31 | dependencies: 32 | flutter_bloc: ^8.1.1 33 | flutter_login: ^4.0.0 34 | freezed_annotation: ^2.1.0 35 | json_annotation: ^4.6.0 36 | hydrated_bloc: ^9.0.0-dev.2 37 | path_provider: ^2.0.11 38 | intl: ^0.17.0 39 | logger: ^1.1.0 40 | pretty_dio_logger: ^1.1.1 41 | search_page: ^2.0.0+1 42 | dash_chat_2: ^0.0.14 43 | dio: ^4.0.6 44 | equatable: ^2.0.5 45 | laravel_echo: 46 | git: 47 | url: https://github.com/kakajansh/echo.git 48 | ref: master 49 | pusher_client: 50 | git: 51 | url: https://github.com/DumbDev168/pusher_client.git 52 | ref: master 53 | onesignal_flutter: ^3.4.1 54 | flutter: 55 | sdk: flutter 56 | 57 | # The following adds the Cupertino Icons font to your application. 58 | # Use with the CupertinoIcons class for iOS style icons. 59 | cupertino_icons: ^1.0.2 60 | 61 | dev_dependencies: 62 | build_runner: ^2.2.0 63 | freezed: ^2.1.0+1 64 | json_serializable: ^6.3.1 65 | flutter_test: 66 | sdk: flutter 67 | 68 | # The "flutter_lints" package below contains a set of recommended lints to 69 | # encourage good coding practices. The lint set provided by the package is 70 | # activated in the `analysis_options.yaml` file located at the root of your 71 | # package. See that file for information about deactivating specific lint 72 | # rules and activating additional ones. 73 | flutter_lints: ^2.0.0 74 | 75 | # For information on the generic Dart part of this file, see the 76 | # following page: https://dart.dev/tools/pub/pubspec 77 | 78 | # The following section is specific to Flutter packages. 79 | flutter: 80 | # The following line ensures that the Material Icons font is 81 | # included with your application, so that you can use the icons in 82 | # the material Icons class. 83 | uses-material-design: true 84 | 85 | # To add assets to your application, add an assets section, like this: 86 | assets: 87 | - assets/images/chat.png 88 | # - images/a_dot_ham.jpeg 89 | 90 | # An image asset can refer to one or more resolution-specific "variants", see 91 | # https://flutter.dev/assets-and-images/#resolution-aware 92 | 93 | # For details regarding adding assets from package dependencies, see 94 | # https://flutter.dev/assets-and-images/#from-packages 95 | 96 | # To add custom fonts to your application, add a fonts section here, 97 | # in this "flutter" section. Each entry in this list should have a 98 | # "family" key with the font family name, and a "fonts" key with a 99 | # list giving the asset and other descriptors for the font. For 100 | # example: 101 | # fonts: 102 | # - family: Schyler 103 | # fonts: 104 | # - asset: fonts/Schyler-Regular.ttf 105 | # - asset: fonts/Schyler-Italic.ttf 106 | # style: italic 107 | # - family: Trajan Pro 108 | # fonts: 109 | # - asset: fonts/TrajanPro.ttf 110 | # - asset: fonts/TrajanPro_Bold.ttf 111 | # weight: 700 112 | # 113 | # For details regarding fonts from package dependencies, 114 | # see https://flutter.dev/custom-fonts/#from-packages 115 | -------------------------------------------------------------------------------- /test/widget_test.dart: -------------------------------------------------------------------------------- 1 | // This is a basic Flutter widget test. 2 | // 3 | // To perform an interaction with a widget in your test, use the WidgetTester 4 | // utility in the flutter_test package. For example, you can send tap and scroll 5 | // gestures. You can also use WidgetTester to find child widgets in the widget 6 | // tree, read text, and verify that the values of widget properties are correct. 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:flutter_test/flutter_test.dart'; 10 | 11 | import 'package:flutter_chat_app/main.dart'; 12 | 13 | void main() { 14 | testWidgets('Counter increments smoke test', (WidgetTester tester) async { 15 | // Build our app and trigger a frame. 16 | await tester.pumpWidget(const MyApp()); 17 | 18 | // Verify that our counter starts at 0. 19 | expect(find.text('0'), findsOneWidget); 20 | expect(find.text('1'), findsNothing); 21 | 22 | // Tap the '+' icon and trigger a frame. 23 | await tester.tap(find.byIcon(Icons.add)); 24 | await tester.pump(); 25 | 26 | // Verify that our counter has incremented. 27 | expect(find.text('0'), findsNothing); 28 | expect(find.text('1'), findsOneWidget); 29 | }); 30 | } 31 | -------------------------------------------------------------------------------- /web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/web/favicon.png -------------------------------------------------------------------------------- /web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/web/icons/Icon-192.png -------------------------------------------------------------------------------- /web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/web/icons/Icon-512.png -------------------------------------------------------------------------------- /web/icons/Icon-maskable-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/web/icons/Icon-maskable-192.png -------------------------------------------------------------------------------- /web/icons/Icon-maskable-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/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 | flutter_chat_app 33 | 34 | 35 | 39 | 40 | 41 | 42 | 43 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "flutter_chat_app", 3 | "short_name": "flutter_chat_app", 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(flutter_chat_app 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 "flutter_chat_app") 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 | 11 | void RegisterPlugins(flutter::PluginRegistry* registry) { 12 | UrlLauncherWindowsRegisterWithRegistrar( 13 | registry->GetRegistrarForPlugin("UrlLauncherWindows")); 14 | } 15 | -------------------------------------------------------------------------------- /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 | url_launcher_windows 7 | ) 8 | 9 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 10 | ) 11 | 12 | set(PLUGIN_BUNDLED_LIBRARIES) 13 | 14 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 15 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 16 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 18 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 19 | endforeach(plugin) 20 | 21 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 22 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) 23 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 24 | endforeach(ffi_plugin) 25 | -------------------------------------------------------------------------------- /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.example" "\0" 93 | VALUE "FileDescription", "flutter_chat_app" "\0" 94 | VALUE "FileVersion", VERSION_AS_STRING "\0" 95 | VALUE "InternalName", "flutter_chat_app" "\0" 96 | VALUE "LegalCopyright", "Copyright (C) 2022 com.example. All rights reserved." "\0" 97 | VALUE "OriginalFilename", "flutter_chat_app.exe" "\0" 98 | VALUE "ProductName", "flutter_chat_app" "\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"flutter_chat_app", 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/DumbDev168/flutter_chat_app/33695f23bd6547b794d2eee8838f5b71b25aa253/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 | --------------------------------------------------------------------------------