├── .gitignore ├── .metadata ├── .vscode └── launch.json ├── README.md ├── analysis_options.yaml ├── android ├── .gitignore ├── app │ ├── build.gradle │ └── src │ │ ├── debug │ │ └── AndroidManifest.xml │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── kotlin │ │ │ └── za │ │ │ │ └── co │ │ │ │ └── nanosoft │ │ │ │ └── crm │ │ │ │ └── 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 ├── docs ├── Clean Architecture.excalidraw ├── clean_arch.png ├── side_effects.excalidraw ├── side_effects.png ├── side_effects_no_side_effects.png ├── structure.png ├── tdd_1.png ├── tdd_2.png ├── tdd_3.png ├── tdd_create_customer.png ├── tdd_delete_customer.png ├── tdd_get_customer.png ├── tdd_update_customer.png └── unclebobcleanarch.png ├── gen_mocks.sh ├── 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 ├── core │ └── error │ │ └── failures.dart ├── data │ ├── data_sources │ │ ├── implementations │ │ │ └── api │ │ │ │ ├── customer_datasource_impl.dart │ │ │ │ └── task_datasource_impl.dart │ │ └── interfaces │ │ │ ├── customer_datasource.dart │ │ │ └── task_datasource.dart │ └── entities │ │ ├── customer_entity.dart │ │ └── task_entity.dart ├── domain │ ├── model │ │ ├── customer.dart │ │ └── task.dart │ ├── repositories │ │ ├── implementations │ │ │ ├── customer_repository_impl.dart │ │ │ └── task_repository_impl.dart │ │ └── interfaces │ │ │ ├── customer_repository.dart │ │ │ └── task_repository.dart │ └── use_cases │ │ ├── customer │ │ ├── create_customer.dart │ │ ├── delete_customer.dart │ │ ├── get_all_customers.dart │ │ ├── get_customer.dart │ │ ├── make_customer_active.dart │ │ ├── make_customer_inactive.dart │ │ └── update_customer_details.dart │ │ ├── lead │ │ ├── convert_lead_to_customer.dart │ │ ├── create_lead.dart │ │ ├── delete_lead.dart │ │ ├── get_all_leads.dart │ │ ├── get_lead.dart │ │ └── update_lead_details.dart │ │ └── task │ │ ├── create_task.dart │ │ ├── delete_task.dart │ │ ├── mark_task_as_completed.dart │ │ └── update_task.dart ├── main.dart └── presentation │ ├── components │ ├── delete_button.dart │ ├── edit_button.dart │ ├── list.dart │ ├── list_item.dart │ └── toolbar.dart │ ├── view_models │ ├── another_vm │ │ └── custom_hook.dart │ ├── customer │ │ ├── detail.dart │ │ ├── edit.dart │ │ ├── list.dart │ │ └── new.dart │ └── task │ │ ├── detail.dart │ │ ├── edit.dart │ │ ├── list.dart │ │ └── new.dart │ └── views │ ├── customer │ ├── detail.dart │ ├── edit.dart │ ├── list.dart │ └── new.dart │ ├── models │ └── screen.dart │ └── task │ ├── detail.dart │ ├── edit.dart │ ├── list.dart │ └── new.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.sh ├── test ├── domain │ ├── repositories │ │ └── implementations │ │ │ ├── customer_repository_impl_test.dart │ │ │ └── task_repository_impl_test.dart │ └── use_cases │ │ ├── customer │ │ ├── create_customer_test.dart │ │ ├── delete_customer_test.dart │ │ ├── get_all_customers_test.dart │ │ ├── get_customer_test.dart │ │ ├── make_customer_active_test.dart │ │ ├── make_customer_inactive_test.dart │ │ └── update_customer_test.dart │ │ ├── lead │ │ ├── convert_lead_to_customer_test.dart │ │ ├── create_lead_test.dart │ │ ├── delete_lead_test.dart │ │ ├── get_all_leads_test.dart │ │ ├── get_lead_test.dart │ │ └── update_lead_details_test.dart │ │ └── task │ │ ├── create_task_test.dart │ │ ├── delete_customer_task_test.dart │ │ ├── mark_task_completed_test.dart │ │ └── update_task_test.dart └── presentation │ └── view_models │ └── customer │ ├── customer_detail_view_model_test.dart │ ├── customer_edit_view_model_test.dart │ ├── customer_list_view_model_test.dart │ └── customer_new_view_model_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 | coverage 46 | -------------------------------------------------------------------------------- /.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: eb6d86ee27deecba4a83536aa20f366a6044895c 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: eb6d86ee27deecba4a83536aa20f366a6044895c 17 | base_revision: eb6d86ee27deecba4a83536aa20f366a6044895c 18 | - platform: android 19 | create_revision: eb6d86ee27deecba4a83536aa20f366a6044895c 20 | base_revision: eb6d86ee27deecba4a83536aa20f366a6044895c 21 | - platform: ios 22 | create_revision: eb6d86ee27deecba4a83536aa20f366a6044895c 23 | base_revision: eb6d86ee27deecba4a83536aa20f366a6044895c 24 | - platform: linux 25 | create_revision: eb6d86ee27deecba4a83536aa20f366a6044895c 26 | base_revision: eb6d86ee27deecba4a83536aa20f366a6044895c 27 | - platform: macos 28 | create_revision: eb6d86ee27deecba4a83536aa20f366a6044895c 29 | base_revision: eb6d86ee27deecba4a83536aa20f366a6044895c 30 | - platform: web 31 | create_revision: eb6d86ee27deecba4a83536aa20f366a6044895c 32 | base_revision: eb6d86ee27deecba4a83536aa20f366a6044895c 33 | - platform: windows 34 | create_revision: eb6d86ee27deecba4a83536aa20f366a6044895c 35 | base_revision: eb6d86ee27deecba4a83536aa20f366a6044895c 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": "crm", 9 | "request": "launch", 10 | "type": "dart" 11 | }, 12 | { 13 | "name": "crm (profile mode)", 14 | "request": "launch", 15 | "type": "dart", 16 | "flutterMode": "profile" 17 | }, 18 | { 19 | "name": "crm (release mode)", 20 | "request": "launch", 21 | "type": "dart", 22 | "flutterMode": "release" 23 | } 24 | ] 25 | } -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the analyzer, which statically analyzes Dart code to 2 | # check for errors, warnings, and lints. 3 | # 4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled 5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be 6 | # invoked from the command line by running `flutter analyze`. 7 | 8 | # The following line activates a set of recommended lints for Flutter apps, 9 | # packages, and plugins designed to encourage good coding practices. 10 | include: package:flutter_lints/flutter.yaml 11 | 12 | linter: 13 | # The lint rules applied to this project can be customized in the 14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml` 15 | # included above or to enable additional rules. A list of all available lints 16 | # and their documentation is published at 17 | # https://dart-lang.github.io/linter/lints/index.html. 18 | # 19 | # Instead of disabling a lint rule for the entire project in the 20 | # section below, it can also be suppressed for a single line of code 21 | # or a specific dart file by using the `// ignore: name_of_lint` and 22 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file 23 | # producing the lint. 24 | rules: 25 | # avoid_print: false # Uncomment to disable the `avoid_print` rule 26 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule 27 | 28 | # Additional information about this file can be found at 29 | # https://dart.dev/guides/language/analysis-options 30 | -------------------------------------------------------------------------------- /android/.gitignore: -------------------------------------------------------------------------------- 1 | gradle-wrapper.jar 2 | /.gradle 3 | /captures/ 4 | /gradlew 5 | /gradlew.bat 6 | /local.properties 7 | GeneratedPluginRegistrant.java 8 | 9 | # Remember to never publicly share your keystore. 10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app 11 | key.properties 12 | **/*.keystore 13 | **/*.jks 14 | -------------------------------------------------------------------------------- /android/app/build.gradle: -------------------------------------------------------------------------------- 1 | def localProperties = new Properties() 2 | def localPropertiesFile = rootProject.file('local.properties') 3 | if (localPropertiesFile.exists()) { 4 | localPropertiesFile.withReader('UTF-8') { reader -> 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 15 | if (flutterVersionCode == null) { 16 | flutterVersionCode = '1' 17 | } 18 | 19 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 20 | if (flutterVersionName == null) { 21 | flutterVersionName = '1.0' 22 | } 23 | 24 | apply plugin: 'com.android.application' 25 | apply plugin: 'kotlin-android' 26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 27 | 28 | android { 29 | compileSdkVersion flutter.compileSdkVersion 30 | ndkVersion flutter.ndkVersion 31 | 32 | compileOptions { 33 | sourceCompatibility JavaVersion.VERSION_1_8 34 | targetCompatibility JavaVersion.VERSION_1_8 35 | } 36 | 37 | kotlinOptions { 38 | jvmTarget = '1.8' 39 | } 40 | 41 | sourceSets { 42 | main.java.srcDirs += 'src/main/kotlin' 43 | } 44 | 45 | defaultConfig { 46 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 47 | applicationId "za.co.nanosoft.crm" 48 | // You can update the following values to match your application needs. 49 | // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. 50 | minSdkVersion flutter.minSdkVersion 51 | targetSdkVersion flutter.targetSdkVersion 52 | versionCode flutterVersionCode.toInteger() 53 | versionName flutterVersionName 54 | } 55 | 56 | buildTypes { 57 | release { 58 | // TODO: Add your own signing config for the release build. 59 | // Signing with the debug keys for now, so `flutter run --release` works. 60 | signingConfig signingConfigs.debug 61 | } 62 | } 63 | } 64 | 65 | flutter { 66 | source '../..' 67 | } 68 | 69 | dependencies { 70 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 71 | } 72 | -------------------------------------------------------------------------------- /android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 15 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 30 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /android/app/src/main/kotlin/za/co/nanosoft/crm/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package za.co.nanosoft.crm 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/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/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 | -------------------------------------------------------------------------------- /docs/clean_arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/docs/clean_arch.png -------------------------------------------------------------------------------- /docs/side_effects.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/docs/side_effects.png -------------------------------------------------------------------------------- /docs/side_effects_no_side_effects.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/docs/side_effects_no_side_effects.png -------------------------------------------------------------------------------- /docs/structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/docs/structure.png -------------------------------------------------------------------------------- /docs/tdd_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/docs/tdd_1.png -------------------------------------------------------------------------------- /docs/tdd_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/docs/tdd_2.png -------------------------------------------------------------------------------- /docs/tdd_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/docs/tdd_3.png -------------------------------------------------------------------------------- /docs/tdd_create_customer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/docs/tdd_create_customer.png -------------------------------------------------------------------------------- /docs/tdd_delete_customer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/docs/tdd_delete_customer.png -------------------------------------------------------------------------------- /docs/tdd_get_customer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/docs/tdd_get_customer.png -------------------------------------------------------------------------------- /docs/tdd_update_customer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/docs/tdd_update_customer.png -------------------------------------------------------------------------------- /docs/unclebobcleanarch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/docs/unclebobcleanarch.png -------------------------------------------------------------------------------- /gen_mocks.sh: -------------------------------------------------------------------------------- 1 | flutter pub run build_runner build -------------------------------------------------------------------------------- /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/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/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/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/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/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/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/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/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/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/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/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/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/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/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/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/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/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/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/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/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/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/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/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/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/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/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/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/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/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/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/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/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 | Crm 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | crm 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/core/error/failures.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | 3 | abstract class Failure extends Equatable { 4 | @override 5 | List get props => []; 6 | } 7 | 8 | class ServerFailure extends Failure {} 9 | -------------------------------------------------------------------------------- /lib/data/data_sources/implementations/api/customer_datasource_impl.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/data/data_sources/interfaces/customer_datasource.dart'; 2 | import 'package:dartz/dartz.dart'; 3 | import 'package:crm/domain/model/customer.dart'; 4 | import 'package:crm/data/entities/customer_entity.dart'; 5 | import 'package:dio/dio.dart'; 6 | 7 | const String API_BASE = "http://localhost:4000"; 8 | 9 | class CustomerDataSourceImpl implements CustomerDataSource { 10 | @override 11 | Future create(CustomerEntity data) async { 12 | await Dio().post("$API_BASE/customers", data: { 13 | "customerName": data.customerName, 14 | "emailAddress": data.emailAddress, 15 | "isActive": true, 16 | "type": "customer" 17 | }); 18 | return unit; 19 | } 20 | 21 | @override 22 | Future delete(String id) async { 23 | await Dio().delete("$API_BASE/customers/$id"); 24 | return unit; 25 | } 26 | 27 | @override 28 | Future> find({ 29 | String? customerName, 30 | CustomerType? type, 31 | String? id, 32 | String? emailAddress, 33 | bool? active, 34 | }) async { 35 | var response = await Dio().get("$API_BASE/customers"); 36 | List list = []; 37 | response.data.forEach((d) { 38 | list.add(CustomerEntity( 39 | id: d["id"], 40 | customerName: d["customerName"], 41 | emailAddress: d["emailAddress"], 42 | )); 43 | }); 44 | return list; 45 | } 46 | 47 | @override 48 | Future findOne(String id) async { 49 | var response = await Dio().get("$API_BASE/customers/$id"); 50 | CustomerEntity customer = CustomerEntity( 51 | id: response.data["id"], 52 | customerName: response.data["customerName"], 53 | emailAddress: response.data["emailAddress"], 54 | active: response.data["isActive"]); 55 | return customer; 56 | } 57 | 58 | @override 59 | Future update( 60 | String id, { 61 | String? customerName, 62 | String? emailAddress, 63 | CustomerType? type, 64 | bool? active, 65 | }) async { 66 | dynamic dataToUpdate = {}; 67 | if (customerName != null) { 68 | dataToUpdate["customerName"] = customerName; 69 | } 70 | 71 | if (emailAddress != null) { 72 | dataToUpdate["emailAddress"] = emailAddress; 73 | } 74 | 75 | if (type != null) { 76 | dataToUpdate["type"] = type; 77 | } 78 | 79 | if (active != null) { 80 | dataToUpdate["isActive"] = active; 81 | } 82 | 83 | await Dio().put("$API_BASE/customers/$id", data: dataToUpdate); 84 | 85 | return unit; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /lib/data/data_sources/implementations/api/task_datasource_impl.dart: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/lib/data/data_sources/implementations/api/task_datasource_impl.dart -------------------------------------------------------------------------------- /lib/data/data_sources/interfaces/customer_datasource.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/data/entities/customer_entity.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:dartz/dartz.dart'; 4 | 5 | abstract class CustomerDataSource { 6 | Future> find({ 7 | String? customerName, 8 | CustomerType? type, 9 | String? id, 10 | String? emailAddress, 11 | bool? active, 12 | }); 13 | Future findOne(String id); 14 | Future create(CustomerEntity data); 15 | Future delete(String id); 16 | Future update( 17 | String id, { 18 | String? customerName, 19 | String? emailAddress, 20 | CustomerType? type, 21 | bool? active, 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /lib/data/data_sources/interfaces/task_datasource.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/data/entities/task_entity.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/model/task.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | 6 | abstract class TaskDataSource { 7 | Future> find({ 8 | Customer customer, 9 | Priority priority, 10 | String subject, 11 | Status status, 12 | DateTime dueDate, 13 | }); 14 | Future findOne(String id); 15 | Future create(TaskEntity task); 16 | Future delete(String id); 17 | Future update( 18 | String id, { 19 | Customer? customer, 20 | Priority? priority, 21 | String? subject, 22 | Status? status, 23 | DateTime? dueDate, 24 | }); 25 | } 26 | -------------------------------------------------------------------------------- /lib/data/entities/customer_entity.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/domain/model/customer.dart'; 2 | import 'package:equatable/equatable.dart'; 3 | 4 | class CustomerEntity extends Equatable { 5 | final String? id; 6 | final String customerName; 7 | final String emailAddress; 8 | final CustomerType type; 9 | final bool active; 10 | 11 | const CustomerEntity({ 12 | this.id, 13 | required this.customerName, 14 | required this.emailAddress, 15 | this.active = true, 16 | this.type = CustomerType.customer, 17 | }); 18 | 19 | @override 20 | List get props { 21 | return [customerName, emailAddress, active, type]; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lib/data/entities/task_entity.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/domain/model/customer.dart'; 2 | import 'package:crm/domain/model/task.dart'; 3 | import 'package:equatable/equatable.dart'; 4 | 5 | class TaskEntity extends Equatable { 6 | final String id; 7 | final Customer customer; 8 | final Priority priority; 9 | final String subject; 10 | final Status status; 11 | final DateTime dueDate; 12 | 13 | const TaskEntity({ 14 | required this.id, 15 | required this.customer, 16 | this.priority = Priority.high, 17 | this.status = Status.notStarted, 18 | required this.subject, 19 | required this.dueDate, 20 | }); 21 | 22 | @override 23 | List get props { 24 | return [id, customer, priority, subject, dueDate]; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib/domain/model/customer.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | enum CustomerType { 5 | lead, 6 | customer, 7 | } 8 | 9 | @immutable 10 | class Customer extends Equatable { 11 | final String? id; 12 | final String name; 13 | final String email; 14 | final CustomerType customerType; 15 | final bool isActive; 16 | 17 | const Customer({ 18 | this.id, 19 | required this.name, 20 | required this.email, 21 | this.isActive = true, 22 | this.customerType = CustomerType.customer, 23 | }); 24 | 25 | dynamic toJson() => { 26 | 'id': id, 27 | 'name': name, 28 | 'email': email, 29 | 'isActive': isActive, 30 | "customerType": customerType, 31 | }; 32 | 33 | @override 34 | String toString() { 35 | return toJson().toString(); 36 | } 37 | 38 | @override 39 | List get props { 40 | return [name, email, isActive, customerType]; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /lib/domain/model/task.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/domain/model/customer.dart'; 2 | import 'package:equatable/equatable.dart'; 3 | 4 | enum Status { notStarted, deferred, inProgress, completed, waitingForInput } 5 | 6 | enum Priority { low, normal, high } 7 | 8 | class CRMTask extends Equatable { 9 | final String id; 10 | final Customer customer; 11 | final Priority priority; 12 | final String subject; 13 | final Status status; 14 | final DateTime dueDate; 15 | 16 | const CRMTask({ 17 | required this.id, 18 | required this.customer, 19 | this.priority = Priority.high, 20 | this.status = Status.notStarted, 21 | required this.subject, 22 | required this.dueDate, 23 | }); 24 | @override 25 | List get props { 26 | return [id, customer, priority, subject, dueDate]; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/domain/repositories/implementations/customer_repository_impl.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/data/data_sources/interfaces/customer_datasource.dart'; 2 | import 'package:crm/data/entities/customer_entity.dart'; 3 | import 'package:crm/domain/model/customer.dart'; 4 | import 'package:crm/core/error/failures.dart'; 5 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 6 | import 'package:dartz/dartz.dart'; 7 | import 'package:flutter/material.dart'; 8 | 9 | class CustomerRepositoryImpl implements CustomerRepository { 10 | CustomerDataSource customerDataSource; 11 | CustomerRepositoryImpl(this.customerDataSource); 12 | 13 | @override 14 | Future> createCustomer(Customer data) async { 15 | try { 16 | final result = await customerDataSource.create(CustomerEntity( 17 | customerName: data.name, 18 | emailAddress: data.email, 19 | active: data.isActive, 20 | type: data.customerType, 21 | )); 22 | return Right(result); 23 | } catch (e) { 24 | debugPrint(e.toString()); 25 | return Left(ServerFailure()); 26 | } 27 | } 28 | 29 | @override 30 | Future> deleteCustomer(String id) async { 31 | try { 32 | final result = await customerDataSource.delete(id); 33 | return Right(result); 34 | } catch (e) { 35 | return Left(ServerFailure()); 36 | } 37 | } 38 | 39 | @override 40 | Future>> getAllCustomers(CustomerType customerType) async { 41 | try { 42 | List result = await customerDataSource.find(type: customerType); 43 | return Right(result 44 | .map((e) => Customer( 45 | id: e.id, 46 | name: e.customerName, 47 | email: e.emailAddress, 48 | )) 49 | .toList()); 50 | } catch (e) { 51 | debugPrint(e.toString()); 52 | return Left(ServerFailure()); 53 | } 54 | } 55 | 56 | @override 57 | Future> updateCustomer( 58 | String id, { 59 | String? name, 60 | String? email, 61 | CustomerType? customerType, 62 | bool? isActive, 63 | }) async { 64 | try { 65 | final result = await customerDataSource.update(id, customerName: name, emailAddress: email, active: isActive); 66 | return Right(result); 67 | } catch (e) { 68 | return Left(ServerFailure()); 69 | } 70 | } 71 | 72 | @override 73 | Future> getCustomer(String id) async { 74 | try { 75 | final result = await customerDataSource.findOne(id); 76 | return Right(Customer( 77 | id: result.id, 78 | email: result.emailAddress, 79 | name: result.customerName, 80 | isActive: result.active, 81 | )); 82 | } catch (e) { 83 | return Left(ServerFailure()); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /lib/domain/repositories/implementations/task_repository_impl.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/data/data_sources/interfaces/task_datasource.dart'; 2 | import 'package:crm/data/entities/task_entity.dart'; 3 | import 'package:crm/domain/model/task.dart'; 4 | import 'package:crm/domain/model/customer.dart'; 5 | import 'package:crm/core/error/failures.dart'; 6 | import 'package:crm/domain/repositories/interfaces/task_repository.dart'; 7 | import 'package:dartz/dartz.dart'; 8 | 9 | class TaskRepositoryImpl implements TaskRepository { 10 | TaskDataSource taskDataSource; 11 | TaskRepositoryImpl(this.taskDataSource); 12 | 13 | @override 14 | Future> createTask(CRMTask task) async { 15 | try { 16 | final result = await taskDataSource.create(TaskEntity( 17 | id: task.id, 18 | customer: task.customer, 19 | subject: task.subject, 20 | dueDate: task.dueDate, 21 | )); 22 | return Right(result); 23 | } catch (e) { 24 | return Left(ServerFailure()); 25 | } 26 | } 27 | 28 | @override 29 | Future> deleteTask(String id) async { 30 | try { 31 | final result = await taskDataSource.delete(id); 32 | return Right(result); 33 | } catch (e) { 34 | return Left(ServerFailure()); 35 | } 36 | } 37 | 38 | @override 39 | Future>> getAllTasks() async { 40 | try { 41 | final result = await taskDataSource.find(); 42 | return Right(result 43 | .map((e) => CRMTask( 44 | id: e.id, 45 | subject: e.subject, 46 | customer: e.customer, 47 | dueDate: e.dueDate, 48 | priority: e.priority, 49 | )) 50 | .toList()); 51 | } catch (e) { 52 | return Left(ServerFailure()); 53 | } 54 | } 55 | 56 | @override 57 | Future> updateTask( 58 | String id, { 59 | Customer? customer, 60 | Priority? priority, 61 | String? subject, 62 | Status? status, 63 | DateTime? dueDate, 64 | }) async { 65 | try { 66 | final result = await taskDataSource.update( 67 | id, 68 | customer: customer, 69 | priority: priority, 70 | subject: subject, 71 | status: status, 72 | dueDate: dueDate, 73 | ); 74 | return Right(result); 75 | } catch (e) { 76 | return Left(ServerFailure()); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /lib/domain/repositories/interfaces/customer_repository.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | 4 | import "package:dartz/dartz.dart"; 5 | 6 | abstract class CustomerRepository { 7 | Future>> getAllCustomers(CustomerType customerType); 8 | Future> getCustomer(String id); 9 | Future> createCustomer(Customer data); 10 | Future> deleteCustomer(String id); 11 | Future> updateCustomer( 12 | String id, { 13 | String? name, 14 | String? email, 15 | CustomerType? customerType, 16 | bool? isActive, 17 | }); 18 | } 19 | -------------------------------------------------------------------------------- /lib/domain/repositories/interfaces/task_repository.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/model/task.dart'; 4 | 5 | import "package:dartz/dartz.dart"; 6 | 7 | abstract class TaskRepository { 8 | Future>> getAllTasks(); 9 | Future> createTask(CRMTask data); 10 | Future> deleteTask(String id); 11 | Future> updateTask( 12 | String id, { 13 | Customer? customer, 14 | Priority? priority, 15 | String? subject, 16 | Status? status, 17 | DateTime? dueDate, 18 | }); 19 | } 20 | -------------------------------------------------------------------------------- /lib/domain/use_cases/customer/create_customer.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | 6 | abstract class CreateCustomer { 7 | Future> execute(Customer customer); 8 | } 9 | 10 | class CreateCustomerImpl implements CreateCustomer { 11 | final CustomerRepository customerRepository; 12 | CreateCustomerImpl(this.customerRepository); 13 | 14 | @override 15 | Future> execute(Customer customer) async { 16 | return await customerRepository.createCustomer(customer); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lib/domain/use_cases/customer/delete_customer.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 3 | import 'package:dartz/dartz.dart'; 4 | 5 | abstract class DeleteCustomer { 6 | Future> execute(String customerId); 7 | } 8 | 9 | class DeleteCustomerImpl implements DeleteCustomer { 10 | CustomerRepository customerRepository; 11 | DeleteCustomerImpl(this.customerRepository); 12 | 13 | @override 14 | Future> execute(String customerId) async { 15 | return await customerRepository.deleteCustomer(customerId); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /lib/domain/use_cases/customer/get_all_customers.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | 6 | abstract class GetAllCustomers { 7 | Future>> execute(); 8 | } 9 | 10 | class GetAllCustomersImpl implements GetAllCustomers { 11 | final CustomerRepository customerRepository; 12 | 13 | GetAllCustomersImpl(this.customerRepository); 14 | 15 | @override 16 | Future>> execute() async { 17 | var result = await customerRepository.getAllCustomers(CustomerType.customer); 18 | return result; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/domain/use_cases/customer/get_customer.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | 6 | abstract class GetCustomer { 7 | Future> execute(String customerId); 8 | } 9 | 10 | class GetCustomerImpl implements GetCustomer { 11 | CustomerRepository customerRepository; 12 | GetCustomerImpl(this.customerRepository); 13 | 14 | @override 15 | Future> execute(String customerId) async { 16 | final result = await customerRepository.getCustomer(customerId); 17 | return result; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/domain/use_cases/customer/make_customer_active.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 3 | import 'package:dartz/dartz.dart'; 4 | 5 | abstract class MakeCustomerActive { 6 | Future> execute(String customerId); 7 | } 8 | 9 | class MakeCustomerActiveImpl implements MakeCustomerActive { 10 | CustomerRepository customerRepository; 11 | 12 | MakeCustomerActiveImpl(this.customerRepository); 13 | 14 | @override 15 | Future> execute(String customerId) async { 16 | final result = await customerRepository.updateCustomer(customerId, isActive: true); 17 | return result; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/domain/use_cases/customer/make_customer_inactive.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 3 | import 'package:dartz/dartz.dart'; 4 | 5 | abstract class MakeCustomerInActive { 6 | Future> execute(String customerId); 7 | } 8 | 9 | class MakeCustomerInActiveImpl implements MakeCustomerInActive { 10 | CustomerRepository customerRepository; 11 | MakeCustomerInActiveImpl(this.customerRepository); 12 | 13 | @override 14 | Future> execute(String customerId) async { 15 | final result = await customerRepository.updateCustomer(customerId, isActive: false); 16 | return result; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lib/domain/use_cases/customer/update_customer_details.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 3 | import 'package:dartz/dartz.dart'; 4 | 5 | abstract class UpdateCustomer { 6 | Future> execute(String customerId, {String? name, String? email, bool? isActive}); 7 | } 8 | 9 | class UpdateCustomerImpl implements UpdateCustomer { 10 | CustomerRepository customerRepository; 11 | UpdateCustomerImpl(this.customerRepository); 12 | 13 | @override 14 | Future> execute(String customerId, {String? name, String? email, bool? isActive}) async { 15 | final result = await customerRepository.updateCustomer(customerId, name: name, email: email, isActive: isActive); 16 | return result; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lib/domain/use_cases/lead/convert_lead_to_customer.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | 6 | abstract class ConvertLeadToCustomer { 7 | Future> execute(String leadId); 8 | } 9 | 10 | class ConvertLeadToCustomerImpl implements ConvertLeadToCustomer { 11 | CustomerRepository customerRepository; 12 | ConvertLeadToCustomerImpl(this.customerRepository); 13 | 14 | @override 15 | Future> execute(String leadId) async { 16 | final result = await customerRepository.updateCustomer(leadId, customerType: CustomerType.lead); 17 | return result; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/domain/use_cases/lead/create_lead.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | 6 | abstract class CreateLead { 7 | Future> execute(Customer customer); 8 | } 9 | 10 | class CreateLeadImpl implements CreateLead { 11 | CustomerRepository customerRepository; 12 | CreateLeadImpl(this.customerRepository); 13 | 14 | @override 15 | Future> execute(Customer customer) async { 16 | final result = await customerRepository.createCustomer(customer); 17 | return result; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/domain/use_cases/lead/delete_lead.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 3 | import 'package:dartz/dartz.dart'; 4 | 5 | abstract class DeleteLead { 6 | Future> execute(String leadId); 7 | } 8 | 9 | class DeleteLeadImpl implements DeleteLead { 10 | CustomerRepository customerRepository; 11 | DeleteLeadImpl(this.customerRepository); 12 | 13 | @override 14 | Future> execute(String leadId) async { 15 | final result = await customerRepository.deleteCustomer(leadId); 16 | return result; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lib/domain/use_cases/lead/get_all_leads.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | 6 | abstract class GetAllLeads { 7 | Future>> execute(); 8 | } 9 | 10 | class GetAllLeadsImpl implements GetAllLeads { 11 | CustomerRepository customerRepository; 12 | GetAllLeadsImpl(this.customerRepository); 13 | @override 14 | Future>> execute() async { 15 | final result = await customerRepository.getAllCustomers(CustomerType.lead); 16 | return result; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lib/domain/use_cases/lead/get_lead.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | 6 | abstract class GetLead { 7 | Future> execute(String leadId); 8 | } 9 | 10 | class GetLeadImpl implements GetLead { 11 | CustomerRepository customerRepository; 12 | GetLeadImpl(this.customerRepository); 13 | 14 | @override 15 | Future> execute(String leadId) async { 16 | final result = await customerRepository.getCustomer(leadId); 17 | return result; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/domain/use_cases/lead/update_lead_details.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | 6 | abstract class UpdateLead { 7 | Future> execute( 8 | String leadId, { 9 | String? name, 10 | String? email, 11 | CustomerType? customerType, 12 | bool? isActive, 13 | }); 14 | } 15 | 16 | class UpdateLeadImpl implements UpdateLead { 17 | CustomerRepository customerRepository; 18 | UpdateLeadImpl(this.customerRepository); 19 | 20 | @override 21 | Future> execute( 22 | String leadId, { 23 | String? name, 24 | String? email, 25 | CustomerType? customerType, 26 | bool? isActive, 27 | }) async { 28 | final result = await customerRepository.updateCustomer( 29 | leadId, 30 | name: name, 31 | email: email, 32 | customerType: customerType, 33 | isActive: isActive, 34 | ); 35 | return result; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/domain/use_cases/task/create_task.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/task.dart'; 3 | import 'package:crm/domain/repositories/interfaces/task_repository.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | 6 | abstract class CreateTask { 7 | Future> execute(CRMTask task); 8 | } 9 | 10 | class CreateTaskImpl implements CreateTask { 11 | TaskRepository taskRepository; 12 | CreateTaskImpl(this.taskRepository); 13 | 14 | @override 15 | Future> execute(CRMTask task) async { 16 | final result = await taskRepository.createTask(task); 17 | return result; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/domain/use_cases/task/delete_task.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/repositories/interfaces/task_repository.dart'; 3 | import 'package:dartz/dartz.dart'; 4 | 5 | abstract class DeleteTask { 6 | Future> execute(String id); 7 | } 8 | 9 | class DeleteTaskImpl implements DeleteTask { 10 | TaskRepository taskRepository; 11 | DeleteTaskImpl(this.taskRepository); 12 | 13 | @override 14 | Future> execute(String id) async { 15 | final result = await taskRepository.deleteTask(id); 16 | return result; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lib/domain/use_cases/task/mark_task_as_completed.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/task.dart'; 3 | import 'package:crm/domain/repositories/interfaces/task_repository.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | 6 | abstract class MarkTaskAsComplete { 7 | Future> execute(String id); 8 | } 9 | 10 | class MarkTaskAsCompleteImpl implements MarkTaskAsComplete { 11 | TaskRepository taskRepository; 12 | MarkTaskAsCompleteImpl(this.taskRepository); 13 | 14 | @override 15 | Future> execute(String id) async { 16 | final result = await taskRepository.updateTask(id, status: Status.completed); 17 | return result; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/domain/use_cases/task/update_task.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/model/task.dart'; 4 | import 'package:crm/domain/repositories/interfaces/task_repository.dart'; 5 | import 'package:dartz/dartz.dart'; 6 | 7 | abstract class UpdateTask { 8 | Future> execute( 9 | String id, { 10 | Customer? customer, 11 | Priority? priority, 12 | String? subject, 13 | Status? status, 14 | DateTime? dueDate, 15 | }); 16 | } 17 | 18 | class UpdateTaskImpl implements UpdateTask { 19 | TaskRepository taskRepository; 20 | UpdateTaskImpl(this.taskRepository); 21 | 22 | @override 23 | Future> execute( 24 | String id, { 25 | Customer? customer, 26 | Priority? priority, 27 | String? subject, 28 | Status? status, 29 | DateTime? dueDate, 30 | }) async { 31 | final result = await taskRepository.updateTask( 32 | id, 33 | customer: customer, 34 | priority: priority, 35 | dueDate: dueDate, 36 | status: status, 37 | subject: subject, 38 | ); 39 | return result; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/presentation/views/customer/list.dart'; 2 | import 'package:crm/presentation/views/models/screen.dart'; 3 | import 'package:crm/presentation/views/task/list.dart'; 4 | import 'package:flutter/material.dart'; 5 | import 'package:flutter_hooks/flutter_hooks.dart'; 6 | 7 | void main() { 8 | runApp(const CRMApp()); 9 | } 10 | 11 | class CRMApp extends StatelessWidget { 12 | const CRMApp({super.key}); 13 | 14 | @override 15 | Widget build(BuildContext context) => MaterialApp( 16 | debugShowCheckedModeBanner: false, 17 | darkTheme: ThemeData.dark(), 18 | themeMode: ThemeMode.dark, 19 | home: AppContainer(), 20 | ); 21 | } 22 | 23 | class AppContainer extends HookWidget { 24 | AppContainer({super.key}); 25 | 26 | final screens = [ 27 | Screen(title: "Customers", widget: const CustomerList(), icon: const Icon(Icons.person)), 28 | Screen(title: "Tasks", widget: const TaskList(), icon: const Icon(Icons.task)), 29 | ]; 30 | 31 | @override 32 | Widget build(BuildContext context) { 33 | final selectedIndex = useState(0); 34 | return Scaffold( 35 | body: screens.elementAt(selectedIndex.value).widget, 36 | bottomNavigationBar: BottomNavigationBar( 37 | currentIndex: selectedIndex.value, 38 | onTap: (index) => selectedIndex.value = index, 39 | items: screens.map((screen) => BottomNavigationBarItem(icon: screen.icon, label: screen.title)).toList(), 40 | ), 41 | ); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /lib/presentation/components/delete_button.dart: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/presentation/components/edit_button.dart: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/lib/presentation/components/edit_button.dart -------------------------------------------------------------------------------- /lib/presentation/components/list.dart: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/presentation/components/list_item.dart: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/presentation/components/toolbar.dart: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/lib/presentation/components/toolbar.dart -------------------------------------------------------------------------------- /lib/presentation/view_models/another_vm/custom_hook.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_hooks/flutter_hooks.dart'; 3 | 4 | class CounterModel { 5 | int counter; 6 | Function(int incrAmount) increment; 7 | CounterModel({ 8 | required this.counter, 9 | required this.increment, 10 | }); 11 | } 12 | 13 | class CounterHook extends Hook { 14 | @override 15 | HookState> createState() { 16 | return CounterHookState(); 17 | } 18 | } 19 | 20 | class CounterHookState extends HookState { 21 | int counter = 0; 22 | 23 | @override 24 | void initHook() { 25 | setState(() { 26 | counter = 0; 27 | }); 28 | super.initHook(); 29 | } 30 | 31 | void increment(int incrAmount) { 32 | setState(() { 33 | counter = counter + incrAmount; 34 | }); 35 | } 36 | 37 | @override 38 | CounterModel build(BuildContext context) { 39 | return CounterModel(counter: counter, increment: increment); 40 | } 41 | } 42 | 43 | CounterModel useCounter(BuildContext context) { 44 | return use(CounterHook()); 45 | } 46 | -------------------------------------------------------------------------------- /lib/presentation/view_models/customer/detail.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/use_cases/customer/delete_customer.dart'; 4 | import 'package:crm/domain/use_cases/customer/get_customer.dart'; 5 | import 'package:flutter_hooks/flutter_hooks.dart'; 6 | 7 | class CustomerDetailViewModel { 8 | Customer data; 9 | String error; 10 | Function(String id) fetchCustomerData; 11 | Function(String id) deleteCustomer; 12 | CustomerDetailViewModel({ 13 | required this.data, 14 | required this.fetchCustomerData, 15 | required this.deleteCustomer, 16 | required this.error, 17 | }); 18 | } 19 | 20 | CustomerDetailViewModel useCustomerDetailViewModel({ 21 | required GetCustomer getCustomerUseCase, 22 | required DeleteCustomer deleteCustomerUseCase, 23 | }) { 24 | final customer = useState(const Customer(id: "", name: "", email: "")); 25 | final error = useState(""); 26 | 27 | void fetchCustomerData(String id) async { 28 | error.value = ""; 29 | var result = await getCustomerUseCase.execute(id); 30 | result.fold((failure) { 31 | if (failure == ServerFailure()) { 32 | error.value = "Error Fetching Customer!"; 33 | } 34 | }, (data) { 35 | customer.value = data; 36 | }); 37 | } 38 | 39 | void deleteCustomer(String id) async { 40 | error.value = ""; 41 | var result = await deleteCustomerUseCase.execute(id); 42 | result.fold((failure) { 43 | if (failure == ServerFailure()) { 44 | error.value = "Error Deleting Customer!"; 45 | } 46 | }, (data) { 47 | // customer.value = data; 48 | }); 49 | } 50 | 51 | return CustomerDetailViewModel( 52 | data: customer.value, 53 | fetchCustomerData: fetchCustomerData, 54 | deleteCustomer: deleteCustomer, 55 | error: error.value, 56 | ); 57 | } 58 | -------------------------------------------------------------------------------- /lib/presentation/view_models/customer/edit.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/use_cases/customer/get_customer.dart'; 4 | import 'package:crm/domain/use_cases/customer/update_customer_details.dart'; 5 | import 'package:flutter_hooks/flutter_hooks.dart'; 6 | 7 | class CustomerEditViewModel { 8 | Customer data; 9 | String error; 10 | Function(String id) fetchCustomerData; 11 | Function({String name, String? email, bool? isActive}) saveCustomerData; 12 | CustomerEditViewModel({ 13 | required this.data, 14 | required this.fetchCustomerData, 15 | required this.error, 16 | required this.saveCustomerData, 17 | }); 18 | } 19 | 20 | CustomerEditViewModel useCustomerEditViewModel({ 21 | required GetCustomer getCustomer, 22 | required UpdateCustomer updateCustomer, 23 | }) { 24 | final customer = useState(const Customer(id: "", name: "", email: "")); 25 | final error = useState(""); 26 | 27 | void fetchCustomerData(String id) async { 28 | var result = await getCustomer.execute(id); 29 | result.fold((failure) { 30 | if (failure == ServerFailure()) { 31 | error.value = "Error Fetching Customer!"; 32 | } 33 | }, (data) { 34 | customer.value = data; 35 | }); 36 | } 37 | 38 | void saveCustomerData({String? name, String? email, bool? isActive}) async { 39 | var result = await updateCustomer.execute( 40 | customer.value.id!, 41 | name: name != customer.value.name ? name : null, 42 | email: email != customer.value.email ? email : null, 43 | isActive: isActive != customer.value.isActive ? isActive : null, 44 | ); 45 | result.fold((failure) { 46 | if (failure == ServerFailure()) { 47 | error.value = "Error Saving Customer Data!"; 48 | } 49 | }, (data) {}); 50 | } 51 | 52 | return CustomerEditViewModel( 53 | fetchCustomerData: (String id) { 54 | fetchCustomerData(id); 55 | }, 56 | saveCustomerData: saveCustomerData, 57 | data: customer.value, 58 | error: error.value); 59 | } 60 | -------------------------------------------------------------------------------- /lib/presentation/view_models/customer/list.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/use_cases/customer/get_all_customers.dart'; 4 | import 'package:flutter_hooks/flutter_hooks.dart'; 5 | 6 | class CustomerListViewModel { 7 | List data; 8 | String error; 9 | Function fetchData; 10 | CustomerListViewModel({required this.data, required this.fetchData, required this.error}); 11 | } 12 | 13 | CustomerListViewModel useCustomerListViewModel({required GetAllCustomers getAllCustomers}) { 14 | final customers = useState>([]); 15 | final error = useState(""); 16 | 17 | void fetchData() async { 18 | error.value = ""; 19 | var result = await getAllCustomers.execute(); 20 | result.fold((failure) { 21 | if (failure == ServerFailure()) { 22 | error.value = "Error Fetching Customers!"; 23 | } 24 | }, (data) { 25 | customers.value = data; 26 | }); 27 | } 28 | 29 | return CustomerListViewModel(fetchData: fetchData, data: customers.value, error: error.value); 30 | } 31 | -------------------------------------------------------------------------------- /lib/presentation/view_models/customer/new.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/use_cases/customer/create_customer.dart'; 4 | import 'package:flutter_hooks/flutter_hooks.dart'; 5 | 6 | class CustomerNewViewModel { 7 | Customer data; 8 | String error; 9 | Function({required String name, required String email}) saveCustomerData; 10 | CustomerNewViewModel({ 11 | required this.data, 12 | required this.saveCustomerData, 13 | required this.error, 14 | }); 15 | } 16 | 17 | CustomerNewViewModel useCustomerNewViewModel({required CreateCustomer createCustomer}) { 18 | final customer = useState(const Customer(id: "", name: "", email: "")); 19 | final error = useState(""); 20 | void saveCustomerData({required String name, required String email}) async { 21 | var result = await createCustomer.execute(Customer(name: name, email: email)); 22 | result.fold((failure) { 23 | if (failure == ServerFailure()) { 24 | error.value = "Error Saving Customer Data!"; 25 | } 26 | }, (data) {}); 27 | } 28 | 29 | return CustomerNewViewModel( 30 | data: customer.value, 31 | saveCustomerData: saveCustomerData, 32 | error: error.value, 33 | ); 34 | } 35 | -------------------------------------------------------------------------------- /lib/presentation/view_models/task/detail.dart: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/presentation/view_models/task/edit.dart: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/lib/presentation/view_models/task/edit.dart -------------------------------------------------------------------------------- /lib/presentation/view_models/task/list.dart: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/presentation/view_models/task/new.dart: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/lib/presentation/view_models/task/new.dart -------------------------------------------------------------------------------- /lib/presentation/views/customer/detail.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/data/data_sources/implementations/api/customer_datasource_impl.dart'; 2 | import 'package:crm/domain/repositories/implementations/customer_repository_impl.dart'; 3 | import 'package:crm/domain/use_cases/customer/delete_customer.dart'; 4 | import 'package:crm/domain/use_cases/customer/get_customer.dart'; 5 | import 'package:crm/presentation/view_models/customer/detail.dart'; 6 | import 'package:crm/presentation/views/customer/edit.dart'; 7 | import 'package:flutter/material.dart'; 8 | import 'package:flutter_hooks/flutter_hooks.dart'; 9 | 10 | class CustomerDetail extends HookWidget { 11 | const CustomerDetail(this.id, {super.key}); 12 | final String id; 13 | 14 | @override 15 | Widget build(BuildContext context) { 16 | final vm = useCustomerDetailViewModel( 17 | getCustomerUseCase: GetCustomerImpl(CustomerRepositoryImpl(CustomerDataSourceImpl())), 18 | deleteCustomerUseCase: DeleteCustomerImpl(CustomerRepositoryImpl(CustomerDataSourceImpl())), 19 | ); 20 | 21 | useEffect(() { 22 | vm.fetchCustomerData(id); 23 | return () {}; 24 | }, []); 25 | 26 | return Scaffold( 27 | appBar: AppBar( 28 | title: const Text('Customer Edit'), 29 | actions: [ 30 | TextButton( 31 | child: const Text("Edit"), 32 | onPressed: () { 33 | Navigator.push( 34 | context, 35 | MaterialPageRoute(builder: (context) => CustomerEdit(vm.data.id!)), 36 | ).then((value) { 37 | vm.fetchCustomerData(id); 38 | }); 39 | }, 40 | ) 41 | ], 42 | ), 43 | body: Padding( 44 | padding: const EdgeInsets.all(16.0), 45 | child: Column( 46 | crossAxisAlignment: CrossAxisAlignment.start, 47 | children: [ 48 | ListTile( 49 | title: Text(vm.data.name), 50 | ), 51 | ListTile( 52 | title: Text(vm.data.email), 53 | ), 54 | SwitchListTile( 55 | title: const Text("Active"), 56 | value: vm.data.isActive, 57 | onChanged: (value) {}, 58 | ), 59 | OutlinedButton( 60 | onPressed: () { 61 | vm.deleteCustomer(vm.data.id!); 62 | Navigator.pop(context); 63 | }, 64 | child: const Text('Delete'), 65 | ) 66 | ], 67 | ), 68 | )); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /lib/presentation/views/customer/edit.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/data/data_sources/implementations/api/customer_datasource_impl.dart'; 2 | import 'package:crm/domain/repositories/implementations/customer_repository_impl.dart'; 3 | import 'package:crm/domain/use_cases/customer/get_all_customers.dart'; 4 | import 'package:crm/domain/use_cases/customer/get_customer.dart'; 5 | import 'package:crm/domain/use_cases/customer/update_customer_details.dart'; 6 | import 'package:crm/presentation/view_models/customer/edit.dart'; 7 | import 'package:flutter/material.dart'; 8 | import 'package:flutter_hooks/flutter_hooks.dart'; 9 | 10 | class CustomerEdit extends HookWidget { 11 | const CustomerEdit(this.id, {super.key}); 12 | final String id; 13 | 14 | @override 15 | Widget build(BuildContext context) { 16 | final vm = useCustomerEditViewModel( 17 | getCustomer: GetCustomerImpl(CustomerRepositoryImpl(CustomerDataSourceImpl())), 18 | updateCustomer: UpdateCustomerImpl(CustomerRepositoryImpl(CustomerDataSourceImpl())), 19 | ); 20 | final nameController = useTextEditingController(); 21 | final emailController = useTextEditingController(); 22 | final isActive = useState(false); 23 | 24 | useEffect(() { 25 | vm.fetchCustomerData(id); 26 | return () {}; 27 | }, []); 28 | 29 | useEffect(() { 30 | nameController.text = vm.data.name; 31 | emailController.text = vm.data.email; 32 | isActive.value = vm.data.isActive; 33 | return () {}; 34 | }, [vm.data.id]); 35 | 36 | return Scaffold( 37 | appBar: AppBar( 38 | title: const Text('Customer Edit'), 39 | actions: [ 40 | IconButton( 41 | icon: const Icon(Icons.save), 42 | onPressed: () { 43 | vm.saveCustomerData( 44 | name: nameController.text, 45 | email: emailController.text, 46 | isActive: isActive.value, 47 | ); 48 | Navigator.pop(context); 49 | }, 50 | ) 51 | ], 52 | ), 53 | body: Padding( 54 | padding: const EdgeInsets.all(16.0), 55 | child: Column( 56 | crossAxisAlignment: CrossAxisAlignment.start, 57 | children: [ 58 | TextField(controller: nameController), 59 | TextField(controller: emailController), 60 | SwitchListTile( 61 | title: const Text("Active"), 62 | value: isActive.value, 63 | onChanged: (value) { 64 | isActive.value = value; 65 | }, 66 | ) 67 | ], 68 | ), 69 | )); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /lib/presentation/views/customer/list.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/data/data_sources/implementations/api/customer_datasource_impl.dart'; 2 | import 'package:crm/domain/repositories/implementations/customer_repository_impl.dart'; 3 | import 'package:crm/domain/use_cases/customer/get_all_customers.dart'; 4 | import 'package:crm/presentation/view_models/customer/list.dart'; 5 | import 'package:crm/presentation/views/customer/detail.dart'; 6 | import 'package:crm/presentation/views/customer/new.dart'; 7 | import 'package:flutter/material.dart'; 8 | import 'package:flutter_hooks/flutter_hooks.dart'; 9 | 10 | class CustomerList extends HookWidget { 11 | const CustomerList({super.key}); 12 | 13 | @override 14 | Widget build(BuildContext context) { 15 | final vm = useCustomerListViewModel( 16 | getAllCustomers: GetAllCustomersImpl(CustomerRepositoryImpl(CustomerDataSourceImpl())), 17 | ); 18 | 19 | useEffect(() { 20 | vm.fetchData(); 21 | 22 | return () {}; 23 | }, []); 24 | 25 | return Scaffold( 26 | appBar: AppBar( 27 | title: const Text('Customers'), 28 | actions: [ 29 | IconButton( 30 | icon: const Icon(Icons.add), 31 | onPressed: () { 32 | Navigator.push( 33 | context, 34 | MaterialPageRoute(builder: (context) => const CustomerNew()), 35 | ).then((value) { 36 | vm.fetchData(); 37 | }); 38 | }, 39 | ) 40 | ], 41 | ), 42 | body: vm.error.isNotEmpty 43 | ? Center( 44 | child: Text( 45 | vm.error, 46 | style: const TextStyle(color: Colors.redAccent), 47 | )) 48 | : ListView.builder( 49 | itemCount: vm.data.length, 50 | itemBuilder: (context, index) { 51 | return ListTile( 52 | onTap: () { 53 | Navigator.push( 54 | context, 55 | MaterialPageRoute(builder: (context) => CustomerDetail(vm.data[index].id!)), 56 | ).then((value) { 57 | vm.fetchData(); 58 | }); 59 | }, 60 | title: Text(vm.data[index].name)); 61 | }, 62 | ), 63 | ); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /lib/presentation/views/customer/new.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/data/data_sources/implementations/api/customer_datasource_impl.dart'; 2 | import 'package:crm/domain/repositories/implementations/customer_repository_impl.dart'; 3 | import 'package:crm/domain/use_cases/customer/create_customer.dart'; 4 | import 'package:crm/presentation/view_models/customer/new.dart'; 5 | import 'package:flutter/material.dart'; 6 | import 'package:flutter_hooks/flutter_hooks.dart'; 7 | 8 | class CustomerNew extends HookWidget { 9 | const CustomerNew({super.key}); 10 | 11 | @override 12 | Widget build(BuildContext context) { 13 | final vm = useCustomerNewViewModel( 14 | createCustomer: CreateCustomerImpl(CustomerRepositoryImpl(CustomerDataSourceImpl())), 15 | ); 16 | final nameController = useTextEditingController(); 17 | final emailController = useTextEditingController(); 18 | 19 | return Scaffold( 20 | appBar: AppBar( 21 | title: const Text('New Customer'), 22 | actions: [ 23 | IconButton( 24 | icon: const Icon(Icons.save), 25 | onPressed: () { 26 | vm.saveCustomerData(name: nameController.text, email: emailController.text); 27 | Navigator.pop(context); 28 | }, 29 | ) 30 | ], 31 | ), 32 | body: Padding( 33 | padding: const EdgeInsets.all(16.0), 34 | child: vm.error.isEmpty ? buildList(nameController, emailController) : buildError(vm)), 35 | ); 36 | } 37 | 38 | Center buildError(CustomerNewViewModel vm) { 39 | return Center( 40 | child: Text(vm.error), 41 | ); 42 | } 43 | 44 | Column buildList(TextEditingController nameController, TextEditingController emailController) { 45 | return Column( 46 | children: [ 47 | TextField( 48 | decoration: const InputDecoration(hintText: "Name"), 49 | controller: nameController, 50 | ), 51 | TextField( 52 | keyboardType: TextInputType.emailAddress, 53 | decoration: const InputDecoration(hintText: "Email"), 54 | controller: emailController, 55 | ) 56 | ], 57 | ); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /lib/presentation/views/models/screen.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class Screen { 4 | final String title; 5 | final Widget widget; 6 | final Icon icon; 7 | 8 | Screen({ 9 | required this.title, 10 | required this.widget, 11 | required this.icon, 12 | }); 13 | } 14 | -------------------------------------------------------------------------------- /lib/presentation/views/task/detail.dart: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/lib/presentation/views/task/detail.dart -------------------------------------------------------------------------------- /lib/presentation/views/task/edit.dart: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/lib/presentation/views/task/edit.dart -------------------------------------------------------------------------------- /lib/presentation/views/task/list.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/presentation/view_models/another_vm/custom_hook.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_hooks/flutter_hooks.dart'; 4 | 5 | class TaskList extends HookWidget { 6 | const TaskList({super.key}); 7 | 8 | @override 9 | Widget build(BuildContext context) { 10 | final vm = useCounter(context); 11 | 12 | return Scaffold( 13 | appBar: AppBar( 14 | title: const Text('Tasks'), 15 | actions: [ 16 | IconButton( 17 | icon: const Icon(Icons.add), 18 | onPressed: () { 19 | vm.increment(5); 20 | }, 21 | ) 22 | ], 23 | ), 24 | body: Center( 25 | child: Text(vm.counter.toString()), 26 | ), 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/presentation/views/task/new.dart: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/lib/presentation/views/task/new.dart -------------------------------------------------------------------------------- /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 "crm") 8 | # The unique GTK application identifier for this application. See: 9 | # https://wiki.gnome.org/HowDoI/ChooseApplicationID 10 | set(APPLICATION_ID "za.co.nanosoft.crm") 11 | 12 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 13 | # versions of CMake. 14 | cmake_policy(SET CMP0063 NEW) 15 | 16 | # Load bundled libraries from the lib/ directory relative to the binary. 17 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") 18 | 19 | # Root filesystem for cross-building. 20 | if(FLUTTER_TARGET_PLATFORM_SYSROOT) 21 | set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) 22 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) 23 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 24 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 25 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 26 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 27 | endif() 28 | 29 | # Define build configuration options. 30 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 31 | set(CMAKE_BUILD_TYPE "Debug" CACHE 32 | STRING "Flutter build mode" FORCE) 33 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 34 | "Debug" "Profile" "Release") 35 | endif() 36 | 37 | # Compilation settings that should be applied to most targets. 38 | # 39 | # Be cautious about adding new options here, as plugins use this function by 40 | # default. In most cases, you should add new options to specific targets instead 41 | # of modifying this function. 42 | function(APPLY_STANDARD_SETTINGS TARGET) 43 | target_compile_features(${TARGET} PUBLIC cxx_std_14) 44 | target_compile_options(${TARGET} PRIVATE -Wall -Werror) 45 | target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") 46 | target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") 47 | endfunction() 48 | 49 | # Flutter library and tool build rules. 50 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 51 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 52 | 53 | # System-level dependencies. 54 | find_package(PkgConfig REQUIRED) 55 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 56 | 57 | add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") 58 | 59 | # Define the application target. To change its name, change BINARY_NAME above, 60 | # not the value here, or `flutter run` will no longer work. 61 | # 62 | # Any new source files that you add to the application should be added here. 63 | add_executable(${BINARY_NAME} 64 | "main.cc" 65 | "my_application.cc" 66 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 67 | ) 68 | 69 | # Apply the standard set of build settings. This can be removed for applications 70 | # that need different build settings. 71 | apply_standard_settings(${BINARY_NAME}) 72 | 73 | # Add dependency libraries. Add any application-specific dependencies here. 74 | target_link_libraries(${BINARY_NAME} PRIVATE flutter) 75 | target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) 76 | 77 | # Run the Flutter tool portions of the build. This must not be removed. 78 | add_dependencies(${BINARY_NAME} flutter_assemble) 79 | 80 | # Only the install-generated bundle's copy of the executable will launch 81 | # correctly, since the resources must in the right relative locations. To avoid 82 | # people trying to run the unbundled copy, put it in a subdirectory instead of 83 | # the default top-level location. 84 | set_target_properties(${BINARY_NAME} 85 | PROPERTIES 86 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" 87 | ) 88 | 89 | # Generated plugin build rules, which manage building the plugins and adding 90 | # them to the application. 91 | include(flutter/generated_plugins.cmake) 92 | 93 | 94 | # === Installation === 95 | # By default, "installing" just makes a relocatable bundle in the build 96 | # directory. 97 | set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") 98 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 99 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 100 | endif() 101 | 102 | # Start with a clean build bundle directory every time. 103 | install(CODE " 104 | file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") 105 | " COMPONENT Runtime) 106 | 107 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 108 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") 109 | 110 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 111 | COMPONENT Runtime) 112 | 113 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 114 | COMPONENT Runtime) 115 | 116 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 117 | COMPONENT Runtime) 118 | 119 | foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) 120 | install(FILES "${bundled_library}" 121 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 122 | COMPONENT Runtime) 123 | endforeach(bundled_library) 124 | 125 | # Fully re-copy the assets directory on each build to avoid having stale files 126 | # from a previous install. 127 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 128 | install(CODE " 129 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 130 | " COMPONENT Runtime) 131 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 132 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 133 | 134 | # Install the AOT library on non-Debug builds only. 135 | if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") 136 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 137 | COMPONENT Runtime) 138 | endif() 139 | -------------------------------------------------------------------------------- /linux/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.10) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | 12 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...), 13 | # which isn't available in 3.10. 14 | function(list_prepend LIST_NAME PREFIX) 15 | set(NEW_LIST "") 16 | foreach(element ${${LIST_NAME}}) 17 | list(APPEND NEW_LIST "${PREFIX}${element}") 18 | endforeach(element) 19 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) 20 | endfunction() 21 | 22 | # === Flutter Library === 23 | # System-level dependencies. 24 | find_package(PkgConfig REQUIRED) 25 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 26 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) 27 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) 28 | 29 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") 30 | 31 | # Published to parent scope for install step. 32 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 33 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 34 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 35 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) 36 | 37 | list(APPEND FLUTTER_LIBRARY_HEADERS 38 | "fl_basic_message_channel.h" 39 | "fl_binary_codec.h" 40 | "fl_binary_messenger.h" 41 | "fl_dart_project.h" 42 | "fl_engine.h" 43 | "fl_json_message_codec.h" 44 | "fl_json_method_codec.h" 45 | "fl_message_codec.h" 46 | "fl_method_call.h" 47 | "fl_method_channel.h" 48 | "fl_method_codec.h" 49 | "fl_method_response.h" 50 | "fl_plugin_registrar.h" 51 | "fl_plugin_registry.h" 52 | "fl_standard_message_codec.h" 53 | "fl_standard_method_codec.h" 54 | "fl_string_codec.h" 55 | "fl_value.h" 56 | "fl_view.h" 57 | "flutter_linux.h" 58 | ) 59 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") 60 | add_library(flutter INTERFACE) 61 | target_include_directories(flutter INTERFACE 62 | "${EPHEMERAL_DIR}" 63 | ) 64 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") 65 | target_link_libraries(flutter INTERFACE 66 | PkgConfig::GTK 67 | PkgConfig::GLIB 68 | PkgConfig::GIO 69 | ) 70 | add_dependencies(flutter flutter_assemble) 71 | 72 | # === Flutter tool backend === 73 | # _phony_ is a non-existent file to force this command to run every time, 74 | # since currently there's no way to get a full input/output list from the 75 | # flutter tool. 76 | add_custom_command( 77 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 78 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_ 79 | COMMAND ${CMAKE_COMMAND} -E env 80 | ${FLUTTER_TOOL_ENVIRONMENT} 81 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" 82 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} 83 | VERBATIM 84 | ) 85 | add_custom_target(flutter_assemble DEPENDS 86 | "${FLUTTER_LIBRARY}" 87 | ${FLUTTER_LIBRARY_HEADERS} 88 | ) 89 | -------------------------------------------------------------------------------- /linux/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void fl_register_plugins(FlPluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /linux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void fl_register_plugins(FlPluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /linux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /linux/main.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | int main(int argc, char** argv) { 4 | g_autoptr(MyApplication) app = my_application_new(); 5 | return g_application_run(G_APPLICATION(app), argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /linux/my_application.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | #include 4 | #ifdef GDK_WINDOWING_X11 5 | #include 6 | #endif 7 | 8 | #include "flutter/generated_plugin_registrant.h" 9 | 10 | struct _MyApplication { 11 | GtkApplication parent_instance; 12 | char** dart_entrypoint_arguments; 13 | }; 14 | 15 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) 16 | 17 | // Implements GApplication::activate. 18 | static void my_application_activate(GApplication* application) { 19 | MyApplication* self = MY_APPLICATION(application); 20 | GtkWindow* window = 21 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); 22 | 23 | // Use a header bar when running in GNOME as this is the common style used 24 | // by applications and is the setup most users will be using (e.g. Ubuntu 25 | // desktop). 26 | // If running on X and not using GNOME then just use a traditional title bar 27 | // in case the window manager does more exotic layout, e.g. tiling. 28 | // If running on Wayland assume the header bar will work (may need changing 29 | // if future cases occur). 30 | gboolean use_header_bar = TRUE; 31 | #ifdef GDK_WINDOWING_X11 32 | GdkScreen* screen = gtk_window_get_screen(window); 33 | if (GDK_IS_X11_SCREEN(screen)) { 34 | const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); 35 | if (g_strcmp0(wm_name, "GNOME Shell") != 0) { 36 | use_header_bar = FALSE; 37 | } 38 | } 39 | #endif 40 | if (use_header_bar) { 41 | GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); 42 | gtk_widget_show(GTK_WIDGET(header_bar)); 43 | gtk_header_bar_set_title(header_bar, "crm"); 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, "crm"); 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 | 9 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { 10 | } 11 | -------------------------------------------------------------------------------- /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/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/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 = crm 9 | 10 | // The application's bundle identifier 11 | PRODUCT_BUNDLE_IDENTIFIER = za.co.nanosoft.crm 12 | 13 | // The copyright displayed in application information 14 | PRODUCT_COPYRIGHT = Copyright © 2022 za.co.nanosoft. 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: crm 2 | description: Nanosoft's Mobile CRM 3 | publish_to: "none" 4 | version: 1.0.0+1 5 | environment: 6 | sdk: ">=2.18.2 <3.0.0" 7 | dependencies: 8 | flutter: 9 | sdk: flutter 10 | cupertino_icons: ^1.0.2 11 | equatable: ^2.0.5 12 | dio: ^4.0.6 13 | uuid: ^3.0.6 14 | dartz: ^0.10.1 15 | flutter_hooks: ^0.18.5+1 16 | dev_dependencies: 17 | flutter_test: 18 | sdk: flutter 19 | flutter_lints: ^2.0.0 20 | flutter_hooks_test: ^0.0.2 21 | mocktail: ^0.3.0 22 | build_runner: ^2.3.0 23 | flutter: 24 | uses-material-design: true 25 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | flutter test --coverage -------------------------------------------------------------------------------- /test/domain/repositories/implementations/customer_repository_impl_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/data/data_sources/interfaces/customer_datasource.dart'; 3 | import 'package:crm/data/entities/customer_entity.dart'; 4 | import 'package:crm/domain/model/customer.dart'; 5 | import 'package:crm/domain/repositories/implementations/customer_repository_impl.dart'; 6 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 7 | import 'package:dartz/dartz.dart'; 8 | import 'package:flutter_test/flutter_test.dart'; 9 | import 'package:mocktail/mocktail.dart'; 10 | 11 | class MockCustomerDataSource extends Mock implements CustomerDataSource {} 12 | 13 | void main() { 14 | late CustomerDataSource mockDS; 15 | late CustomerRepository customerRepository; 16 | setUp(() { 17 | mockDS = MockCustomerDataSource(); 18 | customerRepository = CustomerRepositoryImpl(mockDS); 19 | }); 20 | 21 | group("getAllCustomers", () { 22 | test("should return all list of customer models", () async { 23 | //arrange 24 | List dsResponse = [ 25 | const CustomerEntity( 26 | id: "123", 27 | emailAddress: "paul@nanosoft.co.za", 28 | customerName: "Paul", 29 | ) 30 | ]; 31 | 32 | List expected = [ 33 | const Customer( 34 | id: "123", 35 | name: "Paul", 36 | email: "paul@nanosoft.co.za", 37 | ) 38 | ]; 39 | 40 | when(() => mockDS.find(type: CustomerType.customer)).thenAnswer((_) async => dsResponse); 41 | 42 | //act 43 | final result = await customerRepository.getAllCustomers(CustomerType.customer); 44 | 45 | //assert 46 | List resultList = List.empty(); 47 | result.fold((l) => {}, (r) => {resultList = expected}); 48 | expect(resultList, equals(expected)); 49 | }); 50 | 51 | test("should return Failure when data source throws", () async { 52 | //arrange 53 | Either> expected = Left(ServerFailure()); 54 | when(() => mockDS.find(type: CustomerType.lead)).thenThrow(ServerFailure()); 55 | 56 | //act 57 | final result = await customerRepository.getAllCustomers(CustomerType.customer); 58 | 59 | //assert 60 | expect(result, equals(expected)); 61 | }); 62 | }); 63 | 64 | group("getCustomer", () { 65 | test("should return one customer model by customerid", () async { 66 | //arrange 67 | const dsResponse = CustomerEntity( 68 | id: "123", 69 | emailAddress: "paul@nanosoft.co.za", 70 | customerName: "Paul", 71 | ); 72 | Either expected = const Right(Customer( 73 | id: "123", 74 | name: "Paul", 75 | email: "paul@nanosoft.co.za", 76 | )); 77 | const customerId = "123"; 78 | when(() => mockDS.findOne(customerId)).thenAnswer((_) async => dsResponse); 79 | 80 | //act 81 | final result = await customerRepository.getCustomer(customerId); 82 | 83 | //assert 84 | expect(result, equals(expected)); 85 | }); 86 | 87 | test("should return Failure when data source throws", () async { 88 | //arrange 89 | Either expected = Left(ServerFailure()); 90 | const customerId = "123"; 91 | when(() => mockDS.findOne(customerId)).thenThrow(ServerFailure()); 92 | 93 | //act 94 | final result = await customerRepository.getCustomer(customerId); 95 | 96 | //assert 97 | expect(result, equals(expected)); 98 | }); 99 | }); 100 | 101 | group("createCustomer", () { 102 | test("should call ds create method", () async { 103 | //arrange 104 | const customer = Customer( 105 | id: "123", 106 | email: "john@gmail.com", 107 | name: "John", 108 | ); 109 | Either expected = const Right(unit); 110 | when(() => mockDS.create(const CustomerEntity( 111 | id: "123", 112 | emailAddress: "john@gmail.com", 113 | customerName: "John", 114 | active: true, 115 | type: CustomerType.customer, 116 | ))).thenAnswer((_) async => unit); 117 | 118 | //act 119 | final result = await customerRepository.createCustomer(customer); 120 | 121 | //assert 122 | expect(result, equals(expected)); 123 | }); 124 | 125 | test("should return Failure when data source throws", () async { 126 | //arrange 127 | const customer = Customer(id: "123", email: "john@gmail.com", name: "John"); 128 | when(() => mockDS.create(const CustomerEntity( 129 | id: "123", 130 | emailAddress: "john@gmail.com", 131 | customerName: "John", 132 | active: true, 133 | type: CustomerType.customer, 134 | ))).thenThrow(ServerFailure()); 135 | 136 | //act 137 | final result = await customerRepository.createCustomer(customer); 138 | 139 | //assert 140 | expect(result, equals(Left(ServerFailure()))); 141 | }); 142 | }); 143 | 144 | group("deleteCustomer", () { 145 | test("should call 'delete' method of data source", () async { 146 | //arrange 147 | const customerId = "123"; 148 | Either expected = const Right(unit); 149 | when(() => mockDS.delete(customerId)).thenAnswer((_) async => unit); 150 | 151 | //act 152 | final result = await customerRepository.deleteCustomer(customerId); 153 | 154 | //assert 155 | expect(result, equals(expected)); 156 | }); 157 | 158 | test("should return Failure when data source throws", () async { 159 | //arrange 160 | const customerId = "123"; 161 | when(() => mockDS.delete(customerId)).thenThrow(ServerFailure()); 162 | 163 | //act 164 | final result = await customerRepository.deleteCustomer(customerId); 165 | 166 | //assert 167 | expect(result, equals(Left(ServerFailure()))); 168 | }); 169 | }); 170 | 171 | group("updateCustomer", () { 172 | test("should call 'update' method of data source", () async { 173 | //arrange 174 | const customerId = "123"; 175 | Either expected = const Right(unit); 176 | when(() => mockDS.update(customerId, customerName: "Jim")).thenAnswer((_) async => unit); 177 | 178 | //act 179 | final result = await customerRepository.updateCustomer(customerId, name: "Jim"); 180 | 181 | //assert 182 | expect(result, equals(expected)); 183 | verify(() => mockDS.update(customerId, customerName: "Jim")); 184 | verifyNoMoreInteractions(mockDS); 185 | }); 186 | 187 | test("should return Failure when data source throws", () async { 188 | //arrange 189 | const customerId = "123"; 190 | when(() => mockDS.update(customerId, customerName: "Jim")).thenThrow(ServerFailure()); 191 | 192 | //act 193 | final result = await customerRepository.updateCustomer(customerId, name: "Jim"); 194 | 195 | //assert 196 | expect(result, equals(Left(ServerFailure()))); 197 | }); 198 | }); 199 | } 200 | -------------------------------------------------------------------------------- /test/domain/repositories/implementations/task_repository_impl_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/data/data_sources/interfaces/task_datasource.dart'; 3 | import 'package:crm/data/entities/task_entity.dart'; 4 | import 'package:crm/domain/model/customer.dart'; 5 | import 'package:crm/domain/model/task.dart'; 6 | import 'package:crm/domain/repositories/implementations/task_repository_impl.dart'; 7 | import 'package:crm/domain/repositories/interfaces/task_repository.dart'; 8 | import 'package:dartz/dartz.dart'; 9 | import 'package:flutter_test/flutter_test.dart'; 10 | import 'package:mocktail/mocktail.dart'; 11 | 12 | class MockTaskDataSource extends Mock implements TaskDataSource {} 13 | 14 | void main() { 15 | late TaskDataSource mockDS; 16 | late TaskRepository repo; 17 | 18 | setUp(() { 19 | mockDS = MockTaskDataSource(); 20 | repo = TaskRepositoryImpl(mockDS); 21 | }); 22 | 23 | group("TaskRepository", () { 24 | group("createTask", () { 25 | test("should call create method of data source", () async { 26 | //arrange 27 | var customer = const Customer(id: "123", name: "John", email: "person@email.com"); 28 | var task = CRMTask(id: "1001", customer: customer, subject: "Meeting", dueDate: DateTime.now()); 29 | var taskEntity = TaskEntity( 30 | id: task.id, 31 | customer: customer, 32 | subject: task.subject, 33 | dueDate: task.dueDate, 34 | ); 35 | when(() => mockDS.create(taskEntity)).thenAnswer((realInvocation) async => unit); 36 | 37 | //act 38 | final result = await repo.createTask(task); 39 | 40 | //assert 41 | expect(result, equals(const Right(unit))); 42 | verify(() => mockDS.create(taskEntity)); 43 | verifyNoMoreInteractions(mockDS); 44 | }); 45 | 46 | test("should return Failure when data source throws", () async { 47 | //arrange 48 | var customer = const Customer(id: "123", name: "John", email: "person@email.com"); 49 | var task = CRMTask(id: "1001", customer: customer, subject: "Meeting", dueDate: DateTime.now()); 50 | var taskEntity = TaskEntity( 51 | id: task.id, 52 | customer: customer, 53 | subject: task.subject, 54 | dueDate: task.dueDate, 55 | ); 56 | when(() => mockDS.create(taskEntity)).thenThrow(ServerFailure()); 57 | 58 | //act 59 | final result = await repo.createTask(task); 60 | 61 | //assert 62 | expect(result, equals(Left(ServerFailure()))); 63 | verify(() => mockDS.create(taskEntity)); 64 | verifyNoMoreInteractions(mockDS); 65 | }); 66 | }); 67 | 68 | group("deleteTask", () { 69 | test("should call delete method of data source", () async { 70 | //arrange 71 | var id = "1001"; 72 | when(() => mockDS.delete(id)).thenAnswer((_) async => unit); 73 | 74 | //act 75 | final result = await repo.deleteTask(id); 76 | 77 | //assert 78 | expect(result, equals(const Right(unit))); 79 | verify(() => mockDS.delete(id)); 80 | verifyNoMoreInteractions(mockDS); 81 | }); 82 | 83 | test("should return Failure when data source throws", () async { 84 | //arrange 85 | //arrange 86 | var id = "1001"; 87 | when(() => mockDS.delete(id)).thenThrow(ServerFailure()); 88 | 89 | //act 90 | final result = await repo.deleteTask(id); 91 | 92 | //assert 93 | expect(result, equals(Left(ServerFailure()))); 94 | verify(() => mockDS.delete(id)); 95 | verifyNoMoreInteractions(mockDS); 96 | }); 97 | }); 98 | 99 | group("getAllTasks", () { 100 | test("should call find method of data source", () async { 101 | //arrange 102 | const customer = Customer(id: "123", name: "John", email: "john@email.com"); 103 | List dsResponse = [ 104 | TaskEntity( 105 | id: "1001", 106 | customer: customer, 107 | subject: "Meeting", 108 | dueDate: DateTime.now(), 109 | ) 110 | ]; 111 | List expected = [ 112 | CRMTask( 113 | id: "1001", 114 | customer: customer, 115 | subject: "Meeting", 116 | dueDate: DateTime.now(), 117 | ) 118 | ]; 119 | when(() => mockDS.find()).thenAnswer((_) async => dsResponse); 120 | 121 | //act 122 | final result = await repo.getAllTasks(); 123 | 124 | //assert 125 | List resultList = List.empty(); 126 | result.fold((l) => {}, (r) => {resultList = expected}); 127 | expect(resultList, equals(expected)); 128 | verify(() => mockDS.find()); 129 | verifyNoMoreInteractions(mockDS); 130 | }); 131 | 132 | test("should return Failure when data source throws", () async { 133 | //arrange 134 | when(() => mockDS.find()).thenThrow(ServerFailure()); 135 | 136 | //act 137 | final result = await repo.getAllTasks(); 138 | 139 | //assert 140 | expect(result, equals(Left(ServerFailure()))); 141 | verify(() => mockDS.find()); 142 | verifyNoMoreInteractions(mockDS); 143 | }); 144 | }); 145 | 146 | group("updateTask", () { 147 | test("should call 'update' method of data source", () async { 148 | //arrange 149 | const taskId = "1001"; 150 | Either expected = const Right(unit); 151 | const updatedSubject = "Changed Meeting Name"; 152 | when(() => mockDS.update(taskId, subject: updatedSubject)).thenAnswer((_) async => unit); 153 | 154 | //act 155 | final result = await repo.updateTask(taskId, subject: updatedSubject); 156 | 157 | //assert 158 | expect(result, equals(expected)); 159 | verify(() => mockDS.update(taskId, subject: updatedSubject)); 160 | verifyNoMoreInteractions(mockDS); 161 | }); 162 | 163 | test("should return Failure when data source throws", () async { 164 | //arrange 165 | const taskId = "1001"; 166 | const updatedSubject = "Changed Meeting Name"; 167 | when(() => mockDS.update(taskId, subject: updatedSubject)).thenThrow(ServerFailure()); 168 | 169 | //act 170 | final result = await repo.updateTask(taskId, subject: updatedSubject); 171 | 172 | //assert 173 | expect(result, equals(Left(ServerFailure()))); 174 | verify(() => mockDS.update(taskId, subject: updatedSubject)); 175 | verifyNoMoreInteractions(mockDS); 176 | }); 177 | }); 178 | }); 179 | } 180 | -------------------------------------------------------------------------------- /test/domain/use_cases/customer/create_customer_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 4 | import 'package:crm/domain/use_cases/customer/create_customer.dart'; 5 | import 'package:dartz/dartz.dart'; 6 | import 'package:flutter_test/flutter_test.dart'; 7 | import 'package:mocktail/mocktail.dart'; 8 | import 'package:uuid/uuid.dart'; 9 | 10 | class MockCustomerRepository extends Mock implements CustomerRepository {} 11 | 12 | void main() { 13 | late CustomerRepository mockCustomerRepository; 14 | late CreateCustomer usecase; 15 | 16 | setUp(() { 17 | mockCustomerRepository = MockCustomerRepository(); 18 | usecase = CreateCustomerImpl(mockCustomerRepository); 19 | }); 20 | 21 | test("should call the createCustmer customer repo method", () async { 22 | //arrange 23 | var repoResult = const Right(unit); 24 | var data = Customer(id: const Uuid().v4(), email: "john@gmail.com", name: 'John'); 25 | when(() => mockCustomerRepository.createCustomer(data)).thenAnswer((_) async => repoResult); 26 | 27 | //act 28 | final result = await usecase.execute(data); 29 | 30 | //assert 31 | expect(result, equals(repoResult)); 32 | verify(() => mockCustomerRepository.createCustomer(data)); 33 | verifyNoMoreInteractions(mockCustomerRepository); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /test/domain/use_cases/customer/delete_customer_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 3 | import 'package:crm/domain/use_cases/customer/delete_customer.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | import 'package:flutter_test/flutter_test.dart'; 6 | import 'package:mocktail/mocktail.dart'; 7 | import 'package:uuid/uuid.dart'; 8 | 9 | class MockCustomerRepository extends Mock implements CustomerRepository {} 10 | 11 | void main() { 12 | late CustomerRepository mockCustomerRepository; 13 | late DeleteCustomer usecase; 14 | 15 | setUp(() { 16 | mockCustomerRepository = MockCustomerRepository(); 17 | usecase = DeleteCustomerImpl(mockCustomerRepository); 18 | }); 19 | 20 | test("should call the deleteCustmer customer repo method", () async { 21 | //arrange 22 | var repoResult = const Right(unit); 23 | var customerId = const Uuid().v4(); 24 | 25 | when(() => mockCustomerRepository.deleteCustomer(customerId)).thenAnswer((_) async => repoResult); 26 | 27 | //act 28 | final result = await usecase.execute(customerId); 29 | 30 | //assert 31 | expect(result, equals(repoResult)); 32 | verify(() => mockCustomerRepository.deleteCustomer(customerId)); 33 | verifyNoMoreInteractions(mockCustomerRepository); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /test/domain/use_cases/customer/get_all_customers_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | import 'package:flutter_test/flutter_test.dart'; 6 | 7 | import 'package:crm/domain/use_cases/customer/get_all_customers.dart'; 8 | import 'package:mocktail/mocktail.dart'; 9 | 10 | class MockCustomerRepository extends Mock implements CustomerRepository {} 11 | 12 | void main() { 13 | late CustomerRepository mockCustomerRepository; 14 | late GetAllCustomers usecase; 15 | 16 | setUp(() { 17 | mockCustomerRepository = MockCustomerRepository(); 18 | usecase = GetAllCustomersImpl(mockCustomerRepository); 19 | }); 20 | 21 | test("should get all customers from the customer repository", () async { 22 | Either> repoResult = const Right>([ 23 | Customer( 24 | id: "123", 25 | email: "john@company.com", 26 | name: "John", 27 | ), 28 | Customer( 29 | id: "124", 30 | email: "jane@company.com", 31 | name: "Jane", 32 | ) 33 | ]); 34 | 35 | when(() => mockCustomerRepository.getAllCustomers(CustomerType.customer)).thenAnswer((_) async => repoResult); 36 | 37 | final result = await usecase.execute(); 38 | 39 | expect(result, equals(repoResult)); 40 | verify(() => mockCustomerRepository.getAllCustomers(CustomerType.customer)); 41 | verifyNoMoreInteractions(mockCustomerRepository); 42 | }); 43 | } 44 | -------------------------------------------------------------------------------- /test/domain/use_cases/customer/get_customer_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 4 | import 'package:crm/domain/use_cases/customer/get_customer.dart'; 5 | import 'package:dartz/dartz.dart'; 6 | import 'package:flutter_test/flutter_test.dart'; 7 | import 'package:mocktail/mocktail.dart'; 8 | 9 | class MockCustomerRepository extends Mock implements CustomerRepository {} 10 | 11 | void main() { 12 | late CustomerRepository mockCustomerRepository; 13 | late GetCustomer usecase; 14 | 15 | setUp(() { 16 | mockCustomerRepository = MockCustomerRepository(); 17 | usecase = GetCustomerImpl(mockCustomerRepository); 18 | }); 19 | test("should return a customer from the customer repository if an id is provided", () async { 20 | //arrange 21 | const customerId = "1234"; 22 | Either repoResponse = 23 | const Right(Customer(id: customerId, name: "John", email: "john@gmail.com")); 24 | when(() => mockCustomerRepository.getCustomer(customerId)).thenAnswer((_) async => repoResponse); 25 | 26 | //act 27 | final result = await usecase.execute(customerId); 28 | 29 | //assert 30 | expect(result, equals(repoResponse)); 31 | verify(() => mockCustomerRepository.getCustomer(customerId)); 32 | verifyNoMoreInteractions(mockCustomerRepository); 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /test/domain/use_cases/customer/make_customer_active_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 3 | import 'package:crm/domain/use_cases/customer/make_customer_active.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | import 'package:flutter_test/flutter_test.dart'; 6 | import 'package:mocktail/mocktail.dart'; 7 | 8 | class MockCustomerRepository extends Mock implements CustomerRepository {} 9 | 10 | void main() { 11 | late CustomerRepository mockCustomerRepository; 12 | late MakeCustomerActive usecase; 13 | 14 | setUp(() { 15 | mockCustomerRepository = MockCustomerRepository(); 16 | usecase = MakeCustomerActiveImpl(mockCustomerRepository); 17 | }); 18 | 19 | test("should call the updateCustomer repo method with customerId and isActive: true successfully", () async { 20 | //arrange 21 | const customerId = "1234"; 22 | const data = {"isActive": true}; 23 | Either repoResponse = const Right(unit); 24 | when(() => mockCustomerRepository.updateCustomer(customerId, isActive: true)).thenAnswer((_) async => repoResponse); 25 | 26 | //act 27 | final result = await usecase.execute(customerId); 28 | 29 | //assert 30 | expect(result, equals(repoResponse)); 31 | verify(() => mockCustomerRepository.updateCustomer(customerId, isActive: true)); 32 | verifyNoMoreInteractions(mockCustomerRepository); 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /test/domain/use_cases/customer/make_customer_inactive_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 3 | import 'package:crm/domain/use_cases/customer/make_customer_inactive.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | import 'package:flutter_test/flutter_test.dart'; 6 | import 'package:mocktail/mocktail.dart'; 7 | 8 | class MockCustomerRepository extends Mock implements CustomerRepository {} 9 | 10 | void main() { 11 | late CustomerRepository mockCustomerRepository; 12 | late MakeCustomerInActive usecase; 13 | setUp(() { 14 | mockCustomerRepository = MockCustomerRepository(); 15 | usecase = MakeCustomerInActiveImpl(mockCustomerRepository); 16 | }); 17 | 18 | test("should all updateCustomer repo method with customerId and things to change", () async { 19 | //arrange 20 | const customerId = "1234"; 21 | Either repoResponse = const Right(unit); 22 | when(() => mockCustomerRepository.updateCustomer(customerId, isActive: false)) 23 | .thenAnswer((_) async => repoResponse); 24 | 25 | //act 26 | final result = await usecase.execute(customerId); 27 | 28 | //assert 29 | expect(result, equals(repoResponse)); 30 | verify(() => mockCustomerRepository.updateCustomer(customerId, isActive: false)); 31 | verifyNoMoreInteractions(mockCustomerRepository); 32 | }); 33 | } 34 | -------------------------------------------------------------------------------- /test/domain/use_cases/customer/update_customer_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 3 | import 'package:crm/domain/use_cases/customer/update_customer_details.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | import 'package:flutter_test/flutter_test.dart'; 6 | import 'package:mocktail/mocktail.dart'; 7 | 8 | class MockCustomerRepository extends Mock implements CustomerRepository {} 9 | 10 | void main() { 11 | late CustomerRepository mockCustomerRepository; 12 | late UpdateCustomer usecase; 13 | setUp(() { 14 | mockCustomerRepository = MockCustomerRepository(); 15 | usecase = UpdateCustomerImpl(mockCustomerRepository); 16 | }); 17 | 18 | test("should call updateCustomer method of customer repo with id and customer data", () async { 19 | //arrange 20 | const customerId = "123"; 21 | Either repoResponse = Right(unit); 22 | when(() => mockCustomerRepository.updateCustomer(customerId, name: "Jim")) 23 | .thenAnswer((realInvocation) async => repoResponse); 24 | 25 | //act 26 | final result = await usecase.execute(customerId, name: "Jim"); 27 | 28 | //assert 29 | expect(result, equals(repoResponse)); 30 | verify(() => mockCustomerRepository.updateCustomer(customerId, name: "Jim")); 31 | verifyNoMoreInteractions(mockCustomerRepository); 32 | }); 33 | } 34 | -------------------------------------------------------------------------------- /test/domain/use_cases/lead/convert_lead_to_customer_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 4 | import 'package:crm/domain/use_cases/lead/convert_lead_to_customer.dart'; 5 | import 'package:dartz/dartz.dart'; 6 | import 'package:flutter_test/flutter_test.dart'; 7 | import 'package:mocktail/mocktail.dart'; 8 | 9 | class MockCustomerRepository extends Mock implements CustomerRepository {} 10 | 11 | void main() { 12 | late CustomerRepository mockCustomerRepository; 13 | late ConvertLeadToCustomer usecase; 14 | setUp(() { 15 | mockCustomerRepository = MockCustomerRepository(); 16 | usecase = ConvertLeadToCustomerImpl(mockCustomerRepository); 17 | }); 18 | 19 | test("should call update customer method to update the type", () async { 20 | //arrange 21 | const id = "123"; 22 | Either repoResponse = const Right(unit); 23 | when(() => mockCustomerRepository.updateCustomer(id, customerType: CustomerType.lead)) 24 | .thenAnswer((realInvocation) async => repoResponse); 25 | 26 | //act 27 | final result = await usecase.execute(id); 28 | 29 | //assert 30 | expect(result, equals(repoResponse)); 31 | verify(() => mockCustomerRepository.updateCustomer(id, customerType: CustomerType.lead)); 32 | verifyNoMoreInteractions(mockCustomerRepository); 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /test/domain/use_cases/lead/create_lead_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 4 | import 'package:crm/domain/use_cases/lead/create_lead.dart'; 5 | import 'package:dartz/dartz.dart'; 6 | import 'package:flutter_test/flutter_test.dart'; 7 | import 'package:mocktail/mocktail.dart'; 8 | 9 | class MockCustomerRepository extends Mock implements CustomerRepository {} 10 | 11 | void main() { 12 | late CustomerRepository mockCustomerRepository; 13 | late CreateLead usecase; 14 | setUp(() { 15 | mockCustomerRepository = MockCustomerRepository(); 16 | usecase = CreateLeadImpl(mockCustomerRepository); 17 | }); 18 | 19 | test("should call the createCustomer with lead type", () async { 20 | //arrange 21 | Customer customer = const Customer( 22 | id: "123", 23 | name: "Person", 24 | email: "person@email.com", 25 | customerType: CustomerType.lead, 26 | ); 27 | Either repoResponse = const Right(unit); 28 | when(() => mockCustomerRepository.createCustomer(customer)).thenAnswer((realInvocation) async => repoResponse); 29 | 30 | //act 31 | final result = await usecase.execute(customer); 32 | 33 | //assert 34 | expect(result, equals(repoResponse)); 35 | verify(() => mockCustomerRepository.createCustomer(customer)); 36 | verifyNoMoreInteractions(mockCustomerRepository); 37 | }); 38 | } 39 | -------------------------------------------------------------------------------- /test/domain/use_cases/lead/delete_lead_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 3 | import 'package:crm/domain/use_cases/lead/delete_lead.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | import 'package:flutter_test/flutter_test.dart'; 6 | import 'package:mocktail/mocktail.dart'; 7 | 8 | class MockCustomerRepository extends Mock implements CustomerRepository {} 9 | 10 | void main() { 11 | late CustomerRepository mockCustomerRepository; 12 | late DeleteLead usecase; 13 | setUp(() { 14 | mockCustomerRepository = MockCustomerRepository(); 15 | usecase = DeleteLeadImpl(mockCustomerRepository); 16 | }); 17 | 18 | test("should call the deleteCustomer repo method", () async { 19 | //arrange 20 | const id = "123"; 21 | Either repoResponse = const Right(unit); 22 | when(() => mockCustomerRepository.deleteCustomer(id)).thenAnswer((realInvocation) async => repoResponse); 23 | 24 | //act 25 | final result = await usecase.execute(id); 26 | 27 | //assert 28 | expect(result, equals(repoResponse)); 29 | verify(() => mockCustomerRepository.deleteCustomer(id)); 30 | verifyNoMoreInteractions(mockCustomerRepository); 31 | }); 32 | } 33 | -------------------------------------------------------------------------------- /test/domain/use_cases/lead/get_all_leads_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 4 | import 'package:crm/domain/use_cases/lead/get_all_leads.dart'; 5 | import 'package:dartz/dartz.dart'; 6 | import 'package:flutter_test/flutter_test.dart'; 7 | import 'package:mocktail/mocktail.dart'; 8 | 9 | class MockCustomerRepository extends Mock implements CustomerRepository {} 10 | 11 | void main() { 12 | late CustomerRepository mockCustomerRepository; 13 | late GetAllLeads usecase; 14 | 15 | setUp(() { 16 | mockCustomerRepository = MockCustomerRepository(); 17 | usecase = GetAllLeadsImpl(mockCustomerRepository); 18 | }); 19 | 20 | test("should call getCustomers with customer type of lead", () async { 21 | //arrange 22 | Either> repoResponse = const Right([ 23 | Customer( 24 | email: "person@email.com", 25 | id: "123", 26 | name: "Person", 27 | ) 28 | ]); 29 | when(() => mockCustomerRepository.getAllCustomers(CustomerType.lead)) 30 | .thenAnswer((realInvocation) async => repoResponse); 31 | 32 | //act 33 | final result = await usecase.execute(); 34 | 35 | //assert 36 | expect(result, equals(repoResponse)); 37 | verify(() => mockCustomerRepository.getAllCustomers(CustomerType.lead)); 38 | verifyNoMoreInteractions(mockCustomerRepository); 39 | }); 40 | } 41 | -------------------------------------------------------------------------------- /test/domain/use_cases/lead/get_lead_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 4 | import 'package:crm/domain/use_cases/lead/get_lead.dart'; 5 | import 'package:dartz/dartz.dart'; 6 | import 'package:flutter_test/flutter_test.dart'; 7 | import 'package:mocktail/mocktail.dart'; 8 | 9 | class MockCustomerRepository extends Mock implements CustomerRepository {} 10 | 11 | void main() { 12 | late CustomerRepository mockCustomerRepository; 13 | late GetLead usecase; 14 | setUp(() { 15 | mockCustomerRepository = MockCustomerRepository(); 16 | usecase = GetLeadImpl(mockCustomerRepository); 17 | }); 18 | 19 | test("should call getCustomer repo method with id", () async { 20 | //arrange 21 | const id = "123"; 22 | 23 | Either repoResponse = const Right(Customer(id: "123", name: "Jim", email: "person@email.com")); 24 | when(() => mockCustomerRepository.getCustomer(id)).thenAnswer((realInvocation) async => repoResponse); 25 | 26 | //act 27 | final result = await usecase.execute(id); 28 | 29 | //assert 30 | expect(result, equals(repoResponse)); 31 | verify(() => mockCustomerRepository.getCustomer(id)); 32 | verifyNoMoreInteractions(mockCustomerRepository); 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /test/domain/use_cases/lead/update_lead_details_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/repositories/interfaces/customer_repository.dart'; 3 | import 'package:crm/domain/use_cases/lead/update_lead_details.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | import 'package:flutter_test/flutter_test.dart'; 6 | import 'package:mocktail/mocktail.dart'; 7 | 8 | class MockCustomerRepository extends Mock implements CustomerRepository {} 9 | 10 | void main() { 11 | late CustomerRepository mockCustomerRepository; 12 | late UpdateLead usecase; 13 | 14 | setUp(() { 15 | mockCustomerRepository = MockCustomerRepository(); 16 | usecase = UpdateLeadImpl(mockCustomerRepository); 17 | }); 18 | 19 | test("should call the updateCustomer method of customer repo", () async { 20 | //arrange 21 | const id = "123"; 22 | Either repoResponse = const Right(unit); 23 | when(() => mockCustomerRepository.updateCustomer(id, name: "Jim")).thenAnswer((_) async => repoResponse); 24 | 25 | //act 26 | final result = await usecase.execute(id, name: "Jim"); 27 | 28 | //assert 29 | expect(result, equals(repoResponse)); 30 | }); 31 | } 32 | -------------------------------------------------------------------------------- /test/domain/use_cases/task/create_task_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/model/task.dart'; 4 | import 'package:crm/domain/repositories/interfaces/task_repository.dart'; 5 | import 'package:crm/domain/use_cases/task/create_task.dart'; 6 | import 'package:dartz/dartz.dart'; 7 | import 'package:flutter_test/flutter_test.dart'; 8 | import 'package:mocktail/mocktail.dart'; 9 | 10 | class MockTaskRepository extends Mock implements TaskRepository {} 11 | 12 | void main() { 13 | late TaskRepository mockTaskRepository; 14 | late CreateTask usecase; 15 | setUp(() { 16 | mockTaskRepository = MockTaskRepository(); 17 | usecase = CreateTaskImpl(mockTaskRepository); 18 | }); 19 | 20 | test("should call createTask of task repo", () async { 21 | //arrange 22 | var customer = const Customer(id: "123", name: "Person", email: "person@email.com"); 23 | var task = CRMTask( 24 | id: "1", 25 | customer: customer, 26 | subject: "Introduction meeting with customer", 27 | dueDate: DateTime.now(), 28 | ); 29 | Either repoResponse = const Right(unit); 30 | when(() => mockTaskRepository.createTask(task)).thenAnswer((realInvocation) async => repoResponse); 31 | 32 | //act 33 | final result = await usecase.execute(task); 34 | 35 | //assert 36 | expect(result, equals(repoResponse)); 37 | verify(() => mockTaskRepository.createTask(task)); 38 | verifyNoMoreInteractions(mockTaskRepository); 39 | }); 40 | } 41 | -------------------------------------------------------------------------------- /test/domain/use_cases/task/delete_customer_task_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/repositories/interfaces/task_repository.dart'; 3 | import 'package:crm/domain/use_cases/task/delete_task.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | import 'package:flutter_test/flutter_test.dart'; 6 | import 'package:mocktail/mocktail.dart'; 7 | 8 | class MockTaskRepository extends Mock implements TaskRepository {} 9 | 10 | void main() { 11 | late TaskRepository mockTaskRepository; 12 | late DeleteTask usecase; 13 | 14 | setUp(() { 15 | mockTaskRepository = MockTaskRepository(); 16 | usecase = DeleteTaskImpl(mockTaskRepository); 17 | }); 18 | 19 | test("should call the deleteTask method of task repo", () async { 20 | //arrange 21 | const id = "1001"; 22 | Either repoResponse = const Right(unit); 23 | when(() => mockTaskRepository.deleteTask(id)).thenAnswer((realInvocation) async => repoResponse); 24 | 25 | //act 26 | final result = await usecase.execute(id); 27 | 28 | //assert 29 | expect(result, equals(repoResponse)); 30 | verify(() => mockTaskRepository.deleteTask(id)); 31 | verifyNoMoreInteractions(mockTaskRepository); 32 | }); 33 | } 34 | -------------------------------------------------------------------------------- /test/domain/use_cases/task/mark_task_completed_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/task.dart'; 3 | import 'package:crm/domain/repositories/interfaces/task_repository.dart'; 4 | import 'package:crm/domain/use_cases/task/mark_task_as_completed.dart'; 5 | import 'package:dartz/dartz.dart'; 6 | import 'package:flutter_test/flutter_test.dart'; 7 | import 'package:mocktail/mocktail.dart'; 8 | 9 | class MockTaskRepository extends Mock implements TaskRepository {} 10 | 11 | void main() { 12 | late TaskRepository mockTaskRepository; 13 | late MarkTaskAsComplete usecase; 14 | 15 | setUp(() { 16 | mockTaskRepository = MockTaskRepository(); 17 | usecase = MarkTaskAsCompleteImpl(mockTaskRepository); 18 | }); 19 | 20 | test("should call the updateTask with status completed", () async { 21 | //arrange 22 | const id = "1001"; 23 | Either repoResponse = const Right(unit); 24 | when(() => mockTaskRepository.updateTask(id, status: Status.completed)) 25 | .thenAnswer((realInvocation) async => repoResponse); 26 | 27 | //act 28 | final result = await usecase.execute(id); 29 | 30 | //assert 31 | expect(result, equals(repoResponse)); 32 | verify(() => mockTaskRepository.updateTask(id, status: Status.completed)); 33 | verifyNoMoreInteractions(mockTaskRepository); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /test/domain/use_cases/task/update_task_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/task.dart'; 3 | import 'package:crm/domain/repositories/interfaces/task_repository.dart'; 4 | import 'package:crm/domain/use_cases/task/update_task.dart'; 5 | import 'package:dartz/dartz.dart'; 6 | import 'package:flutter_test/flutter_test.dart'; 7 | import 'package:mocktail/mocktail.dart'; 8 | 9 | class MockTaskRepository extends Mock implements TaskRepository {} 10 | 11 | void main() { 12 | late TaskRepository mockTaskRepository; 13 | late UpdateTask usecase; 14 | 15 | setUp(() { 16 | mockTaskRepository = MockTaskRepository(); 17 | usecase = UpdateTaskImpl(mockTaskRepository); 18 | }); 19 | 20 | test("should call the updateTask with data to be updated", () async { 21 | //arrange 22 | const id = "1001"; 23 | Either repoResponse = const Right(unit); 24 | when(() => mockTaskRepository.updateTask(id, priority: Priority.high)) 25 | .thenAnswer((realInvocation) async => repoResponse); 26 | 27 | //act 28 | final result = await usecase.execute(id, priority: Priority.high); 29 | 30 | //assert 31 | expect(result, equals(repoResponse)); 32 | verify(() => mockTaskRepository.updateTask(id, priority: Priority.high)); 33 | verifyNoMoreInteractions(mockTaskRepository); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /test/presentation/view_models/customer/customer_detail_view_model_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/use_cases/customer/delete_customer.dart'; 4 | import 'package:crm/domain/use_cases/customer/get_customer.dart'; 5 | import 'package:crm/presentation/view_models/customer/detail.dart'; 6 | import 'package:dartz/dartz.dart'; 7 | import 'package:flutter/material.dart'; 8 | import 'package:flutter_hooks/flutter_hooks.dart'; 9 | import 'package:flutter_hooks_test/flutter_hooks_test.dart'; 10 | import 'package:flutter_test/flutter_test.dart'; 11 | import 'package:mocktail/mocktail.dart'; 12 | 13 | class MockGetCustomer extends Mock implements GetCustomer {} 14 | 15 | class MockDeleteCustomer extends Mock implements DeleteCustomer {} 16 | 17 | void main() { 18 | late GetCustomer mockGetCustomerUseCase; 19 | late DeleteCustomer mockDeleteCustomerUseCase; 20 | setUp(() { 21 | mockGetCustomerUseCase = MockGetCustomer(); 22 | mockDeleteCustomerUseCase = MockDeleteCustomer(); 23 | }); 24 | 25 | testWidgets("should call getCustomer", (tester) async { 26 | //arrange 27 | const expected = Customer(id: "123", name: "John", email: "john@email.com"); 28 | Either useCaseResult = const Right(expected); 29 | when(() => mockGetCustomerUseCase.execute(expected.id!)).thenAnswer((_) async => useCaseResult); 30 | when(() => mockDeleteCustomerUseCase.execute(expected.id!)).thenAnswer((_) async => const Right(unit)); 31 | final result = await buildHook((_) => useCustomerDetailViewModel( 32 | getCustomerUseCase: mockGetCustomerUseCase, 33 | deleteCustomerUseCase: mockDeleteCustomerUseCase, 34 | )); 35 | 36 | //act and assert Fetch 37 | await act(() => result.current.fetchCustomerData(expected.id!)); 38 | expect(result.current.data, expected); 39 | 40 | //act and assert Delete 41 | await act(() => result.current.deleteCustomer(expected.id!)); 42 | verify(() => mockDeleteCustomerUseCase.execute(expected.id!)); 43 | }); 44 | 45 | testWidgets("should set Error message if getCustomer fails", (tester) async { 46 | //arrange 47 | when(() => mockGetCustomerUseCase.execute("123")).thenAnswer((_) async => Left(ServerFailure())); 48 | final result = await buildHook((_) => useCustomerDetailViewModel( 49 | getCustomerUseCase: mockGetCustomerUseCase, 50 | deleteCustomerUseCase: mockDeleteCustomerUseCase, 51 | )); 52 | 53 | //act 54 | await act(() => result.current.fetchCustomerData("123")); 55 | 56 | //assert Fetch 57 | expect(result.current.error, "Error Fetching Customer!"); 58 | }); 59 | 60 | testWidgets("should set Error message if deleteCustomer fails", (tester) async { 61 | //arrange 62 | when(() => mockDeleteCustomerUseCase.execute("123")).thenAnswer((_) async => Left(ServerFailure())); 63 | final result = await buildHook((_) => useCustomerDetailViewModel( 64 | getCustomerUseCase: mockGetCustomerUseCase, 65 | deleteCustomerUseCase: mockDeleteCustomerUseCase, 66 | )); 67 | 68 | //act 69 | await act(() => result.current.deleteCustomer("123")); 70 | 71 | //assert Fetch 72 | expect(result.current.error, "Error Deleting Customer!"); 73 | }); 74 | } 75 | -------------------------------------------------------------------------------- /test/presentation/view_models/customer/customer_edit_view_model_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/use_cases/customer/get_customer.dart'; 4 | import 'package:crm/domain/use_cases/customer/update_customer_details.dart'; 5 | import 'package:crm/presentation/view_models/customer/edit.dart'; 6 | import 'package:dartz/dartz.dart'; 7 | import 'package:flutter_hooks_test/flutter_hooks_test.dart'; 8 | import 'package:flutter_test/flutter_test.dart'; 9 | import 'package:mocktail/mocktail.dart'; 10 | 11 | class MockGetCustomer extends Mock implements GetCustomer {} 12 | 13 | class MockUpdateCustomer extends Mock implements UpdateCustomer {} 14 | 15 | void main() { 16 | late GetCustomer mockGetCustomerUseCase; 17 | late UpdateCustomer mockUpdateCustomerUseCase; 18 | setUp(() { 19 | mockGetCustomerUseCase = MockGetCustomer(); 20 | mockUpdateCustomerUseCase = MockUpdateCustomer(); 21 | }); 22 | 23 | testWidgets("should call fetchCustomerData and update state", (tester) async { 24 | //arrange 25 | const expected = Customer(id: "123", name: "John", email: "john@email.com"); 26 | Either useCaseResult = const Right(expected); 27 | when(() => mockGetCustomerUseCase.execute(expected.id!)).thenAnswer((_) async => useCaseResult); 28 | when( 29 | () => mockUpdateCustomerUseCase.execute( 30 | expected.id!, 31 | name: "Test Name", 32 | email: "test@email.com", 33 | ), 34 | ).thenAnswer((_) async => const Right(unit)); 35 | final result = await buildHook((_) => useCustomerEditViewModel( 36 | getCustomer: mockGetCustomerUseCase, 37 | updateCustomer: mockUpdateCustomerUseCase, 38 | )); 39 | 40 | //act and assert Fetch 41 | await act(() => result.current.fetchCustomerData(expected.id!)); 42 | verify(() => mockGetCustomerUseCase.execute(expected.id!)); 43 | expect(result.current.data, expected); 44 | 45 | //act and assert Save 46 | await act(() => result.current.saveCustomerData(name: "Test Name", email: "test@email.com")); 47 | verify(() => mockUpdateCustomerUseCase.execute(expected.id!, name: "Test Name", email: "test@email.com")); 48 | }); 49 | 50 | testWidgets("should set Error message if getCustomer fails", (tester) async { 51 | //arrange 52 | when(() => mockGetCustomerUseCase.execute("123")).thenAnswer((_) async => Left(ServerFailure())); 53 | final result = await buildHook((_) => useCustomerEditViewModel( 54 | getCustomer: mockGetCustomerUseCase, 55 | updateCustomer: mockUpdateCustomerUseCase, 56 | )); 57 | 58 | //act 59 | await act(() => result.current.fetchCustomerData("123")); 60 | 61 | //assert fetch Error 62 | expect(result.current.error, "Error Fetching Customer!"); 63 | }); 64 | 65 | testWidgets("should set Error message if updateCustomer fails", (tester) async { 66 | //arrange 67 | const expected = Customer(id: "123", name: "John", email: "john@email.com"); 68 | Either useCaseResult = const Right(expected); 69 | when(() => mockGetCustomerUseCase.execute(expected.id!)).thenAnswer((_) async => useCaseResult); 70 | 71 | when(() => mockUpdateCustomerUseCase.execute(expected.id!, name: "Test Name", email: "test@email.com")) 72 | .thenAnswer((_) async => Left(ServerFailure())); 73 | final result = await buildHook((_) => useCustomerEditViewModel( 74 | getCustomer: mockGetCustomerUseCase, 75 | updateCustomer: mockUpdateCustomerUseCase, 76 | )); 77 | 78 | //act 79 | await act(() => result.current.fetchCustomerData("123")); 80 | await act(() => result.current.saveCustomerData(name: "Test Name", email: "test@email.com")); 81 | 82 | //assert Save Error 83 | expect(result.current.error, "Error Saving Customer Data!"); 84 | }); 85 | } 86 | -------------------------------------------------------------------------------- /test/presentation/view_models/customer/customer_list_view_model_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/use_cases/customer/get_all_customers.dart'; 4 | import 'package:crm/presentation/view_models/customer/list.dart'; 5 | import 'package:dartz/dartz.dart'; 6 | import 'package:flutter_test/flutter_test.dart'; 7 | import 'package:mocktail/mocktail.dart'; 8 | import 'package:flutter_hooks_test/flutter_hooks_test.dart'; 9 | 10 | class MockGetAllCustomers extends Mock implements GetAllCustomers {} 11 | 12 | void main() { 13 | late GetAllCustomers mockGetAllCustomersUseCase; 14 | 15 | setUp(() { 16 | mockGetAllCustomersUseCase = MockGetAllCustomers(); 17 | }); 18 | 19 | testWidgets("should return data from use case", (WidgetTester tester) async { 20 | //arrange 21 | const useCaseResult = Right>([ 22 | Customer( 23 | id: "123", 24 | email: "john@company.com", 25 | name: "John", 26 | ), 27 | Customer( 28 | id: "124", 29 | email: "jane@company.com", 30 | name: "Jane", 31 | ) 32 | ]); 33 | 34 | when(() => mockGetAllCustomersUseCase.execute()).thenAnswer((_) async => useCaseResult); 35 | final result = await buildHook((_) => useCustomerListViewModel(getAllCustomers: mockGetAllCustomersUseCase)); 36 | 37 | //act 38 | await act(() => result.current.fetchData()); 39 | 40 | //assert 41 | verify(() => mockGetAllCustomersUseCase.execute()); 42 | expect(result.current.data.length, 2); 43 | }); 44 | 45 | testWidgets("should return error message ", (WidgetTester tester) async { 46 | //arrange 47 | Either> useCaseResult = Left(ServerFailure()); 48 | when(() => mockGetAllCustomersUseCase.execute()).thenAnswer((_) async => useCaseResult); 49 | final result = await buildHook((_) => useCustomerListViewModel(getAllCustomers: mockGetAllCustomersUseCase)); 50 | 51 | //act 52 | await act(() => result.current.fetchData()); 53 | 54 | //assert 55 | verify(() => mockGetAllCustomersUseCase.execute()); 56 | expect(result.current.error, 'Error Fetching Customers!'); 57 | }); 58 | } 59 | -------------------------------------------------------------------------------- /test/presentation/view_models/customer/customer_new_view_model_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:crm/core/error/failures.dart'; 2 | import 'package:crm/domain/model/customer.dart'; 3 | import 'package:crm/domain/use_cases/customer/create_customer.dart'; 4 | import 'package:crm/presentation/view_models/customer/new.dart'; 5 | import 'package:dartz/dartz.dart'; 6 | import 'package:flutter_test/flutter_test.dart'; 7 | import 'package:mocktail/mocktail.dart'; 8 | import 'package:flutter_hooks_test/flutter_hooks_test.dart'; 9 | 10 | class MockCreateCustomer extends Mock implements CreateCustomer {} 11 | 12 | void main() { 13 | late CreateCustomer mockCreateCustomerUseCase; 14 | setUp(() { 15 | mockCreateCustomerUseCase = MockCreateCustomer(); 16 | }); 17 | 18 | testWidgets("should call saveCustomerData", (tester) async { 19 | //arrange 20 | 21 | const inputData = Customer(name: "John", email: "john@email.com"); 22 | Either useCaseResult = const Right(unit); 23 | when(() => mockCreateCustomerUseCase.execute(inputData)).thenAnswer((_) async => useCaseResult); 24 | final result = await buildHook((_) => useCustomerNewViewModel(createCustomer: mockCreateCustomerUseCase)); 25 | 26 | //act 27 | await act(() => result.current.saveCustomerData(name: inputData.name, email: inputData.email)); 28 | 29 | //assert 30 | verify(() => mockCreateCustomerUseCase.execute(inputData)); 31 | verifyNoMoreInteractions(mockCreateCustomerUseCase); 32 | }); 33 | 34 | testWidgets("should set Error message if saveCustomerData fails", (tester) async { 35 | //arrange 36 | const inputData = Customer(name: "John", email: "john@email.com"); 37 | when(() => mockCreateCustomerUseCase.execute(inputData)).thenAnswer((_) async => Left(ServerFailure())); 38 | final result = await buildHook((_) => useCustomerNewViewModel(createCustomer: mockCreateCustomerUseCase)); 39 | 40 | //act 41 | await act(() => result.current.saveCustomerData(name: inputData.name, email: inputData.email)); 42 | 43 | //assert 44 | verify(() => mockCreateCustomerUseCase.execute(inputData)); 45 | expect(result.current.error, "Error Saving Customer Data!"); 46 | }); 47 | } 48 | -------------------------------------------------------------------------------- /web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/web/favicon.png -------------------------------------------------------------------------------- /web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/web/icons/Icon-192.png -------------------------------------------------------------------------------- /web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/web/icons/Icon-512.png -------------------------------------------------------------------------------- /web/icons/Icon-maskable-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/web/icons/Icon-maskable-192.png -------------------------------------------------------------------------------- /web/icons/Icon-maskable-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/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 | crm 33 | 34 | 35 | 39 | 40 | 41 | 42 | 43 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crm", 3 | "short_name": "crm", 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(crm 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 "crm") 8 | 9 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 10 | # versions of CMake. 11 | cmake_policy(SET CMP0063 NEW) 12 | 13 | # Define build configuration option. 14 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 15 | if(IS_MULTICONFIG) 16 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" 17 | CACHE STRING "" FORCE) 18 | else() 19 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 20 | set(CMAKE_BUILD_TYPE "Debug" CACHE 21 | STRING "Flutter build mode" FORCE) 22 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 23 | "Debug" "Profile" "Release") 24 | endif() 25 | endif() 26 | # Define settings for the Profile build mode. 27 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") 28 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") 29 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") 30 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") 31 | 32 | # Use Unicode for all projects. 33 | add_definitions(-DUNICODE -D_UNICODE) 34 | 35 | # Compilation settings that should be applied to most targets. 36 | # 37 | # Be cautious about adding new options here, as plugins use this function by 38 | # default. In most cases, you should add new options to specific targets instead 39 | # of modifying this function. 40 | function(APPLY_STANDARD_SETTINGS TARGET) 41 | target_compile_features(${TARGET} PUBLIC cxx_std_17) 42 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") 43 | target_compile_options(${TARGET} PRIVATE /EHsc) 44 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") 45 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") 46 | endfunction() 47 | 48 | # Flutter library and tool build rules. 49 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 50 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 51 | 52 | # Application build; see runner/CMakeLists.txt. 53 | add_subdirectory("runner") 54 | 55 | # Generated plugin build rules, which manage building the plugins and adding 56 | # them to the application. 57 | include(flutter/generated_plugins.cmake) 58 | 59 | 60 | # === Installation === 61 | # Support files are copied into place next to the executable, so that it can 62 | # run in place. This is done instead of making a separate bundle (as on Linux) 63 | # so that building and running from within Visual Studio will work. 64 | set(BUILD_BUNDLE_DIR "$") 65 | # Make the "install" step default, as it's required to run. 66 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) 67 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 68 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 69 | endif() 70 | 71 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 72 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") 73 | 74 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 75 | COMPONENT Runtime) 76 | 77 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 78 | COMPONENT Runtime) 79 | 80 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 81 | COMPONENT Runtime) 82 | 83 | if(PLUGIN_BUNDLED_LIBRARIES) 84 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" 85 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 86 | COMPONENT Runtime) 87 | endif() 88 | 89 | # Fully re-copy the assets directory on each build to avoid having stale files 90 | # from a previous install. 91 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 92 | install(CODE " 93 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 94 | " COMPONENT Runtime) 95 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 96 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 97 | 98 | # Install the AOT library on non-Debug builds only. 99 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 100 | CONFIGURATIONS Profile;Release 101 | COMPONENT Runtime) 102 | -------------------------------------------------------------------------------- /windows/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.14) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") 12 | 13 | # === Flutter Library === 14 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") 15 | 16 | # Published to parent scope for install step. 17 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 18 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 19 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 20 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) 21 | 22 | list(APPEND FLUTTER_LIBRARY_HEADERS 23 | "flutter_export.h" 24 | "flutter_windows.h" 25 | "flutter_messenger.h" 26 | "flutter_plugin_registrar.h" 27 | "flutter_texture_registrar.h" 28 | ) 29 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") 30 | add_library(flutter INTERFACE) 31 | target_include_directories(flutter INTERFACE 32 | "${EPHEMERAL_DIR}" 33 | ) 34 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") 35 | add_dependencies(flutter flutter_assemble) 36 | 37 | # === Wrapper === 38 | list(APPEND CPP_WRAPPER_SOURCES_CORE 39 | "core_implementations.cc" 40 | "standard_codec.cc" 41 | ) 42 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") 43 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN 44 | "plugin_registrar.cc" 45 | ) 46 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") 47 | list(APPEND CPP_WRAPPER_SOURCES_APP 48 | "flutter_engine.cc" 49 | "flutter_view_controller.cc" 50 | ) 51 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") 52 | 53 | # Wrapper sources needed for a plugin. 54 | add_library(flutter_wrapper_plugin STATIC 55 | ${CPP_WRAPPER_SOURCES_CORE} 56 | ${CPP_WRAPPER_SOURCES_PLUGIN} 57 | ) 58 | apply_standard_settings(flutter_wrapper_plugin) 59 | set_target_properties(flutter_wrapper_plugin PROPERTIES 60 | POSITION_INDEPENDENT_CODE ON) 61 | set_target_properties(flutter_wrapper_plugin PROPERTIES 62 | CXX_VISIBILITY_PRESET hidden) 63 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) 64 | target_include_directories(flutter_wrapper_plugin PUBLIC 65 | "${WRAPPER_ROOT}/include" 66 | ) 67 | add_dependencies(flutter_wrapper_plugin flutter_assemble) 68 | 69 | # Wrapper sources needed for the runner. 70 | add_library(flutter_wrapper_app STATIC 71 | ${CPP_WRAPPER_SOURCES_CORE} 72 | ${CPP_WRAPPER_SOURCES_APP} 73 | ) 74 | apply_standard_settings(flutter_wrapper_app) 75 | target_link_libraries(flutter_wrapper_app PUBLIC flutter) 76 | target_include_directories(flutter_wrapper_app PUBLIC 77 | "${WRAPPER_ROOT}/include" 78 | ) 79 | add_dependencies(flutter_wrapper_app flutter_assemble) 80 | 81 | # === Flutter tool backend === 82 | # _phony_ is a non-existent file to force this command to run every time, 83 | # since currently there's no way to get a full input/output list from the 84 | # flutter tool. 85 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") 86 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) 87 | add_custom_command( 88 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 89 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} 90 | ${CPP_WRAPPER_SOURCES_APP} 91 | ${PHONY_OUTPUT} 92 | COMMAND ${CMAKE_COMMAND} -E env 93 | ${FLUTTER_TOOL_ENVIRONMENT} 94 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" 95 | windows-x64 $ 96 | VERBATIM 97 | ) 98 | add_custom_target(flutter_assemble DEPENDS 99 | "${FLUTTER_LIBRARY}" 100 | ${FLUTTER_LIBRARY_HEADERS} 101 | ${CPP_WRAPPER_SOURCES_CORE} 102 | ${CPP_WRAPPER_SOURCES_PLUGIN} 103 | ${CPP_WRAPPER_SOURCES_APP} 104 | ) 105 | -------------------------------------------------------------------------------- /windows/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void RegisterPlugins(flutter::PluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /windows/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void RegisterPlugins(flutter::PluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /windows/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /windows/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | project(runner LANGUAGES CXX) 3 | 4 | # Define the application target. To change its name, change BINARY_NAME in the 5 | # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer 6 | # work. 7 | # 8 | # Any new source files that you add to the application should be added here. 9 | add_executable(${BINARY_NAME} WIN32 10 | "flutter_window.cpp" 11 | "main.cpp" 12 | "utils.cpp" 13 | "win32_window.cpp" 14 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 15 | "Runner.rc" 16 | "runner.exe.manifest" 17 | ) 18 | 19 | # Apply the standard set of build settings. This can be removed for applications 20 | # that need different build settings. 21 | apply_standard_settings(${BINARY_NAME}) 22 | 23 | # Add preprocessor definitions for the build version. 24 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") 25 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") 26 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") 27 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") 28 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") 29 | 30 | # Disable Windows macros that collide with C++ standard library functions. 31 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 32 | 33 | # Add dependency libraries and include directories. Add any application-specific 34 | # dependencies here. 35 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 36 | target_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", "za.co.nanosoft" "\0" 93 | VALUE "FileDescription", "crm" "\0" 94 | VALUE "FileVersion", VERSION_AS_STRING "\0" 95 | VALUE "InternalName", "crm" "\0" 96 | VALUE "LegalCopyright", "Copyright (C) 2022 za.co.nanosoft. All rights reserved." "\0" 97 | VALUE "OriginalFilename", "crm.exe" "\0" 98 | VALUE "ProductName", "crm" "\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"crm", 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/nanosoftonline/clean-flutter/25625581c6336d80d643b70c236bd3ce9a1c6fd5/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 | --------------------------------------------------------------------------------