├── .gitignore ├── .metadata ├── README.md ├── analysis_options.yaml ├── android ├── .gitignore ├── app │ ├── build.gradle │ └── src │ │ ├── debug │ │ └── AndroidManifest.xml │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── kotlin │ │ │ └── com │ │ │ │ └── example │ │ │ │ ├── clean_architecture │ │ │ │ └── MainActivity.kt │ │ │ │ └── flutter_clean_architecture │ │ │ │ └── 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 ├── ios ├── .gitignore ├── Flutter │ ├── AppFrameworkInfo.plist │ ├── Debug.xcconfig │ └── Release.xcconfig ├── Podfile ├── Podfile.lock ├── Runner.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ └── WorkspaceSettings.xcsettings │ └── xcshareddata │ │ └── xcschemes │ │ └── Runner.xcscheme ├── Runner.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ ├── IDEWorkspaceChecks.plist │ │ └── WorkspaceSettings.xcsettings ├── Runner │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ ├── Contents.json │ │ │ ├── Icon-App-1024x1024@1x.png │ │ │ ├── Icon-App-20x20@1x.png │ │ │ ├── Icon-App-20x20@2x.png │ │ │ ├── Icon-App-20x20@3x.png │ │ │ ├── Icon-App-29x29@1x.png │ │ │ ├── Icon-App-29x29@2x.png │ │ │ ├── Icon-App-29x29@3x.png │ │ │ ├── Icon-App-40x40@1x.png │ │ │ ├── Icon-App-40x40@2x.png │ │ │ ├── Icon-App-40x40@3x.png │ │ │ ├── Icon-App-60x60@2x.png │ │ │ ├── Icon-App-60x60@3x.png │ │ │ ├── Icon-App-76x76@1x.png │ │ │ ├── Icon-App-76x76@2x.png │ │ │ └── Icon-App-83.5x83.5@2x.png │ │ └── LaunchImage.imageset │ │ │ ├── Contents.json │ │ │ ├── LaunchImage.png │ │ │ ├── LaunchImage@2x.png │ │ │ ├── LaunchImage@3x.png │ │ │ └── README.md │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Info.plist │ └── Runner-Bridging-Header.h └── RunnerTests │ └── RunnerTests.swift ├── lib ├── core │ ├── error │ │ ├── exceptions │ │ │ ├── cache_exception.dart │ │ │ └── server_exception.dart │ │ └── failures │ │ │ ├── cache_failure.dart │ │ │ ├── failure.dart │ │ │ ├── failures.dart │ │ │ ├── invalid_input_failure.dart │ │ │ └── server_failure.dart │ ├── network │ │ ├── network_information.dart │ │ └── network_information_implementation.dart │ ├── use_cases │ │ └── use_case.dart │ └── utilities │ │ └── input_converter.dart ├── features │ └── number_trivia │ │ ├── data │ │ ├── data_sources │ │ │ ├── local_data_source │ │ │ │ ├── number_trivia_local_data_source.dart │ │ │ │ └── number_trivia_local_data_source_implementation.dart │ │ │ └── remote_data_source │ │ │ │ ├── number_trivia_remote_data_source.dart │ │ │ │ └── number_trivia_remote_data_source_implementation.dart │ │ ├── models │ │ │ └── number_trivia_model.dart │ │ └── repositories │ │ │ └── number_trivia_repository_implementation.dart │ │ ├── domain │ │ ├── entities │ │ │ └── number_trivia.dart │ │ ├── repositories │ │ │ └── number_trivia_repository.dart │ │ └── use_cases │ │ │ ├── get_concrete_number_trivia.dart │ │ │ └── get_random_number_trivia.dart │ │ └── presentation │ │ ├── bloc │ │ ├── events │ │ │ ├── get_trivia_for_concrete_number.dart │ │ │ ├── get_trivia_for_random_number.dart │ │ │ └── number_trivia_event.dart │ │ ├── number_trivia_bloc.dart │ │ └── state │ │ │ ├── initial_number_trivia_state.dart │ │ │ ├── loaded_number_trivia_state.dart │ │ │ ├── loading_number_trivia_state.dart │ │ │ ├── number_trivia_retrieval_error_state.dart │ │ │ └── number_trivia_state.dart │ │ ├── routes │ │ └── number_trivia_route.dart │ │ └── widgets │ │ ├── loading_widget.dart │ │ ├── message_display.dart │ │ ├── number_trivia_route_body.dart │ │ ├── trivia_control.dart │ │ ├── trivia_display.dart │ │ └── widgets.dart ├── injection_container.dart └── main.dart ├── pubspec.lock ├── pubspec.yaml ├── test ├── core │ ├── network │ │ └── network_information_implementation_test.dart │ └── utilities │ │ └── input_converter_test.dart ├── features │ └── number_trivia │ │ ├── data │ │ ├── data_sources │ │ │ ├── local_data_source │ │ │ │ └── number_trivia_local_data_source_implementation_test.dart │ │ │ └── remote_data_source │ │ │ │ └── number_trivia_remote_data_source_implementation_test.dart │ │ ├── models │ │ │ └── number_trivia_model_test.dart │ │ └── repositories │ │ │ └── number_trivia_repository_implementation_test.dart │ │ ├── domain │ │ └── use_cases │ │ │ ├── get_concrete_number_trivia_test.dart │ │ │ └── get_random_number_trivia_test.dart │ │ └── presentation │ │ └── bloc │ │ └── number_trivia_bloc_test.dart └── fixtures │ ├── fixture_reader.dart │ ├── trivia.json │ ├── trivia_cached.json │ └── trivia_double.json ├── 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 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | **/ios/Flutter/.last_build_id 26 | .dart_tool/ 27 | .flutter-plugins 28 | .flutter-plugins-dependencies 29 | .packages 30 | .pub-cache/ 31 | .pub/ 32 | /build/ 33 | 34 | # Web related 35 | lib/generated_plugin_registrant.dart 36 | 37 | # Symbolication related 38 | app.*.symbols 39 | 40 | # Obfuscation related 41 | app.*.map.json 42 | 43 | # Android Studio will place build artifacts here 44 | /android/app/debug 45 | /android/app/profile 46 | /android/app/release 47 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled. 5 | 6 | version: 7 | revision: f92f44110e87bad5ff168335c36da6f6053036e6 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: f92f44110e87bad5ff168335c36da6f6053036e6 17 | base_revision: f92f44110e87bad5ff168335c36da6f6053036e6 18 | - platform: android 19 | create_revision: f92f44110e87bad5ff168335c36da6f6053036e6 20 | base_revision: f92f44110e87bad5ff168335c36da6f6053036e6 21 | - platform: ios 22 | create_revision: f92f44110e87bad5ff168335c36da6f6053036e6 23 | base_revision: f92f44110e87bad5ff168335c36da6f6053036e6 24 | - platform: web 25 | create_revision: f92f44110e87bad5ff168335c36da6f6053036e6 26 | base_revision: f92f44110e87bad5ff168335c36da6f6053036e6 27 | 28 | # User provided section 29 | 30 | # List of Local paths (relative to this file) that should be 31 | # ignored by the migrate tool. 32 | # 33 | # Files that are not part of the templates will be ignored by default. 34 | unmanaged_files: 35 | - 'lib/main.dart' 36 | - 'ios/Runner.xcodeproj/project.pbxproj' 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Flutter Clean Architecture 2 | 3 | ## Flutter app implemented using Reso Coder Clean Architecture Proposal 4 | 5 | # This implementation features null-safety, and upgraded versions, such as BLoC, and for null-safety, uses internet_connection_checker instead of data_connection_checker, and mocktail instead of mockito. 6 | 7 | # I hope this repository helps anyone looking for a reference to sound-null safe clean architecture and test driven development implementation of flutter apps, and I will try to keep it up-to date and will track & accept pull requests from the community to this repository. 8 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:flutter_lints/flutter.yaml 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /android/app/build.gradle: -------------------------------------------------------------------------------- 1 | def localProperties = new Properties() 2 | def localPropertiesFile = rootProject.file('local.properties') 3 | if (localPropertiesFile.exists()) { 4 | localPropertiesFile.withReader('UTF-8') { reader -> 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 15 | if (flutterVersionCode == null) { 16 | flutterVersionCode = '1' 17 | } 18 | 19 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 20 | if (flutterVersionName == null) { 21 | flutterVersionName = '1.0' 22 | } 23 | 24 | apply plugin: 'com.android.application' 25 | apply plugin: 'kotlin-android' 26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 27 | 28 | android { 29 | compileSdkVersion 33 30 | 31 | sourceSets { 32 | main.java.srcDirs += 'src/main/kotlin' 33 | } 34 | 35 | defaultConfig { 36 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 37 | applicationId "com.example.clean_architecture" 38 | minSdkVersion 21 39 | targetSdkVersion flutter.targetSdkVersion 40 | versionCode flutterVersionCode.toInteger() 41 | versionName flutterVersionName 42 | } 43 | 44 | buildTypes { 45 | release { 46 | // TODO: Add your own signing config for the release build. 47 | // Signing with the debug keys for now, so `flutter run --release` works. 48 | signingConfig signingConfigs.debug 49 | } 50 | } 51 | } 52 | 53 | flutter { 54 | source '../..' 55 | } 56 | 57 | dependencies { 58 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 59 | } 60 | -------------------------------------------------------------------------------- /android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 8 | 16 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /android/app/src/main/kotlin/com/example/clean_architecture/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.clean_architecture 2 | 3 | import io.flutter.embedding.android.FlutterActivity 4 | 5 | class MainActivity: FlutterActivity() { 6 | } 7 | -------------------------------------------------------------------------------- /android/app/src/main/kotlin/com/example/flutter_clean_architecture/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.flutter_clean_architecture 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/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/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 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.3.50' 3 | repositories { 4 | google() 5 | jcenter() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:4.1.0' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | jcenter() 18 | } 19 | } 20 | 21 | rootProject.buildDir = '../build' 22 | subprojects { 23 | project.buildDir = "${rootProject.buildDir}/${project.name}" 24 | project.evaluationDependsOn(':app') 25 | } 26 | 27 | tasks.register("clean", Delete) { 28 | delete rootProject.buildDir 29 | } 30 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | android.useAndroidX=true 3 | android.enableJetifier=true 4 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jun 23 08:50:38 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /ios/.gitignore: -------------------------------------------------------------------------------- 1 | *.mode1v3 2 | *.mode2v3 3 | *.moved-aside 4 | *.pbxuser 5 | *.perspectivev3 6 | **/*sync/ 7 | .sconsign.dblite 8 | .tags* 9 | **/.vagrant/ 10 | **/DerivedData/ 11 | Icon? 12 | **/Pods/ 13 | **/.symlinks/ 14 | profile 15 | xcuserdata 16 | **/.generated/ 17 | Flutter/App.framework 18 | Flutter/Flutter.framework 19 | Flutter/Flutter.podspec 20 | Flutter/Generated.xcconfig 21 | Flutter/ephemeral/ 22 | Flutter/app.flx 23 | Flutter/app.zip 24 | Flutter/flutter_assets/ 25 | Flutter/flutter_export_environment.sh 26 | ServiceDefinitions.json 27 | Runner/GeneratedPluginRegistrant.* 28 | 29 | # Exceptions to above rules. 30 | !default.mode1v3 31 | !default.mode2v3 32 | !default.pbxuser 33 | !default.perspectivev3 34 | -------------------------------------------------------------------------------- /ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | App 9 | CFBundleIdentifier 10 | io.flutter.flutter.app 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | App 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | MinimumOSVersion 24 | 11.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /ios/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment this line to define a global platform for your project 2 | # platform :ios, '11.0' 3 | 4 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency. 5 | ENV['COCOAPODS_DISABLE_STATS'] = 'true' 6 | 7 | project 'Runner', { 8 | 'Debug' => :debug, 9 | 'Profile' => :release, 10 | 'Release' => :release, 11 | } 12 | 13 | def flutter_root 14 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) 15 | unless File.exist?(generated_xcode_build_settings_path) 16 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" 17 | end 18 | 19 | File.foreach(generated_xcode_build_settings_path) do |line| 20 | matches = line.match(/FLUTTER_ROOT\=(.*)/) 21 | return matches[1].strip if matches 22 | end 23 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" 24 | end 25 | 26 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) 27 | 28 | flutter_ios_podfile_setup 29 | 30 | target 'Runner' do 31 | use_frameworks! 32 | use_modular_headers! 33 | 34 | flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) 35 | end 36 | 37 | post_install do |installer| 38 | installer.pods_project.targets.each do |target| 39 | flutter_additional_ios_build_settings(target) 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /ios/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - Flutter (1.0.0) 3 | - shared_preferences_foundation (0.0.1): 4 | - Flutter 5 | - FlutterMacOS 6 | 7 | DEPENDENCIES: 8 | - Flutter (from `Flutter`) 9 | - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) 10 | 11 | EXTERNAL SOURCES: 12 | Flutter: 13 | :path: Flutter 14 | shared_preferences_foundation: 15 | :path: ".symlinks/plugins/shared_preferences_foundation/darwin" 16 | 17 | SPEC CHECKSUMS: 18 | Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 19 | shared_preferences_foundation: 986fc17f3d3251412d18b0265f9c64113a8c2472 20 | 21 | PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3 22 | 23 | COCOAPODS: 1.12.0 24 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 54; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 11 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 12 | 4940923A66D1893B01A33449 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 98AC3DBD4E67CF7B65336965 /* Pods_Runner.framework */; }; 13 | 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 14 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 15 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 16 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXCopyFilesBuildPhase section */ 20 | 9705A1C41CF9048500538489 /* Embed Frameworks */ = { 21 | isa = PBXCopyFilesBuildPhase; 22 | buildActionMask = 2147483647; 23 | dstPath = ""; 24 | dstSubfolderSpec = 10; 25 | files = ( 26 | ); 27 | name = "Embed Frameworks"; 28 | runOnlyForDeploymentPostprocessing = 0; 29 | }; 30 | /* End PBXCopyFilesBuildPhase section */ 31 | 32 | /* Begin PBXFileReference section */ 33 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 34 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 35 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 36 | 44219AD4CA4F07E1545F5E2F /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; 37 | 6005CEE0D8761829AEC5F06E /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; 38 | 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 39 | 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 40 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 41 | 80676E8D80538ED6838888C3 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; 42 | 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 43 | 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 44 | 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 45 | 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 46 | 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 47 | 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 48 | 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 49 | 98AC3DBD4E67CF7B65336965 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 50 | /* End PBXFileReference section */ 51 | 52 | /* Begin PBXFrameworksBuildPhase section */ 53 | 97C146EB1CF9000F007C117D /* Frameworks */ = { 54 | isa = PBXFrameworksBuildPhase; 55 | buildActionMask = 2147483647; 56 | files = ( 57 | 4940923A66D1893B01A33449 /* Pods_Runner.framework in Frameworks */, 58 | ); 59 | runOnlyForDeploymentPostprocessing = 0; 60 | }; 61 | /* End PBXFrameworksBuildPhase section */ 62 | 63 | /* Begin PBXGroup section */ 64 | 95E29E2A5AD30D6B2A3DFB3F /* Pods */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | 6005CEE0D8761829AEC5F06E /* Pods-Runner.debug.xcconfig */, 68 | 44219AD4CA4F07E1545F5E2F /* Pods-Runner.release.xcconfig */, 69 | 80676E8D80538ED6838888C3 /* Pods-Runner.profile.xcconfig */, 70 | ); 71 | name = Pods; 72 | path = Pods; 73 | sourceTree = ""; 74 | }; 75 | 9740EEB11CF90186004384FC /* Flutter */ = { 76 | isa = PBXGroup; 77 | children = ( 78 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 79 | 9740EEB21CF90195004384FC /* Debug.xcconfig */, 80 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, 81 | 9740EEB31CF90195004384FC /* Generated.xcconfig */, 82 | ); 83 | name = Flutter; 84 | sourceTree = ""; 85 | }; 86 | 97C146E51CF9000F007C117D = { 87 | isa = PBXGroup; 88 | children = ( 89 | 9740EEB11CF90186004384FC /* Flutter */, 90 | 97C146F01CF9000F007C117D /* Runner */, 91 | 97C146EF1CF9000F007C117D /* Products */, 92 | 95E29E2A5AD30D6B2A3DFB3F /* Pods */, 93 | B482F2E8DEAB6B59CC0E690F /* Frameworks */, 94 | ); 95 | sourceTree = ""; 96 | }; 97 | 97C146EF1CF9000F007C117D /* Products */ = { 98 | isa = PBXGroup; 99 | children = ( 100 | 97C146EE1CF9000F007C117D /* Runner.app */, 101 | ); 102 | name = Products; 103 | sourceTree = ""; 104 | }; 105 | 97C146F01CF9000F007C117D /* Runner */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | 97C146FA1CF9000F007C117D /* Main.storyboard */, 109 | 97C146FD1CF9000F007C117D /* Assets.xcassets */, 110 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, 111 | 97C147021CF9000F007C117D /* Info.plist */, 112 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, 113 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, 114 | 74858FAE1ED2DC5600515810 /* AppDelegate.swift */, 115 | 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */, 116 | ); 117 | path = Runner; 118 | sourceTree = ""; 119 | }; 120 | B482F2E8DEAB6B59CC0E690F /* Frameworks */ = { 121 | isa = PBXGroup; 122 | children = ( 123 | 98AC3DBD4E67CF7B65336965 /* Pods_Runner.framework */, 124 | ); 125 | name = Frameworks; 126 | sourceTree = ""; 127 | }; 128 | /* End PBXGroup section */ 129 | 130 | /* Begin PBXNativeTarget section */ 131 | 97C146ED1CF9000F007C117D /* Runner */ = { 132 | isa = PBXNativeTarget; 133 | buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; 134 | buildPhases = ( 135 | 5AD01DD082CFF3F16D30FB6E /* [CP] Check Pods Manifest.lock */, 136 | 9740EEB61CF901F6004384FC /* Run Script */, 137 | 97C146EA1CF9000F007C117D /* Sources */, 138 | 97C146EB1CF9000F007C117D /* Frameworks */, 139 | 97C146EC1CF9000F007C117D /* Resources */, 140 | 9705A1C41CF9048500538489 /* Embed Frameworks */, 141 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */, 142 | ED7AD1B2E63F3FF9B26FC16A /* [CP] Embed Pods Frameworks */, 143 | ); 144 | buildRules = ( 145 | ); 146 | dependencies = ( 147 | ); 148 | name = Runner; 149 | productName = Runner; 150 | productReference = 97C146EE1CF9000F007C117D /* Runner.app */; 151 | productType = "com.apple.product-type.application"; 152 | }; 153 | /* End PBXNativeTarget section */ 154 | 155 | /* Begin PBXProject section */ 156 | 97C146E61CF9000F007C117D /* Project object */ = { 157 | isa = PBXProject; 158 | attributes = { 159 | LastUpgradeCheck = 1300; 160 | ORGANIZATIONNAME = ""; 161 | TargetAttributes = { 162 | 97C146ED1CF9000F007C117D = { 163 | CreatedOnToolsVersion = 7.3.1; 164 | LastSwiftMigration = 1100; 165 | }; 166 | }; 167 | }; 168 | buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; 169 | compatibilityVersion = "Xcode 9.3"; 170 | developmentRegion = en; 171 | hasScannedForEncodings = 0; 172 | knownRegions = ( 173 | en, 174 | Base, 175 | ); 176 | mainGroup = 97C146E51CF9000F007C117D; 177 | productRefGroup = 97C146EF1CF9000F007C117D /* Products */; 178 | projectDirPath = ""; 179 | projectRoot = ""; 180 | targets = ( 181 | 97C146ED1CF9000F007C117D /* Runner */, 182 | ); 183 | }; 184 | /* End PBXProject section */ 185 | 186 | /* Begin PBXResourcesBuildPhase section */ 187 | 97C146EC1CF9000F007C117D /* Resources */ = { 188 | isa = PBXResourcesBuildPhase; 189 | buildActionMask = 2147483647; 190 | files = ( 191 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, 192 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 193 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, 194 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, 195 | ); 196 | runOnlyForDeploymentPostprocessing = 0; 197 | }; 198 | /* End PBXResourcesBuildPhase section */ 199 | 200 | /* Begin PBXShellScriptBuildPhase section */ 201 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { 202 | isa = PBXShellScriptBuildPhase; 203 | alwaysOutOfDate = 1; 204 | buildActionMask = 2147483647; 205 | files = ( 206 | ); 207 | inputPaths = ( 208 | "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", 209 | ); 210 | name = "Thin Binary"; 211 | outputPaths = ( 212 | ); 213 | runOnlyForDeploymentPostprocessing = 0; 214 | shellPath = /bin/sh; 215 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; 216 | }; 217 | 5AD01DD082CFF3F16D30FB6E /* [CP] Check Pods Manifest.lock */ = { 218 | isa = PBXShellScriptBuildPhase; 219 | buildActionMask = 2147483647; 220 | files = ( 221 | ); 222 | inputFileListPaths = ( 223 | ); 224 | inputPaths = ( 225 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 226 | "${PODS_ROOT}/Manifest.lock", 227 | ); 228 | name = "[CP] Check Pods Manifest.lock"; 229 | outputFileListPaths = ( 230 | ); 231 | outputPaths = ( 232 | "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", 233 | ); 234 | runOnlyForDeploymentPostprocessing = 0; 235 | shellPath = /bin/sh; 236 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 237 | showEnvVarsInLog = 0; 238 | }; 239 | 9740EEB61CF901F6004384FC /* Run Script */ = { 240 | isa = PBXShellScriptBuildPhase; 241 | alwaysOutOfDate = 1; 242 | buildActionMask = 2147483647; 243 | files = ( 244 | ); 245 | inputPaths = ( 246 | ); 247 | name = "Run Script"; 248 | outputPaths = ( 249 | ); 250 | runOnlyForDeploymentPostprocessing = 0; 251 | shellPath = /bin/sh; 252 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; 253 | }; 254 | ED7AD1B2E63F3FF9B26FC16A /* [CP] Embed Pods Frameworks */ = { 255 | isa = PBXShellScriptBuildPhase; 256 | buildActionMask = 2147483647; 257 | files = ( 258 | ); 259 | inputFileListPaths = ( 260 | "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", 261 | ); 262 | name = "[CP] Embed Pods Frameworks"; 263 | outputFileListPaths = ( 264 | "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", 265 | ); 266 | runOnlyForDeploymentPostprocessing = 0; 267 | shellPath = /bin/sh; 268 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; 269 | showEnvVarsInLog = 0; 270 | }; 271 | /* End PBXShellScriptBuildPhase section */ 272 | 273 | /* Begin PBXSourcesBuildPhase section */ 274 | 97C146EA1CF9000F007C117D /* Sources */ = { 275 | isa = PBXSourcesBuildPhase; 276 | buildActionMask = 2147483647; 277 | files = ( 278 | 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */, 279 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, 280 | ); 281 | runOnlyForDeploymentPostprocessing = 0; 282 | }; 283 | /* End PBXSourcesBuildPhase section */ 284 | 285 | /* Begin PBXVariantGroup section */ 286 | 97C146FA1CF9000F007C117D /* Main.storyboard */ = { 287 | isa = PBXVariantGroup; 288 | children = ( 289 | 97C146FB1CF9000F007C117D /* Base */, 290 | ); 291 | name = Main.storyboard; 292 | sourceTree = ""; 293 | }; 294 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { 295 | isa = PBXVariantGroup; 296 | children = ( 297 | 97C147001CF9000F007C117D /* Base */, 298 | ); 299 | name = LaunchScreen.storyboard; 300 | sourceTree = ""; 301 | }; 302 | /* End PBXVariantGroup section */ 303 | 304 | /* Begin XCBuildConfiguration section */ 305 | 249021D3217E4FDB00AE95B9 /* Profile */ = { 306 | isa = XCBuildConfiguration; 307 | buildSettings = { 308 | ALWAYS_SEARCH_USER_PATHS = NO; 309 | CLANG_ANALYZER_NONNULL = YES; 310 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 311 | CLANG_CXX_LIBRARY = "libc++"; 312 | CLANG_ENABLE_MODULES = YES; 313 | CLANG_ENABLE_OBJC_ARC = YES; 314 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 315 | CLANG_WARN_BOOL_CONVERSION = YES; 316 | CLANG_WARN_COMMA = YES; 317 | CLANG_WARN_CONSTANT_CONVERSION = YES; 318 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 319 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 320 | CLANG_WARN_EMPTY_BODY = YES; 321 | CLANG_WARN_ENUM_CONVERSION = YES; 322 | CLANG_WARN_INFINITE_RECURSION = YES; 323 | CLANG_WARN_INT_CONVERSION = YES; 324 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 325 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 326 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 327 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 328 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 329 | CLANG_WARN_STRICT_PROTOTYPES = YES; 330 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 331 | CLANG_WARN_UNREACHABLE_CODE = YES; 332 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 333 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 334 | COPY_PHASE_STRIP = NO; 335 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 336 | ENABLE_NS_ASSERTIONS = NO; 337 | ENABLE_STRICT_OBJC_MSGSEND = YES; 338 | GCC_C_LANGUAGE_STANDARD = gnu99; 339 | GCC_NO_COMMON_BLOCKS = YES; 340 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 341 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 342 | GCC_WARN_UNDECLARED_SELECTOR = YES; 343 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 344 | GCC_WARN_UNUSED_FUNCTION = YES; 345 | GCC_WARN_UNUSED_VARIABLE = YES; 346 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 347 | MTL_ENABLE_DEBUG_INFO = NO; 348 | SDKROOT = iphoneos; 349 | SUPPORTED_PLATFORMS = iphoneos; 350 | TARGETED_DEVICE_FAMILY = "1,2"; 351 | VALIDATE_PRODUCT = YES; 352 | }; 353 | name = Profile; 354 | }; 355 | 249021D4217E4FDB00AE95B9 /* Profile */ = { 356 | isa = XCBuildConfiguration; 357 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 358 | buildSettings = { 359 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 360 | CLANG_ENABLE_MODULES = YES; 361 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 362 | ENABLE_BITCODE = NO; 363 | INFOPLIST_FILE = Runner/Info.plist; 364 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 365 | PRODUCT_BUNDLE_IDENTIFIER = com.example.cleanArchitecture; 366 | PRODUCT_NAME = "$(TARGET_NAME)"; 367 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 368 | SWIFT_VERSION = 5.0; 369 | VERSIONING_SYSTEM = "apple-generic"; 370 | }; 371 | name = Profile; 372 | }; 373 | 97C147031CF9000F007C117D /* Debug */ = { 374 | isa = XCBuildConfiguration; 375 | buildSettings = { 376 | ALWAYS_SEARCH_USER_PATHS = NO; 377 | CLANG_ANALYZER_NONNULL = YES; 378 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 379 | CLANG_CXX_LIBRARY = "libc++"; 380 | CLANG_ENABLE_MODULES = YES; 381 | CLANG_ENABLE_OBJC_ARC = YES; 382 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 383 | CLANG_WARN_BOOL_CONVERSION = YES; 384 | CLANG_WARN_COMMA = YES; 385 | CLANG_WARN_CONSTANT_CONVERSION = YES; 386 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 387 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 388 | CLANG_WARN_EMPTY_BODY = YES; 389 | CLANG_WARN_ENUM_CONVERSION = YES; 390 | CLANG_WARN_INFINITE_RECURSION = YES; 391 | CLANG_WARN_INT_CONVERSION = YES; 392 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 393 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 394 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 395 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 396 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 397 | CLANG_WARN_STRICT_PROTOTYPES = YES; 398 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 399 | CLANG_WARN_UNREACHABLE_CODE = YES; 400 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 401 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 402 | COPY_PHASE_STRIP = NO; 403 | DEBUG_INFORMATION_FORMAT = dwarf; 404 | ENABLE_STRICT_OBJC_MSGSEND = YES; 405 | ENABLE_TESTABILITY = YES; 406 | GCC_C_LANGUAGE_STANDARD = gnu99; 407 | GCC_DYNAMIC_NO_PIC = NO; 408 | GCC_NO_COMMON_BLOCKS = YES; 409 | GCC_OPTIMIZATION_LEVEL = 0; 410 | GCC_PREPROCESSOR_DEFINITIONS = ( 411 | "DEBUG=1", 412 | "$(inherited)", 413 | ); 414 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 415 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 416 | GCC_WARN_UNDECLARED_SELECTOR = YES; 417 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 418 | GCC_WARN_UNUSED_FUNCTION = YES; 419 | GCC_WARN_UNUSED_VARIABLE = YES; 420 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 421 | MTL_ENABLE_DEBUG_INFO = YES; 422 | ONLY_ACTIVE_ARCH = YES; 423 | SDKROOT = iphoneos; 424 | TARGETED_DEVICE_FAMILY = "1,2"; 425 | }; 426 | name = Debug; 427 | }; 428 | 97C147041CF9000F007C117D /* Release */ = { 429 | isa = XCBuildConfiguration; 430 | buildSettings = { 431 | ALWAYS_SEARCH_USER_PATHS = NO; 432 | CLANG_ANALYZER_NONNULL = YES; 433 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 434 | CLANG_CXX_LIBRARY = "libc++"; 435 | CLANG_ENABLE_MODULES = YES; 436 | CLANG_ENABLE_OBJC_ARC = YES; 437 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 438 | CLANG_WARN_BOOL_CONVERSION = YES; 439 | CLANG_WARN_COMMA = YES; 440 | CLANG_WARN_CONSTANT_CONVERSION = YES; 441 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 442 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 443 | CLANG_WARN_EMPTY_BODY = YES; 444 | CLANG_WARN_ENUM_CONVERSION = YES; 445 | CLANG_WARN_INFINITE_RECURSION = YES; 446 | CLANG_WARN_INT_CONVERSION = YES; 447 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 448 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 449 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 450 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 451 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 452 | CLANG_WARN_STRICT_PROTOTYPES = YES; 453 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 454 | CLANG_WARN_UNREACHABLE_CODE = YES; 455 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 456 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 457 | COPY_PHASE_STRIP = NO; 458 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 459 | ENABLE_NS_ASSERTIONS = NO; 460 | ENABLE_STRICT_OBJC_MSGSEND = YES; 461 | GCC_C_LANGUAGE_STANDARD = gnu99; 462 | GCC_NO_COMMON_BLOCKS = YES; 463 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 464 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 465 | GCC_WARN_UNDECLARED_SELECTOR = YES; 466 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 467 | GCC_WARN_UNUSED_FUNCTION = YES; 468 | GCC_WARN_UNUSED_VARIABLE = YES; 469 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 470 | MTL_ENABLE_DEBUG_INFO = NO; 471 | SDKROOT = iphoneos; 472 | SUPPORTED_PLATFORMS = iphoneos; 473 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 474 | TARGETED_DEVICE_FAMILY = "1,2"; 475 | VALIDATE_PRODUCT = YES; 476 | }; 477 | name = Release; 478 | }; 479 | 97C147061CF9000F007C117D /* Debug */ = { 480 | isa = XCBuildConfiguration; 481 | baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; 482 | buildSettings = { 483 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 484 | CLANG_ENABLE_MODULES = YES; 485 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 486 | ENABLE_BITCODE = NO; 487 | INFOPLIST_FILE = Runner/Info.plist; 488 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 489 | PRODUCT_BUNDLE_IDENTIFIER = com.example.cleanArchitecture; 490 | PRODUCT_NAME = "$(TARGET_NAME)"; 491 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 492 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 493 | SWIFT_VERSION = 5.0; 494 | VERSIONING_SYSTEM = "apple-generic"; 495 | }; 496 | name = Debug; 497 | }; 498 | 97C147071CF9000F007C117D /* Release */ = { 499 | isa = XCBuildConfiguration; 500 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 501 | buildSettings = { 502 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 503 | CLANG_ENABLE_MODULES = YES; 504 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 505 | ENABLE_BITCODE = NO; 506 | INFOPLIST_FILE = Runner/Info.plist; 507 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 508 | PRODUCT_BUNDLE_IDENTIFIER = com.example.cleanArchitecture; 509 | PRODUCT_NAME = "$(TARGET_NAME)"; 510 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 511 | SWIFT_VERSION = 5.0; 512 | VERSIONING_SYSTEM = "apple-generic"; 513 | }; 514 | name = Release; 515 | }; 516 | /* End XCBuildConfiguration section */ 517 | 518 | /* Begin XCConfigurationList section */ 519 | 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { 520 | isa = XCConfigurationList; 521 | buildConfigurations = ( 522 | 97C147031CF9000F007C117D /* Debug */, 523 | 97C147041CF9000F007C117D /* Release */, 524 | 249021D3217E4FDB00AE95B9 /* Profile */, 525 | ); 526 | defaultConfigurationIsVisible = 0; 527 | defaultConfigurationName = Release; 528 | }; 529 | 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { 530 | isa = XCConfigurationList; 531 | buildConfigurations = ( 532 | 97C147061CF9000F007C117D /* Debug */, 533 | 97C147071CF9000F007C117D /* Release */, 534 | 249021D4217E4FDB00AE95B9 /* Profile */, 535 | ); 536 | defaultConfigurationIsVisible = 0; 537 | defaultConfigurationName = Release; 538 | }; 539 | /* End XCConfigurationList section */ 540 | }; 541 | rootObject = 97C146E61CF9000F007C117D /* Project object */; 542 | } 543 | -------------------------------------------------------------------------------- /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 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ios/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import Flutter 3 | 4 | @UIApplicationMain 5 | @objc class AppDelegate: FlutterAppDelegate { 6 | override func application( 7 | _ application: UIApplication, 8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? 9 | ) -> Bool { 10 | GeneratedPluginRegistrant.register(with: self) 11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "Icon-App-20x20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "Icon-App-20x20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "Icon-App-29x29@1x.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "Icon-App-29x29@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "29x29", 29 | "idiom" : "iphone", 30 | "filename" : "Icon-App-29x29@3x.png", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "Icon-App-40x40@2x.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "40x40", 41 | "idiom" : "iphone", 42 | "filename" : "Icon-App-40x40@3x.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "Icon-App-60x60@2x.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "60x60", 53 | "idiom" : "iphone", 54 | "filename" : "Icon-App-60x60@3x.png", 55 | "scale" : "3x" 56 | }, 57 | { 58 | "size" : "20x20", 59 | "idiom" : "ipad", 60 | "filename" : "Icon-App-20x20@1x.png", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "size" : "20x20", 65 | "idiom" : "ipad", 66 | "filename" : "Icon-App-20x20@2x.png", 67 | "scale" : "2x" 68 | }, 69 | { 70 | "size" : "29x29", 71 | "idiom" : "ipad", 72 | "filename" : "Icon-App-29x29@1x.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "29x29", 77 | "idiom" : "ipad", 78 | "filename" : "Icon-App-29x29@2x.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "40x40", 83 | "idiom" : "ipad", 84 | "filename" : "Icon-App-40x40@1x.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "40x40", 89 | "idiom" : "ipad", 90 | "filename" : "Icon-App-40x40@2x.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "76x76", 95 | "idiom" : "ipad", 96 | "filename" : "Icon-App-76x76@1x.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "76x76", 101 | "idiom" : "ipad", 102 | "filename" : "Icon-App-76x76@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "size" : "83.5x83.5", 107 | "idiom" : "ipad", 108 | "filename" : "Icon-App-83.5x83.5@2x.png", 109 | "scale" : "2x" 110 | }, 111 | { 112 | "size" : "1024x1024", 113 | "idiom" : "ios-marketing", 114 | "filename" : "Icon-App-1024x1024@1x.png", 115 | "scale" : "1x" 116 | } 117 | ], 118 | "info" : { 119 | "version" : 1, 120 | "author" : "xcode" 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/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/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/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/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/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/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/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/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/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/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/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/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/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/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/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/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/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/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/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/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/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/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/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/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/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/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/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/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/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/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/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 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | clean_architecture 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | $(FLUTTER_BUILD_NAME) 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | UISupportedInterfaceOrientations~ipad 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationPortraitUpsideDown 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UIViewControllerBasedStatusBarAppearance 43 | 44 | CADisableMinimumFrameDurationOnPhone 45 | 46 | UIApplicationSupportsIndirectInputEvents 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /ios/RunnerTests/RunnerTests.swift: -------------------------------------------------------------------------------- 1 | import Flutter 2 | import UIKit 3 | import XCTest 4 | 5 | class RunnerTests: XCTestCase { 6 | 7 | func testExample() { 8 | // If you add code to the Runner application, consider adding tests here. 9 | // See https://developer.apple.com/documentation/xctest for more information about using XCTest. 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /lib/core/error/exceptions/cache_exception.dart: -------------------------------------------------------------------------------- 1 | class CacheException implements Exception {} 2 | -------------------------------------------------------------------------------- /lib/core/error/exceptions/server_exception.dart: -------------------------------------------------------------------------------- 1 | class ServerException implements Exception {} 2 | -------------------------------------------------------------------------------- /lib/core/error/failures/cache_failure.dart: -------------------------------------------------------------------------------- 1 | import 'failure.dart'; 2 | 3 | class CacheFailure extends Failure {} 4 | -------------------------------------------------------------------------------- /lib/core/error/failures/failure.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | 3 | abstract class Failure extends Equatable { 4 | @override 5 | List get props => []; 6 | } 7 | -------------------------------------------------------------------------------- /lib/core/error/failures/failures.dart: -------------------------------------------------------------------------------- 1 | export 'cache_failure.dart'; 2 | export 'failure.dart'; 3 | export 'server_failure.dart'; 4 | -------------------------------------------------------------------------------- /lib/core/error/failures/invalid_input_failure.dart: -------------------------------------------------------------------------------- 1 | import 'failure.dart'; 2 | 3 | class InvalidInputFailure extends Failure {} 4 | -------------------------------------------------------------------------------- /lib/core/error/failures/server_failure.dart: -------------------------------------------------------------------------------- 1 | import 'failure.dart'; 2 | 3 | class ServerFailure extends Failure {} 4 | -------------------------------------------------------------------------------- /lib/core/network/network_information.dart: -------------------------------------------------------------------------------- 1 | abstract class NetworkInformation { 2 | Future get isConnected; 3 | } 4 | -------------------------------------------------------------------------------- /lib/core/network/network_information_implementation.dart: -------------------------------------------------------------------------------- 1 | import 'package:internet_connection_checker/internet_connection_checker.dart'; 2 | 3 | import 'network_information.dart'; 4 | 5 | class NetworkInformationImplementation implements NetworkInformation { 6 | final InternetConnectionChecker _internetConnectionChecker; 7 | 8 | NetworkInformationImplementation(this._internetConnectionChecker); 9 | 10 | @override 11 | Future get isConnected => _internetConnectionChecker.hasConnection; 12 | } 13 | -------------------------------------------------------------------------------- /lib/core/use_cases/use_case.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:equatable/equatable.dart'; 3 | 4 | import '../error/failures/failure.dart'; 5 | 6 | abstract class UseCase { 7 | Future> call(Params params); 8 | } 9 | 10 | class NoParams extends Equatable { 11 | @override 12 | List get props => []; 13 | } 14 | -------------------------------------------------------------------------------- /lib/core/utilities/input_converter.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | 3 | import '../error/failures/failure.dart'; 4 | import '../error/failures/invalid_input_failure.dart'; 5 | 6 | class InputConverter { 7 | Either stringToUnsignedInteger(String numberString) { 8 | try { 9 | final parsedNumber = int.parse(numberString); 10 | 11 | if (parsedNumber < 0) throw const FormatException(); 12 | 13 | return Right(parsedNumber); 14 | } on FormatException { 15 | final failure = InvalidInputFailure(); 16 | 17 | return Left(failure); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/features/number_trivia/data/data_sources/local_data_source/number_trivia_local_data_source.dart: -------------------------------------------------------------------------------- 1 | import 'package:clean_architecture/features/number_trivia/data/models/number_trivia_model.dart'; 2 | 3 | abstract class NumberTriviaLocalDataSource { 4 | /// Calls the http://numbersapi.com/random endpoint 5 | /// 6 | /// Throws a [ServerException] for all error codes. 7 | Future getLastNumberTrivia(); 8 | 9 | /// Gets the cached [NumberTriviaModel] which was gotten the last time 10 | /// the user had an internet connection. 11 | /// 12 | /// Throws [CacheException] if no cached data is present 13 | Future cacheNumberTrivia(NumberTriviaModel triviaToCache); 14 | } 15 | -------------------------------------------------------------------------------- /lib/features/number_trivia/data/data_sources/local_data_source/number_trivia_local_data_source_implementation.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:shared_preferences/shared_preferences.dart'; 4 | 5 | import '../../../../../core/error/exceptions/cache_exception.dart'; 6 | import '../../models/number_trivia_model.dart'; 7 | import 'number_trivia_local_data_source.dart'; 8 | 9 | const cachedNumberTrivia = 'CACHED_NUMBER_TRIVIA'; 10 | 11 | class NumberTriviaLocalDataSourceImplementation 12 | implements NumberTriviaLocalDataSource { 13 | final SharedPreferences _sharedPreferences; 14 | 15 | NumberTriviaLocalDataSourceImplementation({ 16 | required SharedPreferences sharedPreferences, 17 | }) : _sharedPreferences = sharedPreferences; 18 | 19 | @override 20 | Future getLastNumberTrivia() { 21 | final numberTriviaString = _sharedPreferences.getString(cachedNumberTrivia); 22 | 23 | if (numberTriviaString == null) { 24 | throw CacheException(); 25 | } else { 26 | final numberTriviaJson = json.decode(numberTriviaString); 27 | final numberTriviaModel = NumberTriviaModel.fromJson(numberTriviaJson); 28 | final numberTriviaFuture = Future.value(numberTriviaModel); 29 | 30 | return numberTriviaFuture; 31 | } 32 | } 33 | 34 | @override 35 | Future cacheNumberTrivia(NumberTriviaModel triviaToCache) async { 36 | final triviaMap = triviaToCache.toJson(); 37 | final triviaJson = json.encode(triviaMap); 38 | 39 | _sharedPreferences.setString(cachedNumberTrivia, triviaJson); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /lib/features/number_trivia/data/data_sources/remote_data_source/number_trivia_remote_data_source.dart: -------------------------------------------------------------------------------- 1 | import '../../models/number_trivia_model.dart'; 2 | 3 | abstract class NumberTriviaRemoteDataSource { 4 | /// Calls the http://numbersapi.com/{number} endpoint. 5 | /// 6 | /// Throws a [ServerException] for all error codes. 7 | Future getConcreteNumberTrivia(int number); 8 | 9 | /// Calls the http://numbersapi.com/random endpoint. 10 | /// 11 | /// Throws a [ServerException] for all error codes. 12 | Future getRandomNumberTrivia(); 13 | } 14 | -------------------------------------------------------------------------------- /lib/features/number_trivia/data/data_sources/remote_data_source/number_trivia_remote_data_source_implementation.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:http/http.dart'; 4 | 5 | import '../../../../../core/error/exceptions/server_exception.dart'; 6 | import '../../models/number_trivia_model.dart'; 7 | import 'number_trivia_remote_data_source.dart'; 8 | 9 | const _api = 'http://numbersapi.com'; 10 | 11 | class NumberTriviaRemoteDataSourceImplementation 12 | implements NumberTriviaRemoteDataSource { 13 | final Client _client; 14 | 15 | NumberTriviaRemoteDataSourceImplementation({ 16 | required Client client, 17 | }) : _client = client; 18 | 19 | @override 20 | Future getConcreteNumberTrivia(int number) => 21 | _getTriviaFromUrl('$_api/$number'); 22 | 23 | @override 24 | Future getRandomNumberTrivia() => 25 | _getTriviaFromUrl('$_api/random'); 26 | 27 | Future _getTriviaFromUrl(String url) async { 28 | final uri = Uri.parse(url); 29 | 30 | final headers = { 31 | 'Content-Type': 'application/json', 32 | }; 33 | 34 | final response = await _client.get(uri, headers: headers); 35 | final responseBody = response.body; 36 | final responseCode = response.statusCode; 37 | 38 | if (responseCode == 200) { 39 | final jsonResponse = json.decode(responseBody); 40 | final numberTriviaModel = NumberTriviaModel.fromJson(jsonResponse); 41 | 42 | return numberTriviaModel; 43 | } else { 44 | throw ServerException(); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lib/features/number_trivia/data/models/number_trivia_model.dart: -------------------------------------------------------------------------------- 1 | import '../../domain/entities/number_trivia.dart'; 2 | 3 | class NumberTriviaModel extends NumberTrivia { 4 | const NumberTriviaModel({ 5 | required int number, 6 | required String text, 7 | }) : super(number: number, text: text); 8 | 9 | factory NumberTriviaModel.fromJson(Map json) { 10 | final number = (json['number'] as num).toInt(); 11 | final text = json['text']; 12 | final model = NumberTriviaModel(number: number, text: text); 13 | 14 | return model; 15 | } 16 | 17 | Map toJson() => {'number': number, 'text': text}; 18 | } 19 | -------------------------------------------------------------------------------- /lib/features/number_trivia/data/repositories/number_trivia_repository_implementation.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | 3 | import '../../../../core/error/exceptions/cache_exception.dart'; 4 | import '../../../../core/error/exceptions/server_exception.dart'; 5 | import '../../../../core/error/failures/cache_failure.dart'; 6 | import '../../../../core/error/failures/failure.dart'; 7 | import '../../../../core/error/failures/server_failure.dart'; 8 | import '../../../../core/network/network_information.dart'; 9 | import '../../domain/entities/number_trivia.dart'; 10 | import '../../domain/repositories/number_trivia_repository.dart'; 11 | import '../data_sources/local_data_source/number_trivia_local_data_source.dart'; 12 | import '../data_sources/remote_data_source/number_trivia_remote_data_source.dart'; 13 | import '../models/number_trivia_model.dart'; 14 | 15 | typedef _ConcreteOrRandomChooser = Future Function(); 16 | 17 | class NumberTriviaRepositoryImplementation implements NumberTriviaRepository { 18 | final NumberTriviaRemoteDataSource _numberTriviaRemoteDataSource; 19 | final NumberTriviaLocalDataSource _numberTriviaLocalDataSource; 20 | final NetworkInformation _networkInformation; 21 | 22 | NumberTriviaRepositoryImplementation({ 23 | required NumberTriviaRemoteDataSource remoteDataSource, 24 | required NumberTriviaLocalDataSource localDataSource, 25 | required NetworkInformation networkInformation, 26 | }) : _numberTriviaRemoteDataSource = remoteDataSource, 27 | _numberTriviaLocalDataSource = localDataSource, 28 | _networkInformation = networkInformation; 29 | 30 | @override 31 | Future> getConcreteNumberTrivia( 32 | int number, 33 | ) async => 34 | await _getTrivia( 35 | () => _numberTriviaRemoteDataSource.getConcreteNumberTrivia(number)); 36 | 37 | @override 38 | Future> getRandomNumberTrivia() async => 39 | await _getTrivia( 40 | () => _numberTriviaRemoteDataSource.getRandomNumberTrivia()); 41 | 42 | Future> _getTrivia( 43 | _ConcreteOrRandomChooser getConcreteOrRandom) async { 44 | final isConnected = await _networkInformation.isConnected; 45 | 46 | if (isConnected) { 47 | try { 48 | final numberTrivia = await getConcreteOrRandom(); 49 | 50 | _numberTriviaLocalDataSource.cacheNumberTrivia(numberTrivia); 51 | 52 | return Right(numberTrivia); 53 | } on ServerException { 54 | final failure = ServerFailure(); 55 | 56 | return Left(failure); 57 | } 58 | } else { 59 | try { 60 | final numberTrivia = 61 | await _numberTriviaLocalDataSource.getLastNumberTrivia(); 62 | 63 | return Right(numberTrivia); 64 | } on CacheException { 65 | final failure = CacheFailure(); 66 | 67 | return Left(failure); 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /lib/features/number_trivia/domain/entities/number_trivia.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | 3 | class NumberTrivia extends Equatable { 4 | final String _text; 5 | final int _number; 6 | 7 | const NumberTrivia({ 8 | required int number, 9 | required String text, 10 | }) : _number = number, 11 | _text = text; 12 | 13 | String get text => _text; 14 | 15 | int get number => _number; 16 | 17 | @override 18 | List get props => [_text, _number]; 19 | } 20 | -------------------------------------------------------------------------------- /lib/features/number_trivia/domain/repositories/number_trivia_repository.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | 3 | import '../../../../core/error/failures/failure.dart'; 4 | import '../entities/number_trivia.dart'; 5 | 6 | abstract class NumberTriviaRepository { 7 | Future> getConcreteNumberTrivia(int number); 8 | 9 | Future> getRandomNumberTrivia(); 10 | } 11 | -------------------------------------------------------------------------------- /lib/features/number_trivia/domain/use_cases/get_concrete_number_trivia.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:equatable/equatable.dart'; 3 | 4 | import '../../../../core/error/failures/failure.dart'; 5 | import '../../../../core/use_cases/use_case.dart'; 6 | import '../entities/number_trivia.dart'; 7 | import '../repositories/number_trivia_repository.dart'; 8 | 9 | class GetConcreteNumberTrivia implements UseCase { 10 | late final NumberTriviaRepository _numberTriviaRepository; 11 | 12 | GetConcreteNumberTrivia(NumberTriviaRepository numberTriviaRepository) 13 | : _numberTriviaRepository = numberTriviaRepository; 14 | 15 | @override 16 | Future> call(Params params) async { 17 | final numberTrivia = 18 | await _numberTriviaRepository.getConcreteNumberTrivia(params.number); 19 | 20 | return numberTrivia; 21 | } 22 | } 23 | 24 | class Params extends Equatable { 25 | final int _number; 26 | 27 | const Params({required int number}) : _number = number; 28 | 29 | int get number => _number; 30 | 31 | @override 32 | List get props => [_number]; 33 | } 34 | -------------------------------------------------------------------------------- /lib/features/number_trivia/domain/use_cases/get_random_number_trivia.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | 3 | import '../../../../core/error/failures/failure.dart'; 4 | import '../../../../core/use_cases/use_case.dart'; 5 | import '../entities/number_trivia.dart'; 6 | import '../repositories/number_trivia_repository.dart'; 7 | 8 | class GetRandomNumberTrivia implements UseCase { 9 | final NumberTriviaRepository _numberTriviaRepository; 10 | 11 | GetRandomNumberTrivia(NumberTriviaRepository numberTriviaRepository) 12 | : _numberTriviaRepository = numberTriviaRepository; 13 | 14 | @override 15 | Future> call(NoParams noParams) async { 16 | final trivia = await _numberTriviaRepository.getRandomNumberTrivia(); 17 | 18 | return trivia; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/bloc/events/get_trivia_for_concrete_number.dart: -------------------------------------------------------------------------------- 1 | import '../number_trivia_bloc.dart'; 2 | 3 | class GetTriviaForConcreteNumber extends NumberTriviaEvent { 4 | final String _numberString; 5 | 6 | const GetTriviaForConcreteNumber(this._numberString); 7 | 8 | @override 9 | List get props => [_numberString]; 10 | 11 | String get numberString => _numberString; 12 | } 13 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/bloc/events/get_trivia_for_random_number.dart: -------------------------------------------------------------------------------- 1 | import '../number_trivia_bloc.dart'; 2 | 3 | class GetTriviaForRandomNumber extends NumberTriviaEvent {} 4 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/bloc/events/number_trivia_event.dart: -------------------------------------------------------------------------------- 1 | part of '../number_trivia_bloc.dart'; 2 | 3 | abstract class NumberTriviaEvent extends Equatable { 4 | const NumberTriviaEvent(); 5 | 6 | @override 7 | List get props => []; 8 | } 9 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/bloc/number_trivia_bloc.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:equatable/equatable.dart'; 3 | import 'package:flutter_bloc/flutter_bloc.dart'; 4 | 5 | import '../../../../core/error/failures/cache_failure.dart'; 6 | import '../../../../core/error/failures/failure.dart'; 7 | import '../../../../core/error/failures/server_failure.dart'; 8 | import '../../../../core/use_cases/use_case.dart'; 9 | import '../../../../core/utilities/input_converter.dart'; 10 | import '../../domain/entities/number_trivia.dart'; 11 | import '../../domain/use_cases/get_concrete_number_trivia.dart'; 12 | import '../../domain/use_cases/get_random_number_trivia.dart'; 13 | import 'events/get_trivia_for_concrete_number.dart'; 14 | import 'events/get_trivia_for_random_number.dart'; 15 | import 'state/initial_number_trivia_state.dart'; 16 | import 'state/loaded_number_trivia_state.dart'; 17 | import 'state/loading_number_trivia_state.dart'; 18 | import 'state/number_trivia_retrieval_error_state.dart'; 19 | 20 | part 'events/number_trivia_event.dart'; 21 | part 'state/number_trivia_state.dart'; 22 | 23 | const serverFailureMessage = 'Server Failure'; 24 | const cacheFailureMessage = 'Cache Failure'; 25 | 26 | const invalidInputFailureMessage = 27 | 'Invalid Input - The number must be a positive integer or zero.'; 28 | 29 | class NumberTriviaBloc extends Bloc { 30 | final GetConcreteNumberTrivia _getConcreteNumberTrivia; 31 | final GetRandomNumberTrivia _getRandomNumberTrivia; 32 | final InputConverter _inputConverter; 33 | 34 | NumberTriviaBloc({ 35 | required GetConcreteNumberTrivia getConcreteNumberTrivia, 36 | required GetRandomNumberTrivia getRandomNumberTrivia, 37 | required InputConverter inputConverter, 38 | }) : _getConcreteNumberTrivia = getConcreteNumberTrivia, 39 | _getRandomNumberTrivia = getRandomNumberTrivia, 40 | _inputConverter = inputConverter, 41 | super(InitialNumberTriviaState()) { 42 | on(_concreteTriviaEventHandler); 43 | 44 | on(_randomTriviaEventHandler); 45 | } 46 | 47 | Future _concreteTriviaEventHandler( 48 | GetTriviaForConcreteNumber event, 49 | Emitter emit, 50 | ) async { 51 | final stringNumber = event.numberString; 52 | 53 | final inputEither = _inputConverter.stringToUnsignedInteger(stringNumber); 54 | 55 | await inputEither.fold( 56 | (_) async => emit( 57 | const NumberTriviaRetrievalErrorState( 58 | message: invalidInputFailureMessage, 59 | ), 60 | ), 61 | (parsedNumber) async { 62 | emit(LoadingNumberTriviaState()); 63 | 64 | final params = Params(number: parsedNumber); 65 | final either = await _getConcreteNumberTrivia(params); 66 | 67 | _emitNumberTriviaRetrievalResult(either, emit); 68 | }, 69 | ); 70 | } 71 | 72 | Future _randomTriviaEventHandler( 73 | GetTriviaForRandomNumber event, 74 | Emitter emit, 75 | ) async { 76 | emit(LoadingNumberTriviaState()); 77 | 78 | final either = await _getRandomNumberTrivia(NoParams()); 79 | 80 | _emitNumberTriviaRetrievalResult(either, emit); 81 | } 82 | 83 | String _mapFailureToMessage(Failure failure) { 84 | late final String failureMessage; 85 | 86 | switch (failure.runtimeType) { 87 | case ServerFailure: 88 | failureMessage = serverFailureMessage; 89 | 90 | break; 91 | 92 | case CacheFailure: 93 | failureMessage = cacheFailureMessage; 94 | 95 | break; 96 | 97 | default: 98 | failureMessage = 'Unexpected error'; 99 | 100 | break; 101 | } 102 | 103 | return failureMessage; 104 | } 105 | 106 | void _emitNumberTriviaRetrievalResult( 107 | Either either, 108 | Emitter emit, 109 | ) async { 110 | await either.fold( 111 | (failure) async { 112 | emit( 113 | NumberTriviaRetrievalErrorState( 114 | message: _mapFailureToMessage(failure), 115 | ), 116 | ); 117 | }, 118 | (trivia) async { 119 | emit( 120 | LoadedNumberTriviaState( 121 | trivia: trivia, 122 | ), 123 | ); 124 | }, 125 | ); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/bloc/state/initial_number_trivia_state.dart: -------------------------------------------------------------------------------- 1 | import '../number_trivia_bloc.dart'; 2 | 3 | class InitialNumberTriviaState extends NumberTriviaState {} -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/bloc/state/loaded_number_trivia_state.dart: -------------------------------------------------------------------------------- 1 | import '../../../domain/entities/number_trivia.dart'; 2 | import '../number_trivia_bloc.dart'; 3 | 4 | class LoadedNumberTriviaState extends NumberTriviaState { 5 | final NumberTrivia trivia; 6 | 7 | const LoadedNumberTriviaState({ 8 | required this.trivia, 9 | }); 10 | 11 | @override 12 | List get props => [trivia]; 13 | } 14 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/bloc/state/loading_number_trivia_state.dart: -------------------------------------------------------------------------------- 1 | import '../number_trivia_bloc.dart'; 2 | 3 | class LoadingNumberTriviaState extends NumberTriviaState {} -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/bloc/state/number_trivia_retrieval_error_state.dart: -------------------------------------------------------------------------------- 1 | import '../number_trivia_bloc.dart'; 2 | 3 | class NumberTriviaRetrievalErrorState extends NumberTriviaState { 4 | final String _message; 5 | 6 | const NumberTriviaRetrievalErrorState({ 7 | required String message, 8 | }) : _message = message; 9 | 10 | String get message => _message; 11 | 12 | @override 13 | List get props => [_message]; 14 | } 15 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/bloc/state/number_trivia_state.dart: -------------------------------------------------------------------------------- 1 | part of '../number_trivia_bloc.dart'; 2 | 3 | abstract class NumberTriviaState extends Equatable { 4 | const NumberTriviaState(); 5 | 6 | @override 7 | List get props => []; 8 | } 9 | 10 | 11 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/routes/number_trivia_route.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | import '../widgets/number_trivia_route_body.dart'; 4 | 5 | class NumberTriviaRoute extends StatelessWidget { 6 | static const routeName = '/'; 7 | const NumberTriviaRoute({Key? key}) : super(key: key); 8 | 9 | @override 10 | Widget build(BuildContext context) { 11 | return Scaffold( 12 | appBar: AppBar( 13 | title: const Text('Number Trivia'), 14 | ), 15 | body: const SingleChildScrollView( 16 | child: NumberTriviaRouteBody(), 17 | ), 18 | ); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/widgets/loading_widget.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class LoadingWidget extends StatelessWidget { 4 | const LoadingWidget({ 5 | Key? key, 6 | }) : super(key: key); 7 | 8 | @override 9 | Widget build(BuildContext context) { 10 | final size = MediaQuery.of(context).size; 11 | 12 | return Container( 13 | height: size.height / 3, 14 | alignment: Alignment.center, 15 | child: const CircularProgressIndicator.adaptive(), 16 | ); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/widgets/message_display.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class MessageDisplay extends StatelessWidget { 4 | final String _message; 5 | 6 | const MessageDisplay({ 7 | Key? key, 8 | required String message, 9 | }) : _message = message, 10 | super(key: key); 11 | 12 | @override 13 | Widget build(BuildContext context) { 14 | final size = MediaQuery.of(context).size; 15 | 16 | return Container( 17 | height: size.height / 3, 18 | alignment: Alignment.center, 19 | child: SingleChildScrollView( 20 | child: Text( 21 | _message, 22 | style: const TextStyle( 23 | fontSize: 25, 24 | ), 25 | textAlign: TextAlign.center, 26 | ), 27 | ), 28 | ); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/widgets/number_trivia_route_body.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_bloc/flutter_bloc.dart'; 3 | 4 | import '../../../../injection_container.dart'; 5 | import '../bloc/number_trivia_bloc.dart'; 6 | import '../bloc/state/initial_number_trivia_state.dart'; 7 | import '../bloc/state/loaded_number_trivia_state.dart'; 8 | import '../bloc/state/loading_number_trivia_state.dart'; 9 | import '../bloc/state/number_trivia_retrieval_error_state.dart'; 10 | import 'widgets.dart'; 11 | 12 | class NumberTriviaRouteBody extends StatelessWidget { 13 | const NumberTriviaRouteBody({ 14 | Key? key, 15 | }) : super(key: key); 16 | 17 | @override 18 | Widget build(BuildContext context) { 19 | return BlocProvider( 20 | create: (_) => serviceLocator.get(), 21 | child: Container( 22 | padding: const EdgeInsets.all(10), 23 | alignment: Alignment.center, 24 | child: Column( 25 | children: [ 26 | const SizedBox( 27 | height: 10, 28 | ), 29 | BlocBuilder( 30 | builder: (context, state) { 31 | late final Widget widget; 32 | 33 | if (state is InitialNumberTriviaState) { 34 | widget = const MessageDisplay( 35 | message: 'Start searching!', 36 | ); 37 | } else if (state is LoadingNumberTriviaState) { 38 | widget = const LoadingWidget(); 39 | } else if (state is LoadedNumberTriviaState) { 40 | widget = TriviaDisplay( 41 | numberTrivia: state.trivia, 42 | ); 43 | } else if (state is NumberTriviaRetrievalErrorState) { 44 | widget = MessageDisplay( 45 | message: state.message, 46 | ); 47 | } 48 | return widget; 49 | }, 50 | ), 51 | const SizedBox( 52 | height: 20, 53 | ), 54 | const TriviaControl(), 55 | ], 56 | ), 57 | ), 58 | ); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/widgets/trivia_control.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_bloc/flutter_bloc.dart'; 3 | 4 | import '../bloc/events/get_trivia_for_concrete_number.dart'; 5 | import '../bloc/events/get_trivia_for_random_number.dart'; 6 | import '../bloc/number_trivia_bloc.dart'; 7 | 8 | class TriviaControl extends StatefulWidget { 9 | const TriviaControl({ 10 | Key? key, 11 | }) : super(key: key); 12 | 13 | @override 14 | State createState() => _TriviaControlState(); 15 | } 16 | 17 | class _TriviaControlState extends State { 18 | final controller = TextEditingController(); 19 | String input = ''; 20 | 21 | @override 22 | Widget build(BuildContext context) { 23 | return Column( 24 | children: [ 25 | TextField( 26 | controller: controller, 27 | keyboardType: TextInputType.number, 28 | decoration: const InputDecoration( 29 | border: OutlineInputBorder(), 30 | hintText: 'Input a number', 31 | ), 32 | onChanged: (value) { 33 | input = value; 34 | }, 35 | onSubmitted: (value) { 36 | dispatchConcrete(); 37 | }, 38 | ), 39 | const SizedBox( 40 | height: 10, 41 | ), 42 | Row( 43 | children: [ 44 | Expanded( 45 | child: ElevatedButton( 46 | style: ElevatedButton.styleFrom( 47 | backgroundColor: Theme.of(context).colorScheme.secondary, 48 | ), 49 | onPressed: dispatchConcrete, 50 | child: const Text('Search'), 51 | ), 52 | ), 53 | const SizedBox( 54 | width: 10, 55 | ), 56 | Expanded( 57 | child: ElevatedButton( 58 | onPressed: dispatchRandom, 59 | child: const Text('Get random trivia'), 60 | ), 61 | ), 62 | ], 63 | ), 64 | ], 65 | ); 66 | } 67 | 68 | void dispatchConcrete() { 69 | controller.clear(); 70 | 71 | BlocProvider.of(context) 72 | .add(GetTriviaForConcreteNumber(input)); 73 | } 74 | 75 | void dispatchRandom() { 76 | controller.clear(); 77 | 78 | BlocProvider.of(context).add(GetTriviaForRandomNumber()); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/widgets/trivia_display.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | import '../../domain/entities/number_trivia.dart'; 4 | 5 | class TriviaDisplay extends StatelessWidget { 6 | final NumberTrivia numberTrivia; 7 | 8 | const TriviaDisplay({ 9 | Key? key, 10 | required this.numberTrivia, 11 | }) : super(key: key); 12 | 13 | @override 14 | Widget build(BuildContext context) { 15 | final size = MediaQuery.of(context).size; 16 | 17 | return SizedBox( 18 | height: size.height / 3, 19 | child: Column( 20 | children: [ 21 | Text( 22 | numberTrivia.number.toString(), 23 | style: const TextStyle( 24 | fontSize: 50, 25 | fontWeight: FontWeight.bold, 26 | ), 27 | ), 28 | Expanded( 29 | child: Center( 30 | child: SingleChildScrollView( 31 | child: Text( 32 | numberTrivia.text, 33 | style: const TextStyle( 34 | fontSize: 25, 35 | ), 36 | textAlign: TextAlign.center, 37 | ), 38 | ), 39 | ), 40 | ), 41 | ], 42 | ), 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/widgets/widgets.dart: -------------------------------------------------------------------------------- 1 | export 'loading_widget.dart'; 2 | export 'message_display.dart'; 3 | export 'trivia_control.dart'; 4 | export 'trivia_display.dart'; 5 | -------------------------------------------------------------------------------- /lib/injection_container.dart: -------------------------------------------------------------------------------- 1 | import 'package:get_it/get_it.dart'; 2 | import 'package:http/http.dart'; 3 | import 'package:internet_connection_checker/internet_connection_checker.dart'; 4 | import 'package:shared_preferences/shared_preferences.dart'; 5 | 6 | import 'core/network/network_information.dart'; 7 | import 'core/network/network_information_implementation.dart'; 8 | import 'core/utilities/input_converter.dart'; 9 | import 'features/number_trivia/data/data_sources/local_data_source/number_trivia_local_data_source.dart'; 10 | import 'features/number_trivia/data/data_sources/local_data_source/number_trivia_local_data_source_implementation.dart'; 11 | import 'features/number_trivia/data/data_sources/remote_data_source/number_trivia_remote_data_source.dart'; 12 | import 'features/number_trivia/data/data_sources/remote_data_source/number_trivia_remote_data_source_implementation.dart'; 13 | import 'features/number_trivia/data/repositories/number_trivia_repository_implementation.dart'; 14 | import 'features/number_trivia/domain/repositories/number_trivia_repository.dart'; 15 | import 'features/number_trivia/domain/use_cases/get_concrete_number_trivia.dart'; 16 | import 'features/number_trivia/domain/use_cases/get_random_number_trivia.dart'; 17 | import 'features/number_trivia/presentation/bloc/number_trivia_bloc.dart'; 18 | 19 | final serviceLocator = GetIt.instance; 20 | 21 | Future initializeServiceLocator() async { 22 | //! Features - NumberTrivia 23 | //* presentation logic holder 24 | serviceLocator.registerFactory( 25 | () => NumberTriviaBloc( 26 | getConcreteNumberTrivia: serviceLocator(), 27 | getRandomNumberTrivia: serviceLocator(), 28 | inputConverter: serviceLocator(), 29 | ), 30 | ); 31 | 32 | //* use cases 33 | serviceLocator 34 | .registerLazySingleton(() => GetConcreteNumberTrivia(serviceLocator())); 35 | 36 | serviceLocator 37 | .registerLazySingleton(() => GetRandomNumberTrivia(serviceLocator())); 38 | 39 | //* repository 40 | serviceLocator.registerLazySingleton( 41 | () => NumberTriviaRepositoryImplementation( 42 | remoteDataSource: serviceLocator(), 43 | localDataSource: serviceLocator(), 44 | networkInformation: serviceLocator(), 45 | ), 46 | ); 47 | 48 | //* data sources 49 | serviceLocator.registerLazySingleton( 50 | () => NumberTriviaRemoteDataSourceImplementation( 51 | client: serviceLocator(), 52 | ), 53 | ); 54 | 55 | serviceLocator.registerLazySingleton( 56 | () => NumberTriviaLocalDataSourceImplementation( 57 | sharedPreferences: serviceLocator(), 58 | ), 59 | ); 60 | 61 | //! Core 62 | serviceLocator.registerLazySingleton(() => InputConverter()); 63 | 64 | serviceLocator.registerLazySingleton( 65 | () => NetworkInformationImplementation(serviceLocator())); 66 | 67 | //! External 68 | final sharedPreferences = await SharedPreferences.getInstance(); 69 | 70 | serviceLocator.registerLazySingleton(() => sharedPreferences); 71 | serviceLocator.registerLazySingleton(() => Client()); 72 | serviceLocator.registerLazySingleton(() => InternetConnectionChecker()); 73 | } 74 | -------------------------------------------------------------------------------- /lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | import 'features/number_trivia/presentation/routes/number_trivia_route.dart'; 4 | import 'injection_container.dart'; 5 | 6 | void main() async { 7 | WidgetsFlutterBinding.ensureInitialized(); 8 | 9 | initializeServiceLocator().then((_) => runApp(const MyApp())); 10 | } 11 | 12 | class MyApp extends StatelessWidget { 13 | const MyApp({Key? key}) : super(key: key); 14 | 15 | @override 16 | Widget build(BuildContext context) { 17 | final theme = ThemeData( 18 | primaryColor: Colors.green.shade800, 19 | primarySwatch: Colors.green, 20 | ); 21 | 22 | return MaterialApp( 23 | debugShowCheckedModeBanner: false, 24 | theme: theme.copyWith( 25 | colorScheme: theme.colorScheme.copyWith( 26 | secondary: Colors.green.shade600, 27 | ), 28 | ), 29 | home: const NumberTriviaRoute(), 30 | ); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | _fe_analyzer_shared: 5 | dependency: transitive 6 | description: 7 | name: _fe_analyzer_shared 8 | sha256: "8880b4cfe7b5b17d57c052a5a3a8cc1d4f546261c7cc8fbd717bd53f48db0568" 9 | url: "https://pub.dev" 10 | source: hosted 11 | version: "59.0.0" 12 | analyzer: 13 | dependency: transitive 14 | description: 15 | name: analyzer 16 | sha256: a89627f49b0e70e068130a36571409726b04dab12da7e5625941d2c8ec278b96 17 | url: "https://pub.dev" 18 | source: hosted 19 | version: "5.11.1" 20 | args: 21 | dependency: transitive 22 | description: 23 | name: args 24 | sha256: "4cab82a83ffef80b262ddedf47a0a8e56ee6fbf7fe21e6e768b02792034dd440" 25 | url: "https://pub.dev" 26 | source: hosted 27 | version: "2.4.0" 28 | async: 29 | dependency: transitive 30 | description: 31 | name: async 32 | sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" 33 | url: "https://pub.dev" 34 | source: hosted 35 | version: "2.11.0" 36 | bloc: 37 | dependency: transitive 38 | description: 39 | name: bloc 40 | sha256: "658a5ae59edcf1e58aac98b000a71c762ad8f46f1394c34a52050cafb3e11a80" 41 | url: "https://pub.dev" 42 | source: hosted 43 | version: "8.1.1" 44 | boolean_selector: 45 | dependency: transitive 46 | description: 47 | name: boolean_selector 48 | sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" 49 | url: "https://pub.dev" 50 | source: hosted 51 | version: "2.1.1" 52 | characters: 53 | dependency: transitive 54 | description: 55 | name: characters 56 | sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" 57 | url: "https://pub.dev" 58 | source: hosted 59 | version: "1.3.0" 60 | clock: 61 | dependency: transitive 62 | description: 63 | name: clock 64 | sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf 65 | url: "https://pub.dev" 66 | source: hosted 67 | version: "1.1.1" 68 | collection: 69 | dependency: transitive 70 | description: 71 | name: collection 72 | sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" 73 | url: "https://pub.dev" 74 | source: hosted 75 | version: "1.17.1" 76 | convert: 77 | dependency: transitive 78 | description: 79 | name: convert 80 | sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" 81 | url: "https://pub.dev" 82 | source: hosted 83 | version: "3.1.1" 84 | coverage: 85 | dependency: transitive 86 | description: 87 | name: coverage 88 | sha256: "2fb815080e44a09b85e0f2ca8a820b15053982b2e714b59267719e8a9ff17097" 89 | url: "https://pub.dev" 90 | source: hosted 91 | version: "1.6.3" 92 | crypto: 93 | dependency: transitive 94 | description: 95 | name: crypto 96 | sha256: aa274aa7774f8964e4f4f38cc994db7b6158dd36e9187aaceaddc994b35c6c67 97 | url: "https://pub.dev" 98 | source: hosted 99 | version: "3.0.2" 100 | dartz: 101 | dependency: "direct main" 102 | description: 103 | name: dartz 104 | sha256: e6acf34ad2e31b1eb00948692468c30ab48ac8250e0f0df661e29f12dd252168 105 | url: "https://pub.dev" 106 | source: hosted 107 | version: "0.10.1" 108 | equatable: 109 | dependency: "direct main" 110 | description: 111 | name: equatable 112 | sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2 113 | url: "https://pub.dev" 114 | source: hosted 115 | version: "2.0.5" 116 | fake_async: 117 | dependency: transitive 118 | description: 119 | name: fake_async 120 | sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" 121 | url: "https://pub.dev" 122 | source: hosted 123 | version: "1.3.1" 124 | ffi: 125 | dependency: transitive 126 | description: 127 | name: ffi 128 | sha256: a38574032c5f1dd06c4aee541789906c12ccaab8ba01446e800d9c5b79c4a978 129 | url: "https://pub.dev" 130 | source: hosted 131 | version: "2.0.1" 132 | file: 133 | dependency: transitive 134 | description: 135 | name: file 136 | sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d" 137 | url: "https://pub.dev" 138 | source: hosted 139 | version: "6.1.4" 140 | flutter: 141 | dependency: "direct main" 142 | description: flutter 143 | source: sdk 144 | version: "0.0.0" 145 | flutter_bloc: 146 | dependency: "direct main" 147 | description: 148 | name: flutter_bloc 149 | sha256: e74efb89ee6945bcbce74a5b3a5a3376b088e5f21f55c263fc38cbdc6237faae 150 | url: "https://pub.dev" 151 | source: hosted 152 | version: "8.1.3" 153 | flutter_lints: 154 | dependency: "direct dev" 155 | description: 156 | name: flutter_lints 157 | sha256: aeb0b80a8b3709709c9cc496cdc027c5b3216796bc0af0ce1007eaf24464fd4c 158 | url: "https://pub.dev" 159 | source: hosted 160 | version: "2.0.1" 161 | flutter_test: 162 | dependency: "direct dev" 163 | description: flutter 164 | source: sdk 165 | version: "0.0.0" 166 | flutter_web_plugins: 167 | dependency: transitive 168 | description: flutter 169 | source: sdk 170 | version: "0.0.0" 171 | frontend_server_client: 172 | dependency: transitive 173 | description: 174 | name: frontend_server_client 175 | sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612" 176 | url: "https://pub.dev" 177 | source: hosted 178 | version: "3.2.0" 179 | get_it: 180 | dependency: "direct main" 181 | description: 182 | name: get_it 183 | sha256: "529de303c739fca98cd7ece5fca500d8ff89649f1bb4b4e94fb20954abcd7468" 184 | url: "https://pub.dev" 185 | source: hosted 186 | version: "7.6.0" 187 | glob: 188 | dependency: transitive 189 | description: 190 | name: glob 191 | sha256: "4515b5b6ddb505ebdd242a5f2cc5d22d3d6a80013789debfbda7777f47ea308c" 192 | url: "https://pub.dev" 193 | source: hosted 194 | version: "2.1.1" 195 | http: 196 | dependency: "direct main" 197 | description: 198 | name: http 199 | sha256: "4c3f04bfb64d3efd508d06b41b825542f08122d30bda4933fb95c069d22a4fa3" 200 | url: "https://pub.dev" 201 | source: hosted 202 | version: "1.0.0" 203 | http_multi_server: 204 | dependency: transitive 205 | description: 206 | name: http_multi_server 207 | sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" 208 | url: "https://pub.dev" 209 | source: hosted 210 | version: "3.2.1" 211 | http_parser: 212 | dependency: transitive 213 | description: 214 | name: http_parser 215 | sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" 216 | url: "https://pub.dev" 217 | source: hosted 218 | version: "4.0.2" 219 | internet_connection_checker: 220 | dependency: "direct main" 221 | description: 222 | name: internet_connection_checker 223 | sha256: "1c683e63e89c9ac66a40748b1b20889fd9804980da732bf2b58d6d5456c8e876" 224 | url: "https://pub.dev" 225 | source: hosted 226 | version: "1.0.0+1" 227 | io: 228 | dependency: transitive 229 | description: 230 | name: io 231 | sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" 232 | url: "https://pub.dev" 233 | source: hosted 234 | version: "1.0.4" 235 | js: 236 | dependency: transitive 237 | description: 238 | name: js 239 | sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 240 | url: "https://pub.dev" 241 | source: hosted 242 | version: "0.6.7" 243 | lints: 244 | dependency: transitive 245 | description: 246 | name: lints 247 | sha256: "5e4a9cd06d447758280a8ac2405101e0e2094d2a1dbdd3756aec3fe7775ba593" 248 | url: "https://pub.dev" 249 | source: hosted 250 | version: "2.0.1" 251 | logging: 252 | dependency: transitive 253 | description: 254 | name: logging 255 | sha256: "04094f2eb032cbb06c6f6e8d3607edcfcb0455e2bb6cbc010cb01171dcb64e6d" 256 | url: "https://pub.dev" 257 | source: hosted 258 | version: "1.1.1" 259 | matcher: 260 | dependency: transitive 261 | description: 262 | name: matcher 263 | sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb" 264 | url: "https://pub.dev" 265 | source: hosted 266 | version: "0.12.15" 267 | material_color_utilities: 268 | dependency: transitive 269 | description: 270 | name: material_color_utilities 271 | sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 272 | url: "https://pub.dev" 273 | source: hosted 274 | version: "0.2.0" 275 | meta: 276 | dependency: transitive 277 | description: 278 | name: meta 279 | sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" 280 | url: "https://pub.dev" 281 | source: hosted 282 | version: "1.9.1" 283 | mime: 284 | dependency: transitive 285 | description: 286 | name: mime 287 | sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e 288 | url: "https://pub.dev" 289 | source: hosted 290 | version: "1.0.4" 291 | mocktail: 292 | dependency: "direct dev" 293 | description: 294 | name: mocktail 295 | sha256: "80a996cd9a69284b3dc521ce185ffe9150cde69767c2d3a0720147d93c0cef53" 296 | url: "https://pub.dev" 297 | source: hosted 298 | version: "0.3.0" 299 | nested: 300 | dependency: transitive 301 | description: 302 | name: nested 303 | sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20" 304 | url: "https://pub.dev" 305 | source: hosted 306 | version: "1.0.0" 307 | node_preamble: 308 | dependency: transitive 309 | description: 310 | name: node_preamble 311 | sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" 312 | url: "https://pub.dev" 313 | source: hosted 314 | version: "2.0.2" 315 | package_config: 316 | dependency: transitive 317 | description: 318 | name: package_config 319 | sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" 320 | url: "https://pub.dev" 321 | source: hosted 322 | version: "2.1.0" 323 | path: 324 | dependency: transitive 325 | description: 326 | name: path 327 | sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" 328 | url: "https://pub.dev" 329 | source: hosted 330 | version: "1.8.3" 331 | path_provider_linux: 332 | dependency: transitive 333 | description: 334 | name: path_provider_linux 335 | sha256: "2ae08f2216225427e64ad224a24354221c2c7907e448e6e0e8b57b1eb9f10ad1" 336 | url: "https://pub.dev" 337 | source: hosted 338 | version: "2.1.10" 339 | path_provider_platform_interface: 340 | dependency: transitive 341 | description: 342 | name: path_provider_platform_interface 343 | sha256: "57585299a729335f1298b43245842678cb9f43a6310351b18fb577d6e33165ec" 344 | url: "https://pub.dev" 345 | source: hosted 346 | version: "2.0.6" 347 | path_provider_windows: 348 | dependency: transitive 349 | description: 350 | name: path_provider_windows 351 | sha256: d3f80b32e83ec208ac95253e0cd4d298e104fbc63cb29c5c69edaed43b0c69d6 352 | url: "https://pub.dev" 353 | source: hosted 354 | version: "2.1.6" 355 | platform: 356 | dependency: transitive 357 | description: 358 | name: platform 359 | sha256: "4a451831508d7d6ca779f7ac6e212b4023dd5a7d08a27a63da33756410e32b76" 360 | url: "https://pub.dev" 361 | source: hosted 362 | version: "3.1.0" 363 | plugin_platform_interface: 364 | dependency: transitive 365 | description: 366 | name: plugin_platform_interface 367 | sha256: "6a2128648c854906c53fa8e33986fc0247a1116122f9534dd20e3ab9e16a32bc" 368 | url: "https://pub.dev" 369 | source: hosted 370 | version: "2.1.4" 371 | pool: 372 | dependency: transitive 373 | description: 374 | name: pool 375 | sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" 376 | url: "https://pub.dev" 377 | source: hosted 378 | version: "1.5.1" 379 | process: 380 | dependency: transitive 381 | description: 382 | name: process 383 | sha256: "53fd8db9cec1d37b0574e12f07520d582019cb6c44abf5479a01505099a34a09" 384 | url: "https://pub.dev" 385 | source: hosted 386 | version: "4.2.4" 387 | provider: 388 | dependency: transitive 389 | description: 390 | name: provider 391 | sha256: cdbe7530b12ecd9eb455bdaa2fcb8d4dad22e80b8afb4798b41479d5ce26847f 392 | url: "https://pub.dev" 393 | source: hosted 394 | version: "6.0.5" 395 | pub_semver: 396 | dependency: transitive 397 | description: 398 | name: pub_semver 399 | sha256: "307de764d305289ff24ad257ad5c5793ce56d04947599ad68b3baa124105fc17" 400 | url: "https://pub.dev" 401 | source: hosted 402 | version: "2.1.3" 403 | shared_preferences: 404 | dependency: "direct main" 405 | description: 406 | name: shared_preferences 407 | sha256: "16d3fb6b3692ad244a695c0183fca18cf81fd4b821664394a781de42386bf022" 408 | url: "https://pub.dev" 409 | source: hosted 410 | version: "2.1.1" 411 | shared_preferences_android: 412 | dependency: transitive 413 | description: 414 | name: shared_preferences_android 415 | sha256: "6478c6bbbecfe9aced34c483171e90d7c078f5883558b30ec3163cf18402c749" 416 | url: "https://pub.dev" 417 | source: hosted 418 | version: "2.1.4" 419 | shared_preferences_foundation: 420 | dependency: transitive 421 | description: 422 | name: shared_preferences_foundation 423 | sha256: "0c1c16c56c9708aa9c361541a6f0e5cc6fc12a3232d866a687a7b7db30032b07" 424 | url: "https://pub.dev" 425 | source: hosted 426 | version: "2.2.1" 427 | shared_preferences_linux: 428 | dependency: transitive 429 | description: 430 | name: shared_preferences_linux 431 | sha256: "9d387433ca65717bbf1be88f4d5bb18f10508917a8fa2fb02e0fd0d7479a9afa" 432 | url: "https://pub.dev" 433 | source: hosted 434 | version: "2.2.0" 435 | shared_preferences_platform_interface: 436 | dependency: transitive 437 | description: 438 | name: shared_preferences_platform_interface 439 | sha256: fb5cf25c0235df2d0640ac1b1174f6466bd311f621574997ac59018a6664548d 440 | url: "https://pub.dev" 441 | source: hosted 442 | version: "2.2.0" 443 | shared_preferences_web: 444 | dependency: transitive 445 | description: 446 | name: shared_preferences_web 447 | sha256: "74083203a8eae241e0de4a0d597dbedab3b8fef5563f33cf3c12d7e93c655ca5" 448 | url: "https://pub.dev" 449 | source: hosted 450 | version: "2.1.0" 451 | shared_preferences_windows: 452 | dependency: transitive 453 | description: 454 | name: shared_preferences_windows 455 | sha256: "5e588e2efef56916a3b229c3bfe81e6a525665a454519ca51dbcc4236a274173" 456 | url: "https://pub.dev" 457 | source: hosted 458 | version: "2.2.0" 459 | shelf: 460 | dependency: transitive 461 | description: 462 | name: shelf 463 | sha256: c24a96135a2ccd62c64b69315a14adc5c3419df63b4d7c05832a346fdb73682c 464 | url: "https://pub.dev" 465 | source: hosted 466 | version: "1.4.0" 467 | shelf_packages_handler: 468 | dependency: transitive 469 | description: 470 | name: shelf_packages_handler 471 | sha256: aef74dc9195746a384843102142ab65b6a4735bb3beea791e63527b88cc83306 472 | url: "https://pub.dev" 473 | source: hosted 474 | version: "3.0.1" 475 | shelf_static: 476 | dependency: transitive 477 | description: 478 | name: shelf_static 479 | sha256: e792b76b96a36d4a41b819da593aff4bdd413576b3ba6150df5d8d9996d2e74c 480 | url: "https://pub.dev" 481 | source: hosted 482 | version: "1.1.1" 483 | shelf_web_socket: 484 | dependency: transitive 485 | description: 486 | name: shelf_web_socket 487 | sha256: a988c0e8d8ffbdb8a28aa7ec8e449c260f3deb808781fe1284d22c5bba7156e8 488 | url: "https://pub.dev" 489 | source: hosted 490 | version: "1.0.3" 491 | sky_engine: 492 | dependency: transitive 493 | description: flutter 494 | source: sdk 495 | version: "0.0.99" 496 | source_map_stack_trace: 497 | dependency: transitive 498 | description: 499 | name: source_map_stack_trace 500 | sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae" 501 | url: "https://pub.dev" 502 | source: hosted 503 | version: "2.1.1" 504 | source_maps: 505 | dependency: transitive 506 | description: 507 | name: source_maps 508 | sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703" 509 | url: "https://pub.dev" 510 | source: hosted 511 | version: "0.10.12" 512 | source_span: 513 | dependency: transitive 514 | description: 515 | name: source_span 516 | sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 517 | url: "https://pub.dev" 518 | source: hosted 519 | version: "1.9.1" 520 | stack_trace: 521 | dependency: transitive 522 | description: 523 | name: stack_trace 524 | sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 525 | url: "https://pub.dev" 526 | source: hosted 527 | version: "1.11.0" 528 | stream_channel: 529 | dependency: transitive 530 | description: 531 | name: stream_channel 532 | sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" 533 | url: "https://pub.dev" 534 | source: hosted 535 | version: "2.1.1" 536 | string_scanner: 537 | dependency: transitive 538 | description: 539 | name: string_scanner 540 | sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" 541 | url: "https://pub.dev" 542 | source: hosted 543 | version: "1.2.0" 544 | term_glyph: 545 | dependency: transitive 546 | description: 547 | name: term_glyph 548 | sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 549 | url: "https://pub.dev" 550 | source: hosted 551 | version: "1.2.1" 552 | test: 553 | dependency: transitive 554 | description: 555 | name: test 556 | sha256: "3dac9aecf2c3991d09b9cdde4f98ded7b30804a88a0d7e4e7e1678e78d6b97f4" 557 | url: "https://pub.dev" 558 | source: hosted 559 | version: "1.24.1" 560 | test_api: 561 | dependency: transitive 562 | description: 563 | name: test_api 564 | sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb 565 | url: "https://pub.dev" 566 | source: hosted 567 | version: "0.5.1" 568 | test_core: 569 | dependency: transitive 570 | description: 571 | name: test_core 572 | sha256: "5138dbffb77b2289ecb12b81c11ba46036590b72a64a7a90d6ffb880f1a29e93" 573 | url: "https://pub.dev" 574 | source: hosted 575 | version: "0.5.1" 576 | typed_data: 577 | dependency: transitive 578 | description: 579 | name: typed_data 580 | sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5" 581 | url: "https://pub.dev" 582 | source: hosted 583 | version: "1.3.1" 584 | vector_math: 585 | dependency: transitive 586 | description: 587 | name: vector_math 588 | sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" 589 | url: "https://pub.dev" 590 | source: hosted 591 | version: "2.1.4" 592 | vm_service: 593 | dependency: transitive 594 | description: 595 | name: vm_service 596 | sha256: e7fb6c2282f7631712b69c19d1bff82f3767eea33a2321c14fa59ad67ea391c7 597 | url: "https://pub.dev" 598 | source: hosted 599 | version: "9.4.0" 600 | watcher: 601 | dependency: transitive 602 | description: 603 | name: watcher 604 | sha256: "6a7f46926b01ce81bfc339da6a7f20afbe7733eff9846f6d6a5466aa4c6667c0" 605 | url: "https://pub.dev" 606 | source: hosted 607 | version: "1.0.2" 608 | web_socket_channel: 609 | dependency: transitive 610 | description: 611 | name: web_socket_channel 612 | sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b 613 | url: "https://pub.dev" 614 | source: hosted 615 | version: "2.4.0" 616 | webkit_inspection_protocol: 617 | dependency: transitive 618 | description: 619 | name: webkit_inspection_protocol 620 | sha256: "67d3a8b6c79e1987d19d848b0892e582dbb0c66c57cc1fef58a177dd2aa2823d" 621 | url: "https://pub.dev" 622 | source: hosted 623 | version: "1.2.0" 624 | win32: 625 | dependency: transitive 626 | description: 627 | name: win32 628 | sha256: dd8f9344bc305ae2923e3d11a2a911d9a4e2c7dd6fe0ed10626d63211a69676e 629 | url: "https://pub.dev" 630 | source: hosted 631 | version: "4.1.3" 632 | xdg_directories: 633 | dependency: transitive 634 | description: 635 | name: xdg_directories 636 | sha256: ee1505df1426458f7f60aac270645098d318a8b4766d85fde75f76f2e21807d1 637 | url: "https://pub.dev" 638 | source: hosted 639 | version: "1.0.0" 640 | yaml: 641 | dependency: transitive 642 | description: 643 | name: yaml 644 | sha256: "23812a9b125b48d4007117254bca50abb6c712352927eece9e155207b1db2370" 645 | url: "https://pub.dev" 646 | source: hosted 647 | version: "3.1.1" 648 | sdks: 649 | dart: ">=3.0.3 <4.0.0" 650 | flutter: ">=3.0.0" 651 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: clean_architecture 2 | description: A new Flutter project. 3 | publish_to: "none" 4 | version: 1.0.0+1 5 | 6 | environment: 7 | sdk: ">=3.0.3 <4.0.0" 8 | 9 | dependencies: 10 | dartz: ^0.10.1 11 | equatable: ^2.0.5 12 | flutter: 13 | sdk: flutter 14 | flutter_bloc: ^8.1.3 15 | get_it: ^7.6.0 16 | http: ^1.0.0 17 | internet_connection_checker: ^1.0.0+1 18 | shared_preferences: ^2.1.1 19 | 20 | dev_dependencies: 21 | flutter_lints: ^2.0.1 22 | flutter_test: 23 | sdk: flutter 24 | mocktail: ^0.3.0 25 | 26 | flutter: 27 | uses-material-design: true 28 | -------------------------------------------------------------------------------- /test/core/network/network_information_implementation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:internet_connection_checker/internet_connection_checker.dart'; 2 | import 'package:mocktail/mocktail.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | 5 | class MockInternetConnectionChecker extends Mock 6 | implements InternetConnectionChecker {} 7 | 8 | void main() { 9 | late MockInternetConnectionChecker mockInternetConnectionChecker; 10 | 11 | setUp(() { 12 | mockInternetConnectionChecker = MockInternetConnectionChecker(); 13 | }); 14 | 15 | group('isConnected', () { 16 | test( 17 | 'should forward the call to DataConnectionChecker.hasConnection', 18 | () { 19 | // arrange 20 | final testHasConnectionFuture = Future.value(true); 21 | 22 | when(() => mockInternetConnectionChecker.hasConnection) 23 | .thenAnswer((_) => testHasConnectionFuture); 24 | 25 | // act 26 | final result = mockInternetConnectionChecker.hasConnection; 27 | 28 | // assert 29 | verify(() => mockInternetConnectionChecker.hasConnection); 30 | expect(result, equals(testHasConnectionFuture)); 31 | }, 32 | ); 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /test/core/utilities/input_converter_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:clean_architecture/core/error/failures/invalid_input_failure.dart'; 2 | import 'package:clean_architecture/core/utilities/input_converter.dart'; 3 | import 'package:dartz/dartz.dart'; 4 | import 'package:flutter_test/flutter_test.dart'; 5 | 6 | void main() { 7 | late InputConverter inputConverter; 8 | 9 | setUp(() { 10 | inputConverter = InputConverter(); 11 | }); 12 | 13 | group('stringToUnsignedInt', () { 14 | test( 15 | 'should return an integer when the string represents an unsigned integer', 16 | () { 17 | // Arrange 18 | const str = '123'; 19 | 20 | // Act 21 | final result = inputConverter.stringToUnsignedInteger(str); 22 | 23 | // Assert 24 | expect(result, equals(const Right(123))); 25 | }, 26 | ); 27 | 28 | test('should return a failure when the string is not an integer', () { 29 | // Arrange 30 | const str = 'abc'; 31 | 32 | // Act 33 | final result = inputConverter.stringToUnsignedInteger(str); 34 | 35 | // Assert 36 | expect(result, equals(Left(InvalidInputFailure()))); 37 | }); 38 | 39 | test('should return a failure when the string is a negative integer', () { 40 | // Arrange 41 | const str = '-123'; 42 | 43 | // Act 44 | final result = inputConverter.stringToUnsignedInteger(str); 45 | 46 | // Assert 47 | expect(result, equals(Left(InvalidInputFailure()))); 48 | }); 49 | }); 50 | } 51 | -------------------------------------------------------------------------------- /test/features/number_trivia/data/data_sources/local_data_source/number_trivia_local_data_source_implementation_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:clean_architecture/core/error/exceptions/cache_exception.dart'; 4 | import 'package:clean_architecture/features/number_trivia/data/data_sources/local_data_source/number_trivia_local_data_source_implementation.dart'; 5 | import 'package:clean_architecture/features/number_trivia/data/models/number_trivia_model.dart'; 6 | import 'package:flutter_test/flutter_test.dart'; 7 | import 'package:mocktail/mocktail.dart'; 8 | import 'package:shared_preferences/shared_preferences.dart'; 9 | 10 | import '../../../../../fixtures/fixture_reader.dart'; 11 | 12 | class MockSharedPreferences extends Mock implements SharedPreferences {} 13 | 14 | void main() { 15 | late NumberTriviaLocalDataSourceImplementation dataSource; 16 | late MockSharedPreferences mockSharedPreferences; 17 | 18 | setUp(() { 19 | mockSharedPreferences = MockSharedPreferences(); 20 | 21 | dataSource = NumberTriviaLocalDataSourceImplementation( 22 | sharedPreferences: mockSharedPreferences, 23 | ); 24 | }); 25 | 26 | group('getLastNumberTrivia', () { 27 | final testNumberTriviaModel = 28 | NumberTriviaModel.fromJson(json.decode(fixture('trivia_cached.json'))); 29 | test( 30 | 'should return number trivia model from SharedPreferences when there is one in the cache', 31 | () async { 32 | // Arrange 33 | when(() => mockSharedPreferences.getString(any())) 34 | .thenReturn(fixture('trivia_cached.json')); 35 | 36 | // Act 37 | final result = await dataSource.getLastNumberTrivia(); 38 | 39 | // Assert 40 | verify(() => mockSharedPreferences.getString(cachedNumberTrivia)); 41 | expect(result, equals(testNumberTriviaModel)); 42 | }, 43 | ); 44 | 45 | test( 46 | 'should throw a cache exception when there is not a cached value', 47 | () async { 48 | // Arrange 49 | when(() => mockSharedPreferences.getString(any())).thenReturn(null); 50 | 51 | // Act 52 | final call = dataSource.getLastNumberTrivia; 53 | 54 | // Assert 55 | expect(() => call(), throwsA(const TypeMatcher())); 56 | }, 57 | ); 58 | }); 59 | 60 | group('cacheNumberTrivia', () { 61 | const testNumberTriviaModel = NumberTriviaModel( 62 | number: 1, 63 | text: 'test trivia', 64 | ); 65 | 66 | test('should call shared preferences to cache the data', () { 67 | // Arrange 68 | when(() => mockSharedPreferences.setString(any(), any())) 69 | .thenAnswer((_) async => true); 70 | 71 | // Act 72 | dataSource.cacheNumberTrivia(testNumberTriviaModel); 73 | 74 | // Assert 75 | final expectedJsonString = json.encode(testNumberTriviaModel.toJson()); 76 | 77 | verify(() => mockSharedPreferences.setString( 78 | cachedNumberTrivia, 79 | expectedJsonString, 80 | )); 81 | }); 82 | }); 83 | } 84 | -------------------------------------------------------------------------------- /test/features/number_trivia/data/data_sources/remote_data_source/number_trivia_remote_data_source_implementation_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:clean_architecture/core/error/exceptions/server_exception.dart'; 4 | import 'package:clean_architecture/features/number_trivia/data/data_sources/remote_data_source/number_trivia_remote_data_source_implementation.dart'; 5 | import 'package:clean_architecture/features/number_trivia/data/models/number_trivia_model.dart'; 6 | import 'package:flutter_test/flutter_test.dart'; 7 | import 'package:http/http.dart' as http; 8 | import 'package:mocktail/mocktail.dart'; 9 | 10 | import '../../../../../fixtures/fixture_reader.dart'; 11 | 12 | class MockHttpClient extends Mock implements http.Client {} 13 | 14 | void main() { 15 | late NumberTriviaRemoteDataSourceImplementation dataSource; 16 | late MockHttpClient mockHttpClient; 17 | 18 | setUpAll(() { 19 | registerFallbackValue(Uri()); 20 | }); 21 | 22 | setUp(() { 23 | mockHttpClient = MockHttpClient(); 24 | 25 | dataSource = NumberTriviaRemoteDataSourceImplementation( 26 | client: mockHttpClient, 27 | ); 28 | }); 29 | 30 | void setUpMockHttpClientSuccess200() { 31 | final trivia = fixture('trivia.json'); 32 | const responseCode = 200; 33 | final response = http.Response(trivia, responseCode); 34 | 35 | when(() => mockHttpClient.get(any(), headers: any(named: 'headers'))) 36 | .thenAnswer((_) async => response); 37 | } 38 | 39 | void setUpMockHttpClientFailure404() { 40 | const responseBody = 'Something went wrong'; 41 | const statusCode = 404; 42 | final response = http.Response(responseBody, statusCode); 43 | 44 | when(() => mockHttpClient.get(any(), headers: any(named: 'headers'))) 45 | .thenAnswer((_) async => response); 46 | } 47 | 48 | group('getConcreteNumberTrivia', () { 49 | const testNumber = 1; 50 | 51 | final testNumberTriviaModel = 52 | NumberTriviaModel.fromJson(json.decode(fixture('trivia.json'))); 53 | 54 | test( 55 | '''should perform a GET request on a URL with number being the endpoint 56 | and with application/json header''', 57 | () { 58 | // Arrange 59 | setUpMockHttpClientSuccess200(); 60 | 61 | // Act 62 | dataSource.getConcreteNumberTrivia(testNumber); 63 | 64 | // Assert 65 | final uri = Uri.parse('http://numbersapi.com/$testNumber'); 66 | 67 | final headers = { 68 | 'Content-Type': 'application/json', 69 | }; 70 | 71 | verify(() => mockHttpClient.get(uri, headers: headers)); 72 | }, 73 | ); 74 | 75 | test( 76 | 'should return NumberTriviaModel when the response code is 200 (success)', 77 | () async { 78 | // Arrange 79 | setUpMockHttpClientSuccess200(); 80 | 81 | // Act 82 | final result = await dataSource.getConcreteNumberTrivia(testNumber); 83 | 84 | // Assert 85 | expect(result, equals(testNumberTriviaModel)); 86 | }, 87 | ); 88 | 89 | test( 90 | 'should throw a server exception when the response code is 404 or any other failure code', 91 | () { 92 | // Arrange 93 | setUpMockHttpClientFailure404(); 94 | 95 | // Act 96 | final call = dataSource.getConcreteNumberTrivia; 97 | 98 | // Assert 99 | expect(() => call(testNumber), throwsA(const TypeMatcher())); 100 | }, 101 | ); 102 | }); 103 | 104 | group('getRandomNumberTrivia', () { 105 | final testNumberTriviaModel = 106 | NumberTriviaModel.fromJson(json.decode(fixture('trivia.json'))); 107 | 108 | test( 109 | '''should perform a GET request on a URL with number being the endpoint 110 | and with application/json header''', 111 | () { 112 | // Arrange 113 | setUpMockHttpClientSuccess200(); 114 | 115 | // Act 116 | dataSource.getRandomNumberTrivia(); 117 | 118 | // Assert 119 | final uri = Uri.parse('http://numbersapi.com/random'); 120 | 121 | final headers = { 122 | 'Content-Type': 'application/json', 123 | }; 124 | 125 | verify(() => mockHttpClient.get(uri, headers: headers)); 126 | }, 127 | ); 128 | 129 | test( 130 | 'should return NumberTriviaModel when the response code is 200 (success)', 131 | () async { 132 | // Arrange 133 | setUpMockHttpClientSuccess200(); 134 | 135 | // Act 136 | final result = await dataSource.getRandomNumberTrivia(); 137 | 138 | // Assert 139 | expect(result, equals(testNumberTriviaModel)); 140 | }, 141 | ); 142 | 143 | test( 144 | 'should throw a server exception when the response code is 404 or any other failure code', 145 | () { 146 | // Arrange 147 | setUpMockHttpClientFailure404(); 148 | 149 | // Act 150 | final call = dataSource.getRandomNumberTrivia; 151 | 152 | // Assert 153 | expect(() => call(), throwsA(const TypeMatcher())); 154 | }, 155 | ); 156 | }); 157 | } 158 | -------------------------------------------------------------------------------- /test/features/number_trivia/data/models/number_trivia_model_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:clean_architecture/features/number_trivia/data/models/number_trivia_model.dart'; 4 | import 'package:clean_architecture/features/number_trivia/domain/entities/number_trivia.dart'; 5 | import 'package:flutter_test/flutter_test.dart'; 6 | 7 | import '../../../../fixtures/fixture_reader.dart'; 8 | 9 | void main() { 10 | const testNumberTriviaModel = NumberTriviaModel(number: 1, text: 'Test Text'); 11 | 12 | test('should be a subclass of number trivia entity', () { 13 | // Assert 14 | expect(testNumberTriviaModel, isA()); 15 | }); 16 | 17 | group('fromJson', () { 18 | test('should return a valid model when the JSON number is int', () { 19 | // Arrange 20 | final Map jsonMap = json.decode(fixture('trivia.json')); 21 | 22 | // Act 23 | final result = NumberTriviaModel.fromJson(jsonMap); 24 | 25 | // Assert 26 | expect(result, testNumberTriviaModel); 27 | }); 28 | 29 | test( 30 | 'should return a valid model when the JSON number is regarded as a double', 31 | () { 32 | // Arrange 33 | final Map jsonMap = 34 | json.decode(fixture('trivia_double.json')); 35 | 36 | // Act 37 | final result = NumberTriviaModel.fromJson(jsonMap); 38 | 39 | // Assert 40 | expect(result, testNumberTriviaModel); 41 | }, 42 | ); 43 | }); 44 | 45 | group('toJson', () { 46 | test('should return a JSON map containing the proper data', () { 47 | // Act 48 | final result = testNumberTriviaModel.toJson(); 49 | 50 | // Assert 51 | final expectedMap = {'text': 'Test Text', 'number': 1}; 52 | 53 | expect(result, equals(expectedMap)); 54 | }); 55 | }); 56 | } 57 | -------------------------------------------------------------------------------- /test/features/number_trivia/data/repositories/number_trivia_repository_implementation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:clean_architecture/core/error/exceptions/cache_exception.dart'; 2 | import 'package:clean_architecture/core/error/exceptions/server_exception.dart'; 3 | import 'package:clean_architecture/core/error/failures/cache_failure.dart'; 4 | import 'package:clean_architecture/core/error/failures/server_failure.dart'; 5 | import 'package:clean_architecture/core/network/network_information.dart'; 6 | import 'package:clean_architecture/features/number_trivia/data/data_sources/local_data_source/number_trivia_local_data_source.dart'; 7 | import 'package:clean_architecture/features/number_trivia/data/data_sources/remote_data_source/number_trivia_remote_data_source.dart'; 8 | import 'package:clean_architecture/features/number_trivia/data/models/number_trivia_model.dart'; 9 | import 'package:clean_architecture/features/number_trivia/data/repositories/number_trivia_repository_implementation.dart'; 10 | import 'package:clean_architecture/features/number_trivia/domain/entities/number_trivia.dart'; 11 | import 'package:dartz/dartz.dart'; 12 | import 'package:flutter_test/flutter_test.dart'; 13 | import 'package:mocktail/mocktail.dart'; 14 | 15 | class MockRemoteDataSource extends Mock 16 | implements NumberTriviaRemoteDataSource {} 17 | 18 | class MockLocalDataSource extends Mock implements NumberTriviaLocalDataSource {} 19 | 20 | class MockNetworkInfo extends Mock implements NetworkInformation {} 21 | 22 | void main() { 23 | late NumberTriviaRepositoryImplementation repository; 24 | late MockRemoteDataSource mockRemoteDataSource; 25 | late MockLocalDataSource mockLocalDataSource; 26 | late MockNetworkInfo mockNetworkInfo; 27 | 28 | setUp(() { 29 | mockRemoteDataSource = MockRemoteDataSource(); 30 | mockLocalDataSource = MockLocalDataSource(); 31 | mockNetworkInfo = MockNetworkInfo(); 32 | 33 | repository = NumberTriviaRepositoryImplementation( 34 | remoteDataSource: mockRemoteDataSource, 35 | localDataSource: mockLocalDataSource, 36 | networkInformation: mockNetworkInfo, 37 | ); 38 | }); 39 | 40 | void runTestsOnline(Function body) { 41 | group('device is online', () { 42 | setUp(() { 43 | when(() => mockNetworkInfo.isConnected).thenAnswer((_) async => true); 44 | }); 45 | 46 | body(); 47 | }); 48 | } 49 | 50 | void runTestsOffline(Function body) { 51 | group('device is offline', () { 52 | setUp(() { 53 | when(() => mockNetworkInfo.isConnected).thenAnswer((_) async => false); 54 | }); 55 | 56 | body(); 57 | }); 58 | } 59 | 60 | group('getConcreteNumberTrivia', () { 61 | const testNumber = 1; 62 | 63 | const testNumberTriviaModel = NumberTriviaModel( 64 | number: testNumber, 65 | text: 'test trivia', 66 | ); 67 | 68 | const NumberTrivia testNumberTrivia = testNumberTriviaModel; 69 | 70 | test('should check if the device is online', () { 71 | // Arrange 72 | when(() => mockNetworkInfo.isConnected).thenAnswer((_) async => true); 73 | 74 | when(() => mockRemoteDataSource.getConcreteNumberTrivia(any())) 75 | .thenAnswer((_) async => testNumberTriviaModel); 76 | 77 | when(() => mockLocalDataSource.cacheNumberTrivia(testNumberTriviaModel)) 78 | .thenAnswer((_) => Future(() {})); 79 | 80 | // Act 81 | repository.getConcreteNumberTrivia(testNumber); 82 | 83 | // Assert 84 | verify(() => mockNetworkInfo.isConnected); 85 | }); 86 | 87 | runTestsOnline(() { 88 | setUp(() { 89 | when(() => mockLocalDataSource.cacheNumberTrivia(testNumberTriviaModel)) 90 | .thenAnswer((_) => Future(() {})); 91 | }); 92 | 93 | test( 94 | 'should return remote data when the call to remote data source is successful', 95 | () async { 96 | // Arrange 97 | when(() => mockRemoteDataSource.getConcreteNumberTrivia(any())) 98 | .thenAnswer((_) async => testNumberTriviaModel); 99 | 100 | // Act 101 | final result = await repository.getConcreteNumberTrivia(testNumber); 102 | 103 | // Assert 104 | verify( 105 | () => mockRemoteDataSource.getConcreteNumberTrivia(testNumber), 106 | ); 107 | 108 | expect(result, equals(const Right(testNumberTrivia))); 109 | }, 110 | ); 111 | 112 | test( 113 | 'should cache the data locally when the call to remote data source is successful', 114 | () async { 115 | // Arrange 116 | when(() => mockRemoteDataSource.getConcreteNumberTrivia(any())) 117 | .thenAnswer((_) async => testNumberTriviaModel); 118 | 119 | // Act 120 | await repository.getConcreteNumberTrivia(testNumber); 121 | 122 | // Assert 123 | verify( 124 | () => mockRemoteDataSource.getConcreteNumberTrivia(testNumber), 125 | ); 126 | 127 | verify( 128 | () => mockLocalDataSource.cacheNumberTrivia(testNumberTriviaModel), 129 | ); 130 | }, 131 | ); 132 | 133 | test( 134 | 'should return server failure when the call to remote data source is unsuccessful', 135 | () async { 136 | // Arrange 137 | when(() => mockRemoteDataSource.getConcreteNumberTrivia(any())) 138 | .thenThrow(ServerException()); 139 | 140 | // Act 141 | final result = await repository.getConcreteNumberTrivia(testNumber); 142 | 143 | // Assert 144 | verify( 145 | () => mockRemoteDataSource.getConcreteNumberTrivia(testNumber), 146 | ); 147 | 148 | verifyZeroInteractions(mockLocalDataSource); 149 | expect(result, equals(Left(ServerFailure()))); 150 | }, 151 | ); 152 | }); 153 | 154 | runTestsOffline(() { 155 | setUp(() { 156 | when(() => mockNetworkInfo.isConnected).thenAnswer((_) async => false); 157 | }); 158 | 159 | test( 160 | 'should return last locally cached data when the cached data is present', 161 | () async { 162 | // Arrange 163 | when(() => mockLocalDataSource.getLastNumberTrivia()) 164 | .thenAnswer((_) async => testNumberTriviaModel); 165 | 166 | // Act 167 | final result = await repository.getConcreteNumberTrivia(testNumber); 168 | 169 | // Assert 170 | verifyZeroInteractions(mockRemoteDataSource); 171 | verify(() => mockLocalDataSource.getLastNumberTrivia()); 172 | expect(result, const Right(testNumberTrivia)); 173 | }, 174 | ); 175 | 176 | test( 177 | 'should return cache failure when there is no cached data', 178 | () async { 179 | // Arrange 180 | when(() => mockLocalDataSource.getLastNumberTrivia()) 181 | .thenThrow(CacheException()); 182 | 183 | // Act 184 | final result = await repository.getConcreteNumberTrivia(testNumber); 185 | 186 | // Assert 187 | verifyZeroInteractions(mockRemoteDataSource); 188 | verify(() => mockLocalDataSource.getLastNumberTrivia()); 189 | expect(result, Left(CacheFailure())); 190 | }, 191 | ); 192 | }); 193 | }); 194 | 195 | group('getRandomNumberTrivia', () { 196 | const testNumberTriviaModel = NumberTriviaModel( 197 | number: 123, 198 | text: 'test trivia', 199 | ); 200 | 201 | const NumberTrivia testNumberTrivia = testNumberTriviaModel; 202 | 203 | test('should check if the device is online', () { 204 | // Arrange 205 | when(() => mockNetworkInfo.isConnected).thenAnswer((_) async => true); 206 | 207 | when(() => mockRemoteDataSource.getRandomNumberTrivia()) 208 | .thenAnswer((_) async => testNumberTriviaModel); 209 | 210 | when(() => mockLocalDataSource.cacheNumberTrivia(testNumberTriviaModel)) 211 | .thenAnswer((_) => Future(() {})); 212 | 213 | // Act 214 | repository.getRandomNumberTrivia(); 215 | 216 | // Assert 217 | verify(() => mockNetworkInfo.isConnected); 218 | }); 219 | 220 | runTestsOnline(() { 221 | setUp(() { 222 | when(() => mockLocalDataSource.cacheNumberTrivia(testNumberTriviaModel)) 223 | .thenAnswer((_) => Future(() {})); 224 | }); 225 | 226 | test( 227 | 'should return remote data when the call to remote data source is successful', 228 | () async { 229 | // Arrange 230 | when(() => mockRemoteDataSource.getRandomNumberTrivia()) 231 | .thenAnswer((_) async => testNumberTriviaModel); 232 | 233 | // Act 234 | final result = await repository.getRandomNumberTrivia(); 235 | 236 | // Assert 237 | verify( 238 | () => mockRemoteDataSource.getRandomNumberTrivia(), 239 | ); 240 | 241 | expect(result, equals(const Right(testNumberTrivia))); 242 | }, 243 | ); 244 | 245 | test( 246 | 'should cache the data locally when the call to remote data source is successful', 247 | () async { 248 | // Arrange 249 | when(() => mockRemoteDataSource.getRandomNumberTrivia()) 250 | .thenAnswer((_) async => testNumberTriviaModel); 251 | 252 | // Act 253 | await repository.getRandomNumberTrivia(); 254 | 255 | // Assert 256 | verify( 257 | () => mockRemoteDataSource.getRandomNumberTrivia(), 258 | ); 259 | 260 | verify( 261 | () => mockLocalDataSource.cacheNumberTrivia(testNumberTriviaModel), 262 | ); 263 | }, 264 | ); 265 | 266 | test( 267 | 'should return server failure when the call to remote data source is unsuccessful', 268 | () async { 269 | // Arrange 270 | when(() => mockRemoteDataSource.getRandomNumberTrivia()) 271 | .thenThrow(ServerException()); 272 | 273 | // Act 274 | final result = await repository.getRandomNumberTrivia(); 275 | 276 | // Assert 277 | verify( 278 | () => mockRemoteDataSource.getRandomNumberTrivia(), 279 | ); 280 | 281 | verifyZeroInteractions(mockLocalDataSource); 282 | expect(result, equals(Left(ServerFailure()))); 283 | }, 284 | ); 285 | }); 286 | 287 | runTestsOffline(() { 288 | setUp(() { 289 | when(() => mockNetworkInfo.isConnected).thenAnswer((_) async => false); 290 | }); 291 | 292 | test( 293 | 'should return last locally cached data when the cached data is present', 294 | () async { 295 | // Arrange 296 | when(() => mockLocalDataSource.getLastNumberTrivia()) 297 | .thenAnswer((_) async => testNumberTriviaModel); 298 | 299 | // Act 300 | final result = await repository.getRandomNumberTrivia(); 301 | 302 | // Assert 303 | verifyZeroInteractions(mockRemoteDataSource); 304 | verify(() => mockLocalDataSource.getLastNumberTrivia()); 305 | expect(result, const Right(testNumberTrivia)); 306 | }, 307 | ); 308 | 309 | test( 310 | 'should return cache failure when there is no cached data', 311 | () async { 312 | // Arrange 313 | when(() => mockLocalDataSource.getLastNumberTrivia()) 314 | .thenThrow(CacheException()); 315 | 316 | // Act 317 | final result = await repository.getRandomNumberTrivia(); 318 | 319 | // Assert 320 | verifyZeroInteractions(mockRemoteDataSource); 321 | verify(() => mockLocalDataSource.getLastNumberTrivia()); 322 | expect(result, Left(CacheFailure())); 323 | }, 324 | ); 325 | }); 326 | }); 327 | } 328 | -------------------------------------------------------------------------------- /test/features/number_trivia/domain/use_cases/get_concrete_number_trivia_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:clean_architecture/features/number_trivia/domain/entities/number_trivia.dart'; 2 | import 'package:clean_architecture/features/number_trivia/domain/repositories/number_trivia_repository.dart'; 3 | import 'package:clean_architecture/features/number_trivia/domain/use_cases/get_concrete_number_trivia.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | import 'package:flutter_test/flutter_test.dart'; 6 | import 'package:mocktail/mocktail.dart'; 7 | 8 | class MockNumberTriviaRepository extends Mock 9 | implements NumberTriviaRepository {} 10 | 11 | void main() { 12 | const testNumber = 1; 13 | const testNumberTrivia = NumberTrivia(number: 1, text: 'test'); 14 | GetConcreteNumberTrivia? useCase; 15 | MockNumberTriviaRepository? mockNumberTriviaRepository; 16 | 17 | setUp(() { 18 | mockNumberTriviaRepository = MockNumberTriviaRepository(); 19 | useCase = GetConcreteNumberTrivia(mockNumberTriviaRepository!); 20 | }); 21 | 22 | test('should get trivia for the number from the repository', () async { 23 | // Arrange 24 | when(() => mockNumberTriviaRepository!.getConcreteNumberTrivia(any())) 25 | .thenAnswer((_) async => const Right(testNumberTrivia)); 26 | 27 | // Act 28 | final result = await useCase!(const Params(number: testNumber)); 29 | 30 | // Assert 31 | expect(result, equals(const Right(testNumberTrivia))); 32 | verify( 33 | () => mockNumberTriviaRepository!.getConcreteNumberTrivia(testNumber)); 34 | 35 | verifyNoMoreInteractions( 36 | mockNumberTriviaRepository, 37 | ); 38 | }); 39 | } 40 | -------------------------------------------------------------------------------- /test/features/number_trivia/domain/use_cases/get_random_number_trivia_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:clean_architecture/core/use_cases/use_case.dart'; 2 | import 'package:clean_architecture/features/number_trivia/domain/entities/number_trivia.dart'; 3 | import 'package:clean_architecture/features/number_trivia/domain/repositories/number_trivia_repository.dart'; 4 | import 'package:clean_architecture/features/number_trivia/domain/use_cases/get_random_number_trivia.dart'; 5 | import 'package:dartz/dartz.dart'; 6 | import 'package:flutter_test/flutter_test.dart'; 7 | import 'package:mocktail/mocktail.dart'; 8 | 9 | class MockNumberTriviaRepository extends Mock 10 | implements NumberTriviaRepository {} 11 | 12 | void main() { 13 | const testNumberTrivia = NumberTrivia(number: 1, text: 'test'); 14 | GetRandomNumberTrivia? useCase; 15 | MockNumberTriviaRepository? mockNumberTriviaRepository; 16 | 17 | setUp(() { 18 | mockNumberTriviaRepository = MockNumberTriviaRepository(); 19 | useCase = GetRandomNumberTrivia(mockNumberTriviaRepository!); 20 | }); 21 | 22 | test('should get trivia from the repository', () async { 23 | // Arrange 24 | when(() => mockNumberTriviaRepository!.getRandomNumberTrivia()) 25 | .thenAnswer((_) async => const Right(testNumberTrivia)); 26 | 27 | // Act 28 | final result = await useCase!(NoParams()); 29 | 30 | // Assert 31 | expect(result, equals(const Right(testNumberTrivia))); 32 | verify(() => mockNumberTriviaRepository!.getRandomNumberTrivia()); 33 | 34 | verifyNoMoreInteractions( 35 | mockNumberTriviaRepository, 36 | ); 37 | }); 38 | } 39 | -------------------------------------------------------------------------------- /test/features/number_trivia/presentation/bloc/number_trivia_bloc_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:clean_architecture/core/error/failures/cache_failure.dart'; 2 | import 'package:clean_architecture/core/error/failures/invalid_input_failure.dart'; 3 | import 'package:clean_architecture/core/error/failures/server_failure.dart'; 4 | import 'package:clean_architecture/core/use_cases/use_case.dart'; 5 | import 'package:clean_architecture/core/utilities/input_converter.dart'; 6 | import 'package:clean_architecture/features/number_trivia/domain/entities/number_trivia.dart'; 7 | import 'package:clean_architecture/features/number_trivia/domain/use_cases/get_concrete_number_trivia.dart'; 8 | import 'package:clean_architecture/features/number_trivia/domain/use_cases/get_random_number_trivia.dart'; 9 | import 'package:clean_architecture/features/number_trivia/presentation/bloc/events/get_trivia_for_concrete_number.dart'; 10 | import 'package:clean_architecture/features/number_trivia/presentation/bloc/events/get_trivia_for_random_number.dart'; 11 | import 'package:clean_architecture/features/number_trivia/presentation/bloc/number_trivia_bloc.dart'; 12 | import 'package:clean_architecture/features/number_trivia/presentation/bloc/state/initial_number_trivia_state.dart'; 13 | import 'package:clean_architecture/features/number_trivia/presentation/bloc/state/loaded_number_trivia_state.dart'; 14 | import 'package:clean_architecture/features/number_trivia/presentation/bloc/state/loading_number_trivia_state.dart'; 15 | import 'package:clean_architecture/features/number_trivia/presentation/bloc/state/number_trivia_retrieval_error_state.dart'; 16 | import 'package:dartz/dartz.dart'; 17 | import 'package:flutter_test/flutter_test.dart'; 18 | import 'package:mocktail/mocktail.dart'; 19 | 20 | class MockGetConcreteNumberTrivia extends Mock 21 | implements GetConcreteNumberTrivia {} 22 | 23 | class MockGetRandomNumberTrivia extends Mock implements GetRandomNumberTrivia {} 24 | 25 | class MockInputConverter extends Mock implements InputConverter {} 26 | 27 | void main() { 28 | const testNumberString = '1'; 29 | const testParsedNumber = 1; 30 | const testNumberTrivia = NumberTrivia(number: 1, text: 'test trivia'); 31 | NumberTriviaBloc? bloc; 32 | MockGetConcreteNumberTrivia? mockGetConcreteNumberTrivia; 33 | MockGetRandomNumberTrivia? mockGetRandomNumberTrivia; 34 | MockInputConverter? mockInputConverter; 35 | 36 | setUpAll(() { 37 | registerFallbackValue(const Params(number: testParsedNumber)); 38 | registerFallbackValue(NoParams()); 39 | }); 40 | 41 | setUp(() { 42 | mockGetConcreteNumberTrivia = MockGetConcreteNumberTrivia(); 43 | mockGetRandomNumberTrivia = MockGetRandomNumberTrivia(); 44 | mockInputConverter = MockInputConverter(); 45 | 46 | bloc = NumberTriviaBloc( 47 | getConcreteNumberTrivia: mockGetConcreteNumberTrivia!, 48 | getRandomNumberTrivia: mockGetRandomNumberTrivia!, 49 | inputConverter: mockInputConverter!, 50 | ); 51 | }); 52 | 53 | void setUpMockInputConverterSuccess() { 54 | when(() => mockInputConverter!.stringToUnsignedInteger(any())) 55 | .thenReturn(const Right(testParsedNumber)); 56 | } 57 | 58 | void setUpMockGetConcreteNumberTriviaSuccess() { 59 | when(() => mockGetConcreteNumberTrivia!(any())) 60 | .thenAnswer((_) async => const Right(testNumberTrivia)); 61 | } 62 | 63 | void setUpMockGetRandomNumberTriviaSuccess() { 64 | when(() => mockGetRandomNumberTrivia!(any())) 65 | .thenAnswer((_) async => const Right(testNumberTrivia)); 66 | } 67 | 68 | test('bloc initial state should be InitialNumberTriviaState', () { 69 | // Assert 70 | expect(bloc!.state, equals(InitialNumberTriviaState())); 71 | }); 72 | 73 | group('GetTriviaForConcreteNumber', () { 74 | test( 75 | 'should call the InputConverter to validate and convert the number to an unsigned integer', 76 | () async { 77 | // Arrange 78 | setUpMockInputConverterSuccess(); 79 | setUpMockGetConcreteNumberTriviaSuccess(); 80 | 81 | // Act 82 | bloc!.add(const GetTriviaForConcreteNumber(testNumberString)); 83 | 84 | await untilCalled( 85 | () => mockInputConverter!.stringToUnsignedInteger(any())); 86 | 87 | // Assert 88 | verify(() => 89 | mockInputConverter!.stringToUnsignedInteger(testNumberString)); 90 | }, 91 | ); 92 | 93 | test( 94 | 'should emit [NumberTriviaRetrievalErrorState] when the input is invalid', 95 | () { 96 | // Arrange 97 | when(() => mockInputConverter!.stringToUnsignedInteger(any())) 98 | .thenReturn(Left(InvalidInputFailure())); 99 | 100 | // Assert 101 | expectLater( 102 | bloc!.stream, 103 | emitsInOrder([ 104 | const NumberTriviaRetrievalErrorState( 105 | message: invalidInputFailureMessage) 106 | ])); 107 | 108 | // Act 109 | bloc!.add(const GetTriviaForConcreteNumber(testNumberString)); 110 | }, 111 | ); 112 | 113 | test('should get data from the concrete use case', () async { 114 | // arrange 115 | setUpMockInputConverterSuccess(); 116 | setUpMockGetConcreteNumberTriviaSuccess(); 117 | 118 | // act 119 | bloc!.add(const GetTriviaForConcreteNumber(testNumberString)); 120 | await untilCalled(() => mockGetConcreteNumberTrivia!(any())); 121 | 122 | // // assert 123 | verify( 124 | () => mockGetConcreteNumberTrivia!( 125 | const Params(number: testParsedNumber)), 126 | ); 127 | }); 128 | 129 | test( 130 | 'should emit [LoadingNumberTriviaState, LoadedNumberTriviaState] states when data is gotten successfully', 131 | () { 132 | // arrange 133 | setUpMockInputConverterSuccess(); 134 | setUpMockGetConcreteNumberTriviaSuccess(); 135 | 136 | // assert later 137 | final expected = [ 138 | LoadingNumberTriviaState(), 139 | const LoadedNumberTriviaState(trivia: testNumberTrivia), 140 | ]; 141 | 142 | expectLater(bloc!.stream, emitsInOrder(expected)); 143 | 144 | // act 145 | bloc!.add(const GetTriviaForConcreteNumber(testNumberString)); 146 | }, 147 | ); 148 | 149 | test( 150 | 'should emit [LoadingNumberTriviaState, NumberTriviaRetrievalErrorState] states when data is gotten successfully', 151 | () { 152 | // arrange 153 | setUpMockInputConverterSuccess(); 154 | 155 | when(() => mockGetConcreteNumberTrivia!(any())) 156 | .thenAnswer((_) async => Left(ServerFailure())); 157 | 158 | // assert later 159 | final expected = [ 160 | LoadingNumberTriviaState(), 161 | const NumberTriviaRetrievalErrorState(message: serverFailureMessage), 162 | ]; 163 | 164 | expectLater(bloc!.stream, emitsInOrder(expected)); 165 | 166 | // act 167 | bloc!.add(const GetTriviaForConcreteNumber(testNumberString)); 168 | }, 169 | ); 170 | test( 171 | 'should emit [LoadingNumberTriviaState, NumberTriviaRetrievalErrorState] with a propper message for the error when getting data fails', 172 | () { 173 | // arrange 174 | setUpMockInputConverterSuccess(); 175 | 176 | when(() => mockGetConcreteNumberTrivia!(any())) 177 | .thenAnswer((_) async => Left(CacheFailure())); 178 | 179 | // assert later 180 | final expected = [ 181 | LoadingNumberTriviaState(), 182 | const NumberTriviaRetrievalErrorState(message: cacheFailureMessage), 183 | ]; 184 | 185 | expectLater(bloc!.stream, emitsInOrder(expected)); 186 | 187 | // act 188 | bloc!.add(const GetTriviaForConcreteNumber(testNumberString)); 189 | }, 190 | ); 191 | }); 192 | 193 | group('GetTriviaForRandomNumber', () { 194 | test('should get data from the random use case', () async { 195 | // arrange 196 | setUpMockInputConverterSuccess(); 197 | setUpMockGetRandomNumberTriviaSuccess(); 198 | 199 | // act 200 | bloc!.add(GetTriviaForRandomNumber()); 201 | await untilCalled(() => mockGetRandomNumberTrivia!(NoParams())); 202 | 203 | // // assert 204 | verify( 205 | () => mockGetRandomNumberTrivia!(NoParams()), 206 | ); 207 | }); 208 | 209 | test( 210 | 'should emit [LoadingNumberTriviaState, LoadedNumberTriviaState] states when data is gotten successfully', 211 | () { 212 | // arrange 213 | setUpMockInputConverterSuccess(); 214 | setUpMockGetRandomNumberTriviaSuccess(); 215 | 216 | // assert later 217 | final expected = [ 218 | LoadingNumberTriviaState(), 219 | const LoadedNumberTriviaState(trivia: testNumberTrivia), 220 | ]; 221 | 222 | expectLater(bloc!.stream, emitsInOrder(expected)); 223 | 224 | // act 225 | bloc!.add(GetTriviaForRandomNumber()); 226 | }, 227 | ); 228 | 229 | test( 230 | 'should emit [LoadingNumberTriviaState, NumberTriviaRetrievalErrorState] states when data is gotten successfully', 231 | () { 232 | // arrange 233 | setUpMockInputConverterSuccess(); 234 | 235 | when(() => mockGetRandomNumberTrivia!(NoParams())) 236 | .thenAnswer((_) async => Left(ServerFailure())); 237 | 238 | // assert later 239 | final expected = [ 240 | LoadingNumberTriviaState(), 241 | const NumberTriviaRetrievalErrorState(message: serverFailureMessage), 242 | ]; 243 | 244 | expectLater(bloc!.stream, emitsInOrder(expected)); 245 | 246 | // act 247 | bloc!.add(GetTriviaForRandomNumber()); 248 | }, 249 | ); 250 | test( 251 | 'should emit [LoadingNumberTriviaState, NumberTriviaRetrievalErrorState] with a propper message for the error when getting data fails', 252 | () { 253 | // arrange 254 | setUpMockInputConverterSuccess(); 255 | 256 | when(() => mockGetRandomNumberTrivia!(NoParams())) 257 | .thenAnswer((_) async => Left(CacheFailure())); 258 | 259 | // assert later 260 | final expected = [ 261 | LoadingNumberTriviaState(), 262 | const NumberTriviaRetrievalErrorState(message: cacheFailureMessage), 263 | ]; 264 | 265 | expectLater(bloc!.stream, emitsInOrder(expected)); 266 | 267 | // act 268 | bloc!.add(GetTriviaForRandomNumber()); 269 | }, 270 | ); 271 | }); 272 | } 273 | -------------------------------------------------------------------------------- /test/fixtures/fixture_reader.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | String fixture(String name) => File('test/fixtures/$name').readAsStringSync(); 4 | -------------------------------------------------------------------------------- /test/fixtures/trivia.json: -------------------------------------------------------------------------------- 1 | { 2 | "text": "Test Text", 3 | "number": 1, 4 | "found": true, 5 | "type": "trivia" 6 | } -------------------------------------------------------------------------------- /test/fixtures/trivia_cached.json: -------------------------------------------------------------------------------- 1 | { 2 | "text": "Test Text", 3 | "number": 1 4 | } -------------------------------------------------------------------------------- /test/fixtures/trivia_double.json: -------------------------------------------------------------------------------- 1 | { 2 | "text": "Test Text", 3 | "number": 1.0, 4 | "found": true, 5 | "type": "trivia" 6 | } -------------------------------------------------------------------------------- /web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/web/favicon.png -------------------------------------------------------------------------------- /web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/web/icons/Icon-192.png -------------------------------------------------------------------------------- /web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/web/icons/Icon-512.png -------------------------------------------------------------------------------- /web/icons/Icon-maskable-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/web/icons/Icon-maskable-192.png -------------------------------------------------------------------------------- /web/icons/Icon-maskable-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/web/icons/Icon-maskable-512.png -------------------------------------------------------------------------------- /web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | flutter_clean_architecture 33 | 34 | 35 | 36 | 39 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "flutter_clean_architecture", 3 | "short_name": "flutter_clean_architecture", 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 | cmake_minimum_required(VERSION 3.14) 2 | project(flutter_clean_architecture LANGUAGES CXX) 3 | 4 | set(BINARY_NAME "flutter_clean_architecture") 5 | 6 | cmake_policy(SET CMP0063 NEW) 7 | 8 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") 9 | 10 | # Configure build options. 11 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 12 | if(IS_MULTICONFIG) 13 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" 14 | CACHE STRING "" FORCE) 15 | else() 16 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 17 | set(CMAKE_BUILD_TYPE "Debug" CACHE 18 | STRING "Flutter build mode" FORCE) 19 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 20 | "Debug" "Profile" "Release") 21 | endif() 22 | endif() 23 | 24 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") 25 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") 26 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") 27 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") 28 | 29 | # Use Unicode for all projects. 30 | add_definitions(-DUNICODE -D_UNICODE) 31 | 32 | # Compilation settings that should be applied to most targets. 33 | function(APPLY_STANDARD_SETTINGS TARGET) 34 | target_compile_features(${TARGET} PUBLIC cxx_std_17) 35 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") 36 | target_compile_options(${TARGET} PRIVATE /EHsc) 37 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") 38 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") 39 | endfunction() 40 | 41 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 42 | 43 | # Flutter library and tool build rules. 44 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 45 | 46 | # Application build 47 | add_subdirectory("runner") 48 | 49 | # Generated plugin build rules, which manage building the plugins and adding 50 | # them to the application. 51 | include(flutter/generated_plugins.cmake) 52 | 53 | 54 | # === Installation === 55 | # Support files are copied into place next to the executable, so that it can 56 | # run in place. This is done instead of making a separate bundle (as on Linux) 57 | # so that building and running from within Visual Studio will work. 58 | set(BUILD_BUNDLE_DIR "$") 59 | # Make the "install" step default, as it's required to run. 60 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) 61 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 62 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 63 | endif() 64 | 65 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 66 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") 67 | 68 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 69 | COMPONENT Runtime) 70 | 71 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 72 | COMPONENT Runtime) 73 | 74 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 75 | COMPONENT Runtime) 76 | 77 | if(PLUGIN_BUNDLED_LIBRARIES) 78 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" 79 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 80 | COMPONENT Runtime) 81 | endif() 82 | 83 | # Fully re-copy the assets directory on each build to avoid having stale files 84 | # from a previous install. 85 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 86 | install(CODE " 87 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 88 | " COMPONENT Runtime) 89 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 90 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 91 | 92 | # Install the AOT library on non-Debug builds only. 93 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 94 | CONFIGURATIONS Profile;Release 95 | COMPONENT Runtime) 96 | -------------------------------------------------------------------------------- /windows/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 4 | 5 | # Configuration provided via flutter tool. 6 | include(${EPHEMERAL_DIR}/generated_config.cmake) 7 | 8 | # TODO: Move the rest of this into files in ephemeral. See 9 | # https://github.com/flutter/flutter/issues/57146. 10 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") 11 | 12 | # === Flutter Library === 13 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") 14 | 15 | # Published to parent scope for install step. 16 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 17 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 18 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 19 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) 20 | 21 | list(APPEND FLUTTER_LIBRARY_HEADERS 22 | "flutter_export.h" 23 | "flutter_windows.h" 24 | "flutter_messenger.h" 25 | "flutter_plugin_registrar.h" 26 | "flutter_texture_registrar.h" 27 | ) 28 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") 29 | add_library(flutter INTERFACE) 30 | target_include_directories(flutter INTERFACE 31 | "${EPHEMERAL_DIR}" 32 | ) 33 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") 34 | add_dependencies(flutter flutter_assemble) 35 | 36 | # === Wrapper === 37 | list(APPEND CPP_WRAPPER_SOURCES_CORE 38 | "core_implementations.cc" 39 | "standard_codec.cc" 40 | ) 41 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") 42 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN 43 | "plugin_registrar.cc" 44 | ) 45 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") 46 | list(APPEND CPP_WRAPPER_SOURCES_APP 47 | "flutter_engine.cc" 48 | "flutter_view_controller.cc" 49 | ) 50 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") 51 | 52 | # Wrapper sources needed for a plugin. 53 | add_library(flutter_wrapper_plugin STATIC 54 | ${CPP_WRAPPER_SOURCES_CORE} 55 | ${CPP_WRAPPER_SOURCES_PLUGIN} 56 | ) 57 | apply_standard_settings(flutter_wrapper_plugin) 58 | set_target_properties(flutter_wrapper_plugin PROPERTIES 59 | POSITION_INDEPENDENT_CODE ON) 60 | set_target_properties(flutter_wrapper_plugin PROPERTIES 61 | CXX_VISIBILITY_PRESET hidden) 62 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) 63 | target_include_directories(flutter_wrapper_plugin PUBLIC 64 | "${WRAPPER_ROOT}/include" 65 | ) 66 | add_dependencies(flutter_wrapper_plugin flutter_assemble) 67 | 68 | # Wrapper sources needed for the runner. 69 | add_library(flutter_wrapper_app STATIC 70 | ${CPP_WRAPPER_SOURCES_CORE} 71 | ${CPP_WRAPPER_SOURCES_APP} 72 | ) 73 | apply_standard_settings(flutter_wrapper_app) 74 | target_link_libraries(flutter_wrapper_app PUBLIC flutter) 75 | target_include_directories(flutter_wrapper_app PUBLIC 76 | "${WRAPPER_ROOT}/include" 77 | ) 78 | add_dependencies(flutter_wrapper_app flutter_assemble) 79 | 80 | # === Flutter tool backend === 81 | # _phony_ is a non-existent file to force this command to run every time, 82 | # since currently there's no way to get a full input/output list from the 83 | # flutter tool. 84 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") 85 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) 86 | add_custom_command( 87 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 88 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} 89 | ${CPP_WRAPPER_SOURCES_APP} 90 | ${PHONY_OUTPUT} 91 | COMMAND ${CMAKE_COMMAND} -E env 92 | ${FLUTTER_TOOL_ENVIRONMENT} 93 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" 94 | windows-x64 $ 95 | VERBATIM 96 | ) 97 | add_custom_target(flutter_assemble DEPENDS 98 | "${FLUTTER_LIBRARY}" 99 | ${FLUTTER_LIBRARY_HEADERS} 100 | ${CPP_WRAPPER_SOURCES_CORE} 101 | ${CPP_WRAPPER_SOURCES_PLUGIN} 102 | ${CPP_WRAPPER_SOURCES_APP} 103 | ) 104 | -------------------------------------------------------------------------------- /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 | set(PLUGIN_BUNDLED_LIBRARIES) 9 | 10 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 11 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 12 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 13 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 14 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 15 | endforeach(plugin) 16 | -------------------------------------------------------------------------------- /windows/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | project(runner LANGUAGES CXX) 3 | 4 | add_executable(${BINARY_NAME} WIN32 5 | "flutter_window.cpp" 6 | "main.cpp" 7 | "utils.cpp" 8 | "win32_window.cpp" 9 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 10 | "Runner.rc" 11 | "runner.exe.manifest" 12 | ) 13 | apply_standard_settings(${BINARY_NAME}) 14 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 15 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 16 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 17 | add_dependencies(${BINARY_NAME} flutter_assemble) 18 | -------------------------------------------------------------------------------- /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 | #ifdef FLUTTER_BUILD_NUMBER 64 | #define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER 65 | #else 66 | #define VERSION_AS_NUMBER 1,0,0 67 | #endif 68 | 69 | #ifdef FLUTTER_BUILD_NAME 70 | #define VERSION_AS_STRING #FLUTTER_BUILD_NAME 71 | #else 72 | #define VERSION_AS_STRING "1.0.0" 73 | #endif 74 | 75 | VS_VERSION_INFO VERSIONINFO 76 | FILEVERSION VERSION_AS_NUMBER 77 | PRODUCTVERSION VERSION_AS_NUMBER 78 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 79 | #ifdef _DEBUG 80 | FILEFLAGS VS_FF_DEBUG 81 | #else 82 | FILEFLAGS 0x0L 83 | #endif 84 | FILEOS VOS__WINDOWS32 85 | FILETYPE VFT_APP 86 | FILESUBTYPE 0x0L 87 | BEGIN 88 | BLOCK "StringFileInfo" 89 | BEGIN 90 | BLOCK "040904e4" 91 | BEGIN 92 | VALUE "CompanyName", "com.example" "\0" 93 | VALUE "FileDescription", "flutter_clean_architecture" "\0" 94 | VALUE "FileVersion", VERSION_AS_STRING "\0" 95 | VALUE "InternalName", "flutter_clean_architecture" "\0" 96 | VALUE "LegalCopyright", "Copyright (C) 2022 com.example. All rights reserved." "\0" 97 | VALUE "OriginalFilename", "flutter_clean_architecture.exe" "\0" 98 | VALUE "ProductName", "flutter_clean_architecture" "\0" 99 | VALUE "ProductVersion", VERSION_AS_STRING "\0" 100 | END 101 | END 102 | BLOCK "VarFileInfo" 103 | BEGIN 104 | VALUE "Translation", 0x409, 1252 105 | END 106 | END 107 | 108 | #endif // English (United States) resources 109 | ///////////////////////////////////////////////////////////////////////////// 110 | 111 | 112 | 113 | #ifndef APSTUDIO_INVOKED 114 | ///////////////////////////////////////////////////////////////////////////// 115 | // 116 | // Generated from the TEXTINCLUDE 3 resource. 117 | // 118 | 119 | 120 | ///////////////////////////////////////////////////////////////////////////// 121 | #endif // not APSTUDIO_INVOKED 122 | -------------------------------------------------------------------------------- /windows/runner/flutter_window.cpp: -------------------------------------------------------------------------------- 1 | #include "flutter_window.h" 2 | 3 | #include 4 | 5 | #include "flutter/generated_plugin_registrant.h" 6 | 7 | FlutterWindow::FlutterWindow(const flutter::DartProject& project) 8 | : project_(project) {} 9 | 10 | FlutterWindow::~FlutterWindow() {} 11 | 12 | bool FlutterWindow::OnCreate() { 13 | if (!Win32Window::OnCreate()) { 14 | return false; 15 | } 16 | 17 | RECT frame = GetClientArea(); 18 | 19 | // The size here must match the window dimensions to avoid unnecessary surface 20 | // creation / destruction in the startup path. 21 | flutter_controller_ = std::make_unique( 22 | frame.right - frame.left, frame.bottom - frame.top, project_); 23 | // Ensure that basic setup of the controller was successful. 24 | if (!flutter_controller_->engine() || !flutter_controller_->view()) { 25 | return false; 26 | } 27 | RegisterPlugins(flutter_controller_->engine()); 28 | SetChildContent(flutter_controller_->view()->GetNativeWindow()); 29 | return true; 30 | } 31 | 32 | void FlutterWindow::OnDestroy() { 33 | if (flutter_controller_) { 34 | flutter_controller_ = nullptr; 35 | } 36 | 37 | Win32Window::OnDestroy(); 38 | } 39 | 40 | LRESULT 41 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message, 42 | WPARAM const wparam, 43 | LPARAM const lparam) noexcept { 44 | // Give Flutter, including plugins, an opportunity to handle window messages. 45 | if (flutter_controller_) { 46 | std::optional result = 47 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, 48 | lparam); 49 | if (result) { 50 | return *result; 51 | } 52 | } 53 | 54 | switch (message) { 55 | case WM_FONTCHANGE: 56 | flutter_controller_->engine()->ReloadSystemFonts(); 57 | break; 58 | } 59 | 60 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam); 61 | } 62 | -------------------------------------------------------------------------------- /windows/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_FLUTTER_WINDOW_H_ 2 | #define RUNNER_FLUTTER_WINDOW_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "win32_window.h" 10 | 11 | // A window that does nothing but host a Flutter view. 12 | class FlutterWindow : public Win32Window { 13 | public: 14 | // Creates a new FlutterWindow hosting a Flutter view running |project|. 15 | explicit FlutterWindow(const flutter::DartProject& project); 16 | virtual ~FlutterWindow(); 17 | 18 | protected: 19 | // Win32Window: 20 | bool OnCreate() override; 21 | void OnDestroy() override; 22 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, 23 | LPARAM const lparam) noexcept override; 24 | 25 | private: 26 | // The project to run. 27 | flutter::DartProject project_; 28 | 29 | // The Flutter instance hosted by this window. 30 | std::unique_ptr flutter_controller_; 31 | }; 32 | 33 | #endif // RUNNER_FLUTTER_WINDOW_H_ 34 | -------------------------------------------------------------------------------- /windows/runner/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "flutter_window.h" 6 | #include "utils.h" 7 | 8 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, 9 | _In_ wchar_t *command_line, _In_ int show_command) { 10 | // Attach to console when present (e.g., 'flutter run') or create a 11 | // new console when running with a debugger. 12 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { 13 | CreateAndAttachConsole(); 14 | } 15 | 16 | // Initialize COM, so that it is available for use in the library and/or 17 | // plugins. 18 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); 19 | 20 | flutter::DartProject project(L"data"); 21 | 22 | std::vector command_line_arguments = 23 | GetCommandLineArguments(); 24 | 25 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 26 | 27 | FlutterWindow window(project); 28 | Win32Window::Point origin(10, 10); 29 | Win32Window::Size size(1280, 720); 30 | if (!window.CreateAndShow(L"flutter_clean_architecture", 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/Abdullah104/flutter-clean-architecture/c8dd31f67c1256c30e48dd6e55329aff2bdbd171/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 | if (target_length == 0) { 52 | return std::string(); 53 | } 54 | std::string utf8_string; 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.cpp: -------------------------------------------------------------------------------- 1 | #include "win32_window.h" 2 | 3 | #include 4 | 5 | #include "resource.h" 6 | 7 | namespace { 8 | 9 | constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW"; 10 | 11 | // The number of Win32Window objects that currently exist. 12 | static int g_active_window_count = 0; 13 | 14 | using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd); 15 | 16 | // Scale helper to convert logical scaler values to physical using passed in 17 | // scale factor 18 | int Scale(int source, double scale_factor) { 19 | return static_cast(source * scale_factor); 20 | } 21 | 22 | // Dynamically loads the |EnableNonClientDpiScaling| from the User32 module. 23 | // This API is only needed for PerMonitor V1 awareness mode. 24 | void EnableFullDpiSupportIfAvailable(HWND hwnd) { 25 | HMODULE user32_module = LoadLibraryA("User32.dll"); 26 | if (!user32_module) { 27 | return; 28 | } 29 | auto enable_non_client_dpi_scaling = 30 | reinterpret_cast( 31 | GetProcAddress(user32_module, "EnableNonClientDpiScaling")); 32 | if (enable_non_client_dpi_scaling != nullptr) { 33 | enable_non_client_dpi_scaling(hwnd); 34 | FreeLibrary(user32_module); 35 | } 36 | } 37 | 38 | } // namespace 39 | 40 | // Manages the Win32Window's window class registration. 41 | class WindowClassRegistrar { 42 | public: 43 | ~WindowClassRegistrar() = default; 44 | 45 | // Returns the singleton registar instance. 46 | static WindowClassRegistrar* GetInstance() { 47 | if (!instance_) { 48 | instance_ = new WindowClassRegistrar(); 49 | } 50 | return instance_; 51 | } 52 | 53 | // Returns the name of the window class, registering the class if it hasn't 54 | // previously been registered. 55 | const wchar_t* GetWindowClass(); 56 | 57 | // Unregisters the window class. Should only be called if there are no 58 | // instances of the window. 59 | void UnregisterWindowClass(); 60 | 61 | private: 62 | WindowClassRegistrar() = default; 63 | 64 | static WindowClassRegistrar* instance_; 65 | 66 | bool class_registered_ = false; 67 | }; 68 | 69 | WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; 70 | 71 | const wchar_t* WindowClassRegistrar::GetWindowClass() { 72 | if (!class_registered_) { 73 | WNDCLASS window_class{}; 74 | window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); 75 | window_class.lpszClassName = kWindowClassName; 76 | window_class.style = CS_HREDRAW | CS_VREDRAW; 77 | window_class.cbClsExtra = 0; 78 | window_class.cbWndExtra = 0; 79 | window_class.hInstance = GetModuleHandle(nullptr); 80 | window_class.hIcon = 81 | LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); 82 | window_class.hbrBackground = 0; 83 | window_class.lpszMenuName = nullptr; 84 | window_class.lpfnWndProc = Win32Window::WndProc; 85 | RegisterClass(&window_class); 86 | class_registered_ = true; 87 | } 88 | return kWindowClassName; 89 | } 90 | 91 | void WindowClassRegistrar::UnregisterWindowClass() { 92 | UnregisterClass(kWindowClassName, nullptr); 93 | class_registered_ = false; 94 | } 95 | 96 | Win32Window::Win32Window() { 97 | ++g_active_window_count; 98 | } 99 | 100 | Win32Window::~Win32Window() { 101 | --g_active_window_count; 102 | Destroy(); 103 | } 104 | 105 | bool Win32Window::CreateAndShow(const std::wstring& title, 106 | const Point& origin, 107 | const Size& size) { 108 | Destroy(); 109 | 110 | const wchar_t* window_class = 111 | WindowClassRegistrar::GetInstance()->GetWindowClass(); 112 | 113 | const POINT target_point = {static_cast(origin.x), 114 | static_cast(origin.y)}; 115 | HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST); 116 | UINT dpi = FlutterDesktopGetDpiForMonitor(monitor); 117 | double scale_factor = dpi / 96.0; 118 | 119 | HWND window = CreateWindow( 120 | window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, 121 | Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), 122 | Scale(size.width, scale_factor), Scale(size.height, scale_factor), 123 | nullptr, nullptr, GetModuleHandle(nullptr), this); 124 | 125 | if (!window) { 126 | return false; 127 | } 128 | 129 | return OnCreate(); 130 | } 131 | 132 | // static 133 | LRESULT CALLBACK Win32Window::WndProc(HWND const window, 134 | UINT const message, 135 | WPARAM const wparam, 136 | LPARAM const lparam) noexcept { 137 | if (message == WM_NCCREATE) { 138 | auto window_struct = reinterpret_cast(lparam); 139 | SetWindowLongPtr(window, GWLP_USERDATA, 140 | reinterpret_cast(window_struct->lpCreateParams)); 141 | 142 | auto that = static_cast(window_struct->lpCreateParams); 143 | EnableFullDpiSupportIfAvailable(window); 144 | that->window_handle_ = window; 145 | } else if (Win32Window* that = GetThisFromHandle(window)) { 146 | return that->MessageHandler(window, message, wparam, lparam); 147 | } 148 | 149 | return DefWindowProc(window, message, wparam, lparam); 150 | } 151 | 152 | LRESULT 153 | Win32Window::MessageHandler(HWND hwnd, 154 | UINT const message, 155 | WPARAM const wparam, 156 | LPARAM const lparam) noexcept { 157 | switch (message) { 158 | case WM_DESTROY: 159 | window_handle_ = nullptr; 160 | Destroy(); 161 | if (quit_on_close_) { 162 | PostQuitMessage(0); 163 | } 164 | return 0; 165 | 166 | case WM_DPICHANGED: { 167 | auto newRectSize = reinterpret_cast(lparam); 168 | LONG newWidth = newRectSize->right - newRectSize->left; 169 | LONG newHeight = newRectSize->bottom - newRectSize->top; 170 | 171 | SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, 172 | newHeight, SWP_NOZORDER | SWP_NOACTIVATE); 173 | 174 | return 0; 175 | } 176 | case WM_SIZE: { 177 | RECT rect = GetClientArea(); 178 | if (child_content_ != nullptr) { 179 | // Size and position the child window. 180 | MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, 181 | rect.bottom - rect.top, TRUE); 182 | } 183 | return 0; 184 | } 185 | 186 | case WM_ACTIVATE: 187 | if (child_content_ != nullptr) { 188 | SetFocus(child_content_); 189 | } 190 | return 0; 191 | } 192 | 193 | return DefWindowProc(window_handle_, message, wparam, lparam); 194 | } 195 | 196 | void Win32Window::Destroy() { 197 | OnDestroy(); 198 | 199 | if (window_handle_) { 200 | DestroyWindow(window_handle_); 201 | window_handle_ = nullptr; 202 | } 203 | if (g_active_window_count == 0) { 204 | WindowClassRegistrar::GetInstance()->UnregisterWindowClass(); 205 | } 206 | } 207 | 208 | Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { 209 | return reinterpret_cast( 210 | GetWindowLongPtr(window, GWLP_USERDATA)); 211 | } 212 | 213 | void Win32Window::SetChildContent(HWND content) { 214 | child_content_ = content; 215 | SetParent(content, window_handle_); 216 | RECT frame = GetClientArea(); 217 | 218 | MoveWindow(content, frame.left, frame.top, frame.right - frame.left, 219 | frame.bottom - frame.top, true); 220 | 221 | SetFocus(child_content_); 222 | } 223 | 224 | RECT Win32Window::GetClientArea() { 225 | RECT frame; 226 | GetClientRect(window_handle_, &frame); 227 | return frame; 228 | } 229 | 230 | HWND Win32Window::GetHandle() { 231 | return window_handle_; 232 | } 233 | 234 | void Win32Window::SetQuitOnClose(bool quit_on_close) { 235 | quit_on_close_ = quit_on_close; 236 | } 237 | 238 | bool Win32Window::OnCreate() { 239 | // No-op; provided for subclasses. 240 | return true; 241 | } 242 | 243 | void Win32Window::OnDestroy() { 244 | // No-op; provided for subclasses. 245 | } 246 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------