├── .flutter-plugins-dependencies ├── .gitignore ├── .metadata ├── .vscode └── launch.json ├── README.md ├── android ├── app │ ├── build.gradle │ └── src │ │ ├── debug │ │ └── AndroidManifest.xml │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── kotlin │ │ │ └── com │ │ │ │ └── resocoder │ │ │ │ └── clean_architecture_tdd_course │ │ │ │ └── MainActivity.kt │ │ └── res │ │ │ ├── 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 │ │ │ └── styles.xml │ │ └── profile │ │ └── AndroidManifest.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ └── gradle-wrapper.properties └── settings.gradle ├── architecture-proposal.png ├── ios ├── Flutter │ ├── AppFrameworkInfo.plist │ ├── Debug.xcconfig │ ├── Release.xcconfig │ └── flutter_export_environment.sh ├── Runner.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ └── Runner.xcscheme ├── Runner.xcworkspace │ └── contents.xcworkspacedata └── Runner │ ├── AppDelegate.swift │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── Icon-App-1024x1024@1x.png │ │ ├── Icon-App-20x20@1x.png │ │ ├── Icon-App-20x20@2x.png │ │ ├── Icon-App-20x20@3x.png │ │ ├── Icon-App-29x29@1x.png │ │ ├── Icon-App-29x29@2x.png │ │ ├── Icon-App-29x29@3x.png │ │ ├── Icon-App-40x40@1x.png │ │ ├── Icon-App-40x40@2x.png │ │ ├── Icon-App-40x40@3x.png │ │ ├── Icon-App-60x60@2x.png │ │ ├── Icon-App-60x60@3x.png │ │ ├── Icon-App-76x76@1x.png │ │ ├── Icon-App-76x76@2x.png │ │ └── Icon-App-83.5x83.5@2x.png │ └── LaunchImage.imageset │ │ ├── Contents.json │ │ ├── LaunchImage.png │ │ ├── LaunchImage@2x.png │ │ ├── LaunchImage@3x.png │ │ └── README.md │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ └── Runner-Bridging-Header.h ├── lib ├── core │ ├── .gitkeep │ ├── error │ │ ├── .gitkeep │ │ ├── exceptions.dart │ │ └── failures.dart │ ├── network │ │ └── network_info.dart │ ├── usecases │ │ ├── .gitkeep │ │ └── usecase.dart │ └── util │ │ └── input_converter.dart ├── features │ ├── .gitkeep │ └── number_trivia │ │ ├── data │ │ ├── .gitkeep │ │ ├── datasources │ │ │ ├── .gitkeep │ │ │ ├── number_trivia_local_data_source.dart │ │ │ └── number_trivia_remote_data_source.dart │ │ ├── models │ │ │ ├── .gitkeep │ │ │ └── number_trivia_model.dart │ │ └── repositories │ │ │ ├── .gitkeep │ │ │ └── number_trivia_repository_impl.dart │ │ ├── domain │ │ ├── .gitkeep │ │ ├── entities │ │ │ ├── .gitkeep │ │ │ └── number_trivia.dart │ │ ├── repositories │ │ │ ├── .gitkeep │ │ │ └── number_trivia_repository.dart │ │ └── usecases │ │ │ ├── .gitkeep │ │ │ ├── get_concrete_number_trivia.dart │ │ │ └── get_random_number_trivia.dart │ │ └── presentation │ │ ├── .gitkeep │ │ ├── bloc │ │ ├── bloc.dart │ │ ├── number_trivia_bloc.dart │ │ ├── number_trivia_event.dart │ │ └── number_trivia_state.dart │ │ ├── pages │ │ ├── .gitkeep │ │ └── number_trivia_page.dart │ │ └── widgets │ │ ├── .gitkeep │ │ ├── loading_widget.dart │ │ ├── message_display.dart │ │ ├── trivia_controls.dart │ │ ├── trivia_display.dart │ │ └── widgets.dart ├── injection_container.dart └── main.dart ├── pubspec.lock ├── pubspec.yaml └── test ├── core ├── .gitkeep ├── error │ └── .gitkeep ├── network │ └── network_info_test.dart ├── usecases │ └── .gitkeep └── util │ └── input_converter_test.dart ├── features ├── .gitkeep └── number_trivia │ ├── data │ ├── .gitkeep │ ├── datasources │ │ ├── .gitkeep │ │ ├── number_trivia_local_data_source_test.dart │ │ └── number_trivia_remote_data_source_test.dart │ ├── models │ │ ├── .gitkeep │ │ └── number_trivia_model_test.dart │ └── repositories │ │ ├── .gitkeep │ │ └── number_trivia_repository_impl_test.dart │ ├── domain │ ├── .gitkeep │ ├── entities │ │ └── .gitkeep │ ├── repositories │ │ └── .gitkeep │ └── usecases │ │ ├── .gitkeep │ │ ├── get_concrete_number_trivia_test.dart │ │ └── get_random_number_trivia_test.dart │ └── presentation │ ├── .gitkeep │ ├── bloc │ ├── .gitkeep │ └── number_trivia_bloc_test.dart │ ├── pages │ └── .gitkeep │ └── widgets │ └── .gitkeep └── fixtures ├── fixture_reader.dart ├── trivia.json ├── trivia_cached.json └── trivia_double.json /.flutter-plugins-dependencies: -------------------------------------------------------------------------------- 1 | {"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]}]} -------------------------------------------------------------------------------- /.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 | .dart_tool/ 26 | .flutter-plugins 27 | .packages 28 | .pub-cache/ 29 | .pub/ 30 | /build/ 31 | 32 | # Android related 33 | **/android/**/gradle-wrapper.jar 34 | **/android/.gradle 35 | **/android/captures/ 36 | **/android/gradlew 37 | **/android/gradlew.bat 38 | **/android/local.properties 39 | **/android/**/GeneratedPluginRegistrant.java 40 | 41 | # iOS/XCode related 42 | **/ios/**/*.mode1v3 43 | **/ios/**/*.mode2v3 44 | **/ios/**/*.moved-aside 45 | **/ios/**/*.pbxuser 46 | **/ios/**/*.perspectivev3 47 | **/ios/**/*sync/ 48 | **/ios/**/.sconsign.dblite 49 | **/ios/**/.tags* 50 | **/ios/**/.vagrant/ 51 | **/ios/**/DerivedData/ 52 | **/ios/**/Icon? 53 | **/ios/**/Pods/ 54 | **/ios/**/.symlinks/ 55 | **/ios/**/profile 56 | **/ios/**/xcuserdata 57 | **/ios/.generated/ 58 | **/ios/Flutter/App.framework 59 | **/ios/Flutter/Flutter.framework 60 | **/ios/Flutter/Generated.xcconfig 61 | **/ios/Flutter/app.flx 62 | **/ios/Flutter/app.zip 63 | **/ios/Flutter/flutter_assets/ 64 | **/ios/ServiceDefinitions.json 65 | **/ios/Runner/GeneratedPluginRegistrant.* 66 | 67 | # Exceptions to above rules. 68 | !**/ios/**/default.mode1v3 69 | !**/ios/**/default.mode2v3 70 | !**/ios/**/default.pbxuser 71 | !**/ios/**/default.perspectivev3 72 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages 73 | -------------------------------------------------------------------------------- /.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 and should not be manually edited. 5 | 6 | version: 7 | revision: 20e59316b8b8474554b38493b8ca888794b0234a 8 | channel: stable 9 | 10 | project_type: app 11 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Dart: Run all Tests", 9 | "type": "dart", 10 | "request": "launch", 11 | "program": "./test/" 12 | }, 13 | { 14 | "name": "Flutter", 15 | "request": "launch", 16 | "type": "dart" 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TDD Clean Architecture for Flutter 2 | 3 | ### The whole accompanying tutorial series is available at :point_right: [this link](https://resocoder.com/flutter-clean-architecture-tdd/) :point_left:. 4 | 5 | #### _Find more tutorials on [resocoder.com](https://resocoder.com)_ 6 | 7 |
8 | 9 |

Architecture Proposal

10 | 11 |
12 | 13 | 14 | 15 |
16 |
17 | 18 | [![Reso Coder](https://resocoder.com/wp-content/uploads/2019/09/logo_with_text_signature.png)](https://resocoder.com) 19 |
20 | _Be prepared for **real** app development_ 21 | -------------------------------------------------------------------------------- /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 28 30 | 31 | sourceSets { 32 | main.java.srcDirs += 'src/main/kotlin' 33 | } 34 | 35 | lintOptions { 36 | disable 'InvalidPackage' 37 | } 38 | 39 | defaultConfig { 40 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 41 | applicationId "com.resocoder.clean_architecture_tdd_course" 42 | minSdkVersion 16 43 | targetSdkVersion 28 44 | versionCode flutterVersionCode.toInteger() 45 | versionName flutterVersionName 46 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 47 | } 48 | 49 | buildTypes { 50 | release { 51 | // TODO: Add your own signing config for the release build. 52 | // Signing with the debug keys for now, so `flutter run --release` works. 53 | signingConfig signingConfigs.debug 54 | } 55 | } 56 | } 57 | 58 | flutter { 59 | source '../..' 60 | } 61 | 62 | dependencies { 63 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 64 | testImplementation 'junit:junit:4.12' 65 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 66 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 67 | } 68 | -------------------------------------------------------------------------------- /android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 9 | 13 | 20 | 24 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /android/app/src/main/kotlin/com/resocoder/clean_architecture_tdd_course/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.resocoder.clean_architecture_tdd_course 2 | 3 | import android.os.Bundle 4 | 5 | import io.flutter.app.FlutterActivity 6 | import io.flutter.plugins.GeneratedPluginRegistrant 7 | 8 | class MainActivity: FlutterActivity() { 9 | override fun onCreate(savedInstanceState: Bundle?) { 10 | super.onCreate(savedInstanceState) 11 | GeneratedPluginRegistrant.registerWith(this) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /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/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | -------------------------------------------------------------------------------- /android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.2.71' 3 | repositories { 4 | google() 5 | jcenter() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:3.2.1' 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 | } 25 | subprojects { 26 | project.evaluationDependsOn(':app') 27 | } 28 | 29 | task clean(type: Delete) { 30 | delete rootProject.buildDir 31 | } 32 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | 3 | android.enableR8=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-4.10.2-all.zip 7 | -------------------------------------------------------------------------------- /android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | 3 | def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() 4 | 5 | def plugins = new Properties() 6 | def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') 7 | if (pluginsFile.exists()) { 8 | pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } 9 | } 10 | 11 | plugins.each { name, path -> 12 | def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() 13 | include ":$name" 14 | project(":$name").projectDir = pluginDirectory 15 | } 16 | -------------------------------------------------------------------------------- /architecture-proposal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/architecture-proposal.png -------------------------------------------------------------------------------- /ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 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 | 8.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /ios/Flutter/flutter_export_environment.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # This is a generated file; do not edit or check into version control. 3 | export "FLUTTER_ROOT=C:\Flutter\flutter" 4 | export "FLUTTER_APPLICATION_PATH=D:\Projects\Playground_and_Learning\flutter-tdd-clean-architecture-course" 5 | export "FLUTTER_TARGET=lib\main.dart" 6 | export "FLUTTER_BUILD_DIR=build" 7 | export "SYMROOT=${SOURCE_ROOT}/../build\ios" 8 | export "FLUTTER_FRAMEWORK_DIR=C:\Flutter\flutter\bin\cache\artifacts\engine\ios" 9 | export "FLUTTER_BUILD_NAME=1.0.0" 10 | export "FLUTTER_BUILD_NUMBER=1" 11 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 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 | 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; 13 | 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 14 | 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 15 | 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; 16 | 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 17 | 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; }; 18 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 19 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 20 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXCopyFilesBuildPhase section */ 24 | 9705A1C41CF9048500538489 /* Embed Frameworks */ = { 25 | isa = PBXCopyFilesBuildPhase; 26 | buildActionMask = 2147483647; 27 | dstPath = ""; 28 | dstSubfolderSpec = 10; 29 | files = ( 30 | 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */, 31 | 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */, 32 | ); 33 | name = "Embed Frameworks"; 34 | runOnlyForDeploymentPostprocessing = 0; 35 | }; 36 | /* End PBXCopyFilesBuildPhase section */ 37 | 38 | /* Begin PBXFileReference section */ 39 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 40 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 41 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 42 | 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 43 | 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 44 | 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 45 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 46 | 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 47 | 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 48 | 9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = ""; }; 49 | 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 50 | 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 51 | 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 52 | 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 53 | 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 54 | /* End PBXFileReference section */ 55 | 56 | /* Begin PBXFrameworksBuildPhase section */ 57 | 97C146EB1CF9000F007C117D /* Frameworks */ = { 58 | isa = PBXFrameworksBuildPhase; 59 | buildActionMask = 2147483647; 60 | files = ( 61 | 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, 62 | 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, 63 | ); 64 | runOnlyForDeploymentPostprocessing = 0; 65 | }; 66 | /* End PBXFrameworksBuildPhase section */ 67 | 68 | /* Begin PBXGroup section */ 69 | 9740EEB11CF90186004384FC /* Flutter */ = { 70 | isa = PBXGroup; 71 | children = ( 72 | 3B80C3931E831B6300D905FE /* App.framework */, 73 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 74 | 9740EEBA1CF902C7004384FC /* Flutter.framework */, 75 | 9740EEB21CF90195004384FC /* Debug.xcconfig */, 76 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, 77 | 9740EEB31CF90195004384FC /* Generated.xcconfig */, 78 | ); 79 | name = Flutter; 80 | sourceTree = ""; 81 | }; 82 | 97C146E51CF9000F007C117D = { 83 | isa = PBXGroup; 84 | children = ( 85 | 9740EEB11CF90186004384FC /* Flutter */, 86 | 97C146F01CF9000F007C117D /* Runner */, 87 | 97C146EF1CF9000F007C117D /* Products */, 88 | ); 89 | sourceTree = ""; 90 | }; 91 | 97C146EF1CF9000F007C117D /* Products */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | 97C146EE1CF9000F007C117D /* Runner.app */, 95 | ); 96 | name = Products; 97 | sourceTree = ""; 98 | }; 99 | 97C146F01CF9000F007C117D /* Runner */ = { 100 | isa = PBXGroup; 101 | children = ( 102 | 97C146FA1CF9000F007C117D /* Main.storyboard */, 103 | 97C146FD1CF9000F007C117D /* Assets.xcassets */, 104 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, 105 | 97C147021CF9000F007C117D /* Info.plist */, 106 | 97C146F11CF9000F007C117D /* Supporting Files */, 107 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, 108 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, 109 | 74858FAE1ED2DC5600515810 /* AppDelegate.swift */, 110 | 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */, 111 | ); 112 | path = Runner; 113 | sourceTree = ""; 114 | }; 115 | 97C146F11CF9000F007C117D /* Supporting Files */ = { 116 | isa = PBXGroup; 117 | children = ( 118 | ); 119 | name = "Supporting Files"; 120 | sourceTree = ""; 121 | }; 122 | /* End PBXGroup section */ 123 | 124 | /* Begin PBXNativeTarget section */ 125 | 97C146ED1CF9000F007C117D /* Runner */ = { 126 | isa = PBXNativeTarget; 127 | buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; 128 | buildPhases = ( 129 | 9740EEB61CF901F6004384FC /* Run Script */, 130 | 97C146EA1CF9000F007C117D /* Sources */, 131 | 97C146EB1CF9000F007C117D /* Frameworks */, 132 | 97C146EC1CF9000F007C117D /* Resources */, 133 | 9705A1C41CF9048500538489 /* Embed Frameworks */, 134 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */, 135 | ); 136 | buildRules = ( 137 | ); 138 | dependencies = ( 139 | ); 140 | name = Runner; 141 | productName = Runner; 142 | productReference = 97C146EE1CF9000F007C117D /* Runner.app */; 143 | productType = "com.apple.product-type.application"; 144 | }; 145 | /* End PBXNativeTarget section */ 146 | 147 | /* Begin PBXProject section */ 148 | 97C146E61CF9000F007C117D /* Project object */ = { 149 | isa = PBXProject; 150 | attributes = { 151 | LastUpgradeCheck = 1020; 152 | ORGANIZATIONNAME = "The Chromium Authors"; 153 | TargetAttributes = { 154 | 97C146ED1CF9000F007C117D = { 155 | CreatedOnToolsVersion = 7.3.1; 156 | LastSwiftMigration = 0910; 157 | }; 158 | }; 159 | }; 160 | buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; 161 | compatibilityVersion = "Xcode 3.2"; 162 | developmentRegion = en; 163 | hasScannedForEncodings = 0; 164 | knownRegions = ( 165 | en, 166 | Base, 167 | ); 168 | mainGroup = 97C146E51CF9000F007C117D; 169 | productRefGroup = 97C146EF1CF9000F007C117D /* Products */; 170 | projectDirPath = ""; 171 | projectRoot = ""; 172 | targets = ( 173 | 97C146ED1CF9000F007C117D /* Runner */, 174 | ); 175 | }; 176 | /* End PBXProject section */ 177 | 178 | /* Begin PBXResourcesBuildPhase section */ 179 | 97C146EC1CF9000F007C117D /* Resources */ = { 180 | isa = PBXResourcesBuildPhase; 181 | buildActionMask = 2147483647; 182 | files = ( 183 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, 184 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 185 | 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */, 186 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, 187 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, 188 | ); 189 | runOnlyForDeploymentPostprocessing = 0; 190 | }; 191 | /* End PBXResourcesBuildPhase section */ 192 | 193 | /* Begin PBXShellScriptBuildPhase section */ 194 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { 195 | isa = PBXShellScriptBuildPhase; 196 | buildActionMask = 2147483647; 197 | files = ( 198 | ); 199 | inputPaths = ( 200 | ); 201 | name = "Thin Binary"; 202 | outputPaths = ( 203 | ); 204 | runOnlyForDeploymentPostprocessing = 0; 205 | shellPath = /bin/sh; 206 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin"; 207 | }; 208 | 9740EEB61CF901F6004384FC /* Run Script */ = { 209 | isa = PBXShellScriptBuildPhase; 210 | buildActionMask = 2147483647; 211 | files = ( 212 | ); 213 | inputPaths = ( 214 | ); 215 | name = "Run Script"; 216 | outputPaths = ( 217 | ); 218 | runOnlyForDeploymentPostprocessing = 0; 219 | shellPath = /bin/sh; 220 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; 221 | }; 222 | /* End PBXShellScriptBuildPhase section */ 223 | 224 | /* Begin PBXSourcesBuildPhase section */ 225 | 97C146EA1CF9000F007C117D /* Sources */ = { 226 | isa = PBXSourcesBuildPhase; 227 | buildActionMask = 2147483647; 228 | files = ( 229 | 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */, 230 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, 231 | ); 232 | runOnlyForDeploymentPostprocessing = 0; 233 | }; 234 | /* End PBXSourcesBuildPhase section */ 235 | 236 | /* Begin PBXVariantGroup section */ 237 | 97C146FA1CF9000F007C117D /* Main.storyboard */ = { 238 | isa = PBXVariantGroup; 239 | children = ( 240 | 97C146FB1CF9000F007C117D /* Base */, 241 | ); 242 | name = Main.storyboard; 243 | sourceTree = ""; 244 | }; 245 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { 246 | isa = PBXVariantGroup; 247 | children = ( 248 | 97C147001CF9000F007C117D /* Base */, 249 | ); 250 | name = LaunchScreen.storyboard; 251 | sourceTree = ""; 252 | }; 253 | /* End PBXVariantGroup section */ 254 | 255 | /* Begin XCBuildConfiguration section */ 256 | 249021D3217E4FDB00AE95B9 /* Profile */ = { 257 | isa = XCBuildConfiguration; 258 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 259 | buildSettings = { 260 | ALWAYS_SEARCH_USER_PATHS = NO; 261 | CLANG_ANALYZER_NONNULL = YES; 262 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 263 | CLANG_CXX_LIBRARY = "libc++"; 264 | CLANG_ENABLE_MODULES = YES; 265 | CLANG_ENABLE_OBJC_ARC = YES; 266 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 267 | CLANG_WARN_BOOL_CONVERSION = YES; 268 | CLANG_WARN_COMMA = YES; 269 | CLANG_WARN_CONSTANT_CONVERSION = YES; 270 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 271 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 272 | CLANG_WARN_EMPTY_BODY = YES; 273 | CLANG_WARN_ENUM_CONVERSION = YES; 274 | CLANG_WARN_INFINITE_RECURSION = YES; 275 | CLANG_WARN_INT_CONVERSION = YES; 276 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 277 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 278 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 279 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 280 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 281 | CLANG_WARN_STRICT_PROTOTYPES = YES; 282 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 283 | CLANG_WARN_UNREACHABLE_CODE = YES; 284 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 285 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 286 | COPY_PHASE_STRIP = NO; 287 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 288 | ENABLE_NS_ASSERTIONS = NO; 289 | ENABLE_STRICT_OBJC_MSGSEND = YES; 290 | GCC_C_LANGUAGE_STANDARD = gnu99; 291 | GCC_NO_COMMON_BLOCKS = YES; 292 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 293 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 294 | GCC_WARN_UNDECLARED_SELECTOR = YES; 295 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 296 | GCC_WARN_UNUSED_FUNCTION = YES; 297 | GCC_WARN_UNUSED_VARIABLE = YES; 298 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 299 | MTL_ENABLE_DEBUG_INFO = NO; 300 | SDKROOT = iphoneos; 301 | TARGETED_DEVICE_FAMILY = "1,2"; 302 | VALIDATE_PRODUCT = YES; 303 | }; 304 | name = Profile; 305 | }; 306 | 249021D4217E4FDB00AE95B9 /* Profile */ = { 307 | isa = XCBuildConfiguration; 308 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 309 | buildSettings = { 310 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 311 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 312 | DEVELOPMENT_TEAM = S8QB4VV633; 313 | ENABLE_BITCODE = NO; 314 | FRAMEWORK_SEARCH_PATHS = ( 315 | "$(inherited)", 316 | "$(PROJECT_DIR)/Flutter", 317 | ); 318 | INFOPLIST_FILE = Runner/Info.plist; 319 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 320 | LIBRARY_SEARCH_PATHS = ( 321 | "$(inherited)", 322 | "$(PROJECT_DIR)/Flutter", 323 | ); 324 | PRODUCT_BUNDLE_IDENTIFIER = com.resocoder.cleanArchitectureTddCourse; 325 | PRODUCT_NAME = "$(TARGET_NAME)"; 326 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 327 | SWIFT_VERSION = 4.0; 328 | VERSIONING_SYSTEM = "apple-generic"; 329 | }; 330 | name = Profile; 331 | }; 332 | 97C147031CF9000F007C117D /* Debug */ = { 333 | isa = XCBuildConfiguration; 334 | baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; 335 | buildSettings = { 336 | ALWAYS_SEARCH_USER_PATHS = NO; 337 | CLANG_ANALYZER_NONNULL = YES; 338 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 339 | CLANG_CXX_LIBRARY = "libc++"; 340 | CLANG_ENABLE_MODULES = YES; 341 | CLANG_ENABLE_OBJC_ARC = YES; 342 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 343 | CLANG_WARN_BOOL_CONVERSION = YES; 344 | CLANG_WARN_COMMA = YES; 345 | CLANG_WARN_CONSTANT_CONVERSION = YES; 346 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 347 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 348 | CLANG_WARN_EMPTY_BODY = YES; 349 | CLANG_WARN_ENUM_CONVERSION = YES; 350 | CLANG_WARN_INFINITE_RECURSION = YES; 351 | CLANG_WARN_INT_CONVERSION = YES; 352 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 353 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 354 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 355 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 356 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 357 | CLANG_WARN_STRICT_PROTOTYPES = YES; 358 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 359 | CLANG_WARN_UNREACHABLE_CODE = YES; 360 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 361 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 362 | COPY_PHASE_STRIP = NO; 363 | DEBUG_INFORMATION_FORMAT = dwarf; 364 | ENABLE_STRICT_OBJC_MSGSEND = YES; 365 | ENABLE_TESTABILITY = YES; 366 | GCC_C_LANGUAGE_STANDARD = gnu99; 367 | GCC_DYNAMIC_NO_PIC = NO; 368 | GCC_NO_COMMON_BLOCKS = YES; 369 | GCC_OPTIMIZATION_LEVEL = 0; 370 | GCC_PREPROCESSOR_DEFINITIONS = ( 371 | "DEBUG=1", 372 | "$(inherited)", 373 | ); 374 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 375 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 376 | GCC_WARN_UNDECLARED_SELECTOR = YES; 377 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 378 | GCC_WARN_UNUSED_FUNCTION = YES; 379 | GCC_WARN_UNUSED_VARIABLE = YES; 380 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 381 | MTL_ENABLE_DEBUG_INFO = YES; 382 | ONLY_ACTIVE_ARCH = YES; 383 | SDKROOT = iphoneos; 384 | TARGETED_DEVICE_FAMILY = "1,2"; 385 | }; 386 | name = Debug; 387 | }; 388 | 97C147041CF9000F007C117D /* Release */ = { 389 | isa = XCBuildConfiguration; 390 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 391 | buildSettings = { 392 | ALWAYS_SEARCH_USER_PATHS = NO; 393 | CLANG_ANALYZER_NONNULL = YES; 394 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 395 | CLANG_CXX_LIBRARY = "libc++"; 396 | CLANG_ENABLE_MODULES = YES; 397 | CLANG_ENABLE_OBJC_ARC = YES; 398 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 399 | CLANG_WARN_BOOL_CONVERSION = YES; 400 | CLANG_WARN_COMMA = YES; 401 | CLANG_WARN_CONSTANT_CONVERSION = YES; 402 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 403 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 404 | CLANG_WARN_EMPTY_BODY = YES; 405 | CLANG_WARN_ENUM_CONVERSION = YES; 406 | CLANG_WARN_INFINITE_RECURSION = YES; 407 | CLANG_WARN_INT_CONVERSION = YES; 408 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 409 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 410 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 411 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 412 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 413 | CLANG_WARN_STRICT_PROTOTYPES = YES; 414 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 415 | CLANG_WARN_UNREACHABLE_CODE = YES; 416 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 417 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 418 | COPY_PHASE_STRIP = NO; 419 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 420 | ENABLE_NS_ASSERTIONS = NO; 421 | ENABLE_STRICT_OBJC_MSGSEND = YES; 422 | GCC_C_LANGUAGE_STANDARD = gnu99; 423 | GCC_NO_COMMON_BLOCKS = YES; 424 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 425 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 426 | GCC_WARN_UNDECLARED_SELECTOR = YES; 427 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 428 | GCC_WARN_UNUSED_FUNCTION = YES; 429 | GCC_WARN_UNUSED_VARIABLE = YES; 430 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 431 | MTL_ENABLE_DEBUG_INFO = NO; 432 | SDKROOT = iphoneos; 433 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 434 | TARGETED_DEVICE_FAMILY = "1,2"; 435 | VALIDATE_PRODUCT = YES; 436 | }; 437 | name = Release; 438 | }; 439 | 97C147061CF9000F007C117D /* Debug */ = { 440 | isa = XCBuildConfiguration; 441 | baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; 442 | buildSettings = { 443 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 444 | CLANG_ENABLE_MODULES = YES; 445 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 446 | ENABLE_BITCODE = NO; 447 | FRAMEWORK_SEARCH_PATHS = ( 448 | "$(inherited)", 449 | "$(PROJECT_DIR)/Flutter", 450 | ); 451 | INFOPLIST_FILE = Runner/Info.plist; 452 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 453 | LIBRARY_SEARCH_PATHS = ( 454 | "$(inherited)", 455 | "$(PROJECT_DIR)/Flutter", 456 | ); 457 | PRODUCT_BUNDLE_IDENTIFIER = com.resocoder.cleanArchitectureTddCourse; 458 | PRODUCT_NAME = "$(TARGET_NAME)"; 459 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 460 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 461 | SWIFT_SWIFT3_OBJC_INFERENCE = On; 462 | SWIFT_VERSION = 4.0; 463 | VERSIONING_SYSTEM = "apple-generic"; 464 | }; 465 | name = Debug; 466 | }; 467 | 97C147071CF9000F007C117D /* Release */ = { 468 | isa = XCBuildConfiguration; 469 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 470 | buildSettings = { 471 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 472 | CLANG_ENABLE_MODULES = YES; 473 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 474 | ENABLE_BITCODE = NO; 475 | FRAMEWORK_SEARCH_PATHS = ( 476 | "$(inherited)", 477 | "$(PROJECT_DIR)/Flutter", 478 | ); 479 | INFOPLIST_FILE = Runner/Info.plist; 480 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 481 | LIBRARY_SEARCH_PATHS = ( 482 | "$(inherited)", 483 | "$(PROJECT_DIR)/Flutter", 484 | ); 485 | PRODUCT_BUNDLE_IDENTIFIER = com.resocoder.cleanArchitectureTddCourse; 486 | PRODUCT_NAME = "$(TARGET_NAME)"; 487 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 488 | SWIFT_SWIFT3_OBJC_INFERENCE = On; 489 | SWIFT_VERSION = 4.0; 490 | VERSIONING_SYSTEM = "apple-generic"; 491 | }; 492 | name = Release; 493 | }; 494 | /* End XCBuildConfiguration section */ 495 | 496 | /* Begin XCConfigurationList section */ 497 | 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { 498 | isa = XCConfigurationList; 499 | buildConfigurations = ( 500 | 97C147031CF9000F007C117D /* Debug */, 501 | 97C147041CF9000F007C117D /* Release */, 502 | 249021D3217E4FDB00AE95B9 /* Profile */, 503 | ); 504 | defaultConfigurationIsVisible = 0; 505 | defaultConfigurationName = Release; 506 | }; 507 | 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { 508 | isa = XCConfigurationList; 509 | buildConfigurations = ( 510 | 97C147061CF9000F007C117D /* Debug */, 511 | 97C147071CF9000F007C117D /* Release */, 512 | 249021D4217E4FDB00AE95B9 /* Profile */, 513 | ); 514 | defaultConfigurationIsVisible = 0; 515 | defaultConfigurationName = Release; 516 | }; 517 | /* End XCConfigurationList section */ 518 | 519 | }; 520 | rootObject = 97C146E61CF9000F007C117D /* Project object */; 521 | } 522 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /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 | 8 | -------------------------------------------------------------------------------- /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: [UIApplicationLaunchOptionsKey: 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/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/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/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/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/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/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/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/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/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/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/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/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/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/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/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/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/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/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/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/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/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/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/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/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/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/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/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/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/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/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/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/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_tdd_course 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 | 45 | 46 | -------------------------------------------------------------------------------- /ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" -------------------------------------------------------------------------------- /lib/core/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/lib/core/.gitkeep -------------------------------------------------------------------------------- /lib/core/error/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/lib/core/error/.gitkeep -------------------------------------------------------------------------------- /lib/core/error/exceptions.dart: -------------------------------------------------------------------------------- 1 | class ServerException implements Exception {} 2 | 3 | class CacheException implements Exception {} 4 | -------------------------------------------------------------------------------- /lib/core/error/failures.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | 3 | abstract class Failure extends Equatable { 4 | @override 5 | List get props => []; 6 | } 7 | 8 | // General failures 9 | class ServerFailure extends Failure {} 10 | 11 | class CacheFailure extends Failure {} 12 | -------------------------------------------------------------------------------- /lib/core/network/network_info.dart: -------------------------------------------------------------------------------- 1 | import 'package:data_connection_checker/data_connection_checker.dart'; 2 | 3 | abstract class NetworkInfo { 4 | Future get isConnected; 5 | } 6 | 7 | class NetworkInfoImpl implements NetworkInfo { 8 | final DataConnectionChecker connectionChecker; 9 | 10 | NetworkInfoImpl(this.connectionChecker); 11 | 12 | @override 13 | Future get isConnected => connectionChecker.hasConnection; 14 | } 15 | -------------------------------------------------------------------------------- /lib/core/usecases/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/lib/core/usecases/.gitkeep -------------------------------------------------------------------------------- /lib/core/usecases/usecase.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:equatable/equatable.dart'; 3 | 4 | import '../error/failures.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/util/input_converter.dart: -------------------------------------------------------------------------------- 1 | import 'package:clean_architecture_tdd_course/core/error/failures.dart'; 2 | import 'package:dartz/dartz.dart'; 3 | 4 | class InputConverter { 5 | Either stringToUnsignedInteger(String str) { 6 | try { 7 | final integer = int.parse(str); 8 | if (integer < 0) throw FormatException(); 9 | return Right(integer); 10 | } on FormatException { 11 | return Left(InvalidInputFailure()); 12 | } 13 | } 14 | } 15 | 16 | class InvalidInputFailure extends Failure {} 17 | -------------------------------------------------------------------------------- /lib/features/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/lib/features/.gitkeep -------------------------------------------------------------------------------- /lib/features/number_trivia/data/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/lib/features/number_trivia/data/.gitkeep -------------------------------------------------------------------------------- /lib/features/number_trivia/data/datasources/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/lib/features/number_trivia/data/datasources/.gitkeep -------------------------------------------------------------------------------- /lib/features/number_trivia/data/datasources/number_trivia_local_data_source.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:clean_architecture_tdd_course/core/error/exceptions.dart'; 4 | import 'package:meta/meta.dart'; 5 | import 'package:shared_preferences/shared_preferences.dart'; 6 | 7 | import '../models/number_trivia_model.dart'; 8 | 9 | abstract class NumberTriviaLocalDataSource { 10 | /// Gets the cached [NumberTriviaModel] which was gotten the last time 11 | /// the user had an internet connection. 12 | /// 13 | /// Throws [CacheException] if no cached data is present. 14 | Future getLastNumberTrivia(); 15 | 16 | Future cacheNumberTrivia(NumberTriviaModel triviaToCache); 17 | } 18 | 19 | const CACHED_NUMBER_TRIVIA = 'CACHED_NUMBER_TRIVIA'; 20 | 21 | class NumberTriviaLocalDataSourceImpl implements NumberTriviaLocalDataSource { 22 | final SharedPreferences sharedPreferences; 23 | 24 | NumberTriviaLocalDataSourceImpl({@required this.sharedPreferences}); 25 | 26 | @override 27 | Future getLastNumberTrivia() { 28 | final jsonString = sharedPreferences.getString(CACHED_NUMBER_TRIVIA); 29 | if (jsonString != null) { 30 | return Future.value(NumberTriviaModel.fromJson(json.decode(jsonString))); 31 | } else { 32 | throw CacheException(); 33 | } 34 | } 35 | 36 | @override 37 | Future cacheNumberTrivia(NumberTriviaModel triviaToCache) { 38 | return sharedPreferences.setString( 39 | CACHED_NUMBER_TRIVIA, 40 | json.encode(triviaToCache.toJson()), 41 | ); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /lib/features/number_trivia/data/datasources/number_trivia_remote_data_source.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:http/http.dart' as http; 4 | import 'package:meta/meta.dart'; 5 | 6 | import '../../../../core/error/exceptions.dart'; 7 | import '../models/number_trivia_model.dart'; 8 | 9 | abstract class NumberTriviaRemoteDataSource { 10 | /// Calls the http://numbersapi.com/{number} endpoint. 11 | /// 12 | /// Throws a [ServerException] for all error codes. 13 | Future getConcreteNumberTrivia(int number); 14 | 15 | /// Calls the http://numbersapi.com/random endpoint. 16 | /// 17 | /// Throws a [ServerException] for all error codes. 18 | Future getRandomNumberTrivia(); 19 | } 20 | 21 | class NumberTriviaRemoteDataSourceImpl implements NumberTriviaRemoteDataSource { 22 | final http.Client client; 23 | 24 | NumberTriviaRemoteDataSourceImpl({@required this.client}); 25 | 26 | @override 27 | Future getConcreteNumberTrivia(int number) => 28 | _getTriviaFromUrl('http://numbersapi.com/$number'); 29 | 30 | @override 31 | Future getRandomNumberTrivia() => 32 | _getTriviaFromUrl('http://numbersapi.com/random'); 33 | 34 | Future _getTriviaFromUrl(String url) async { 35 | final response = await client.get( 36 | url, 37 | headers: { 38 | 'Content-Type': 'application/json', 39 | }, 40 | ); 41 | 42 | if (response.statusCode == 200) { 43 | return NumberTriviaModel.fromJson(json.decode(response.body)); 44 | } else { 45 | throw ServerException(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /lib/features/number_trivia/data/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/lib/features/number_trivia/data/models/.gitkeep -------------------------------------------------------------------------------- /lib/features/number_trivia/data/models/number_trivia_model.dart: -------------------------------------------------------------------------------- 1 | import 'package:clean_architecture_tdd_course/features/number_trivia/domain/entities/number_trivia.dart'; 2 | import 'package:meta/meta.dart'; 3 | 4 | class NumberTriviaModel extends NumberTrivia { 5 | NumberTriviaModel({ 6 | @required String text, 7 | @required int number, 8 | }) : super(text: text, number: number); 9 | 10 | factory NumberTriviaModel.fromJson(Map json) { 11 | return NumberTriviaModel( 12 | text: json['text'], 13 | number: (json['number'] as num).toInt(), 14 | ); 15 | } 16 | 17 | Map toJson() { 18 | return { 19 | 'text': text, 20 | 'number': number, 21 | }; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lib/features/number_trivia/data/repositories/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/lib/features/number_trivia/data/repositories/.gitkeep -------------------------------------------------------------------------------- /lib/features/number_trivia/data/repositories/number_trivia_repository_impl.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:meta/meta.dart'; 3 | 4 | import '../../../../core/error/failures.dart'; 5 | import '../../../../core/error/exceptions.dart'; 6 | import '../../../../core/network/network_info.dart'; 7 | import '../../domain/entities/number_trivia.dart'; 8 | import '../../domain/repositories/number_trivia_repository.dart'; 9 | import '../datasources/number_trivia_local_data_source.dart'; 10 | import '../datasources/number_trivia_remote_data_source.dart'; 11 | 12 | typedef Future _ConcreteOrRandomChooser(); 13 | 14 | class NumberTriviaRepositoryImpl implements NumberTriviaRepository { 15 | final NumberTriviaRemoteDataSource remoteDataSource; 16 | final NumberTriviaLocalDataSource localDataSource; 17 | final NetworkInfo networkInfo; 18 | 19 | NumberTriviaRepositoryImpl({ 20 | @required this.remoteDataSource, 21 | @required this.localDataSource, 22 | @required this.networkInfo, 23 | }); 24 | 25 | @override 26 | Future> getConcreteNumberTrivia( 27 | int number, 28 | ) async { 29 | return await _getTrivia(() { 30 | return remoteDataSource.getConcreteNumberTrivia(number); 31 | }); 32 | } 33 | 34 | @override 35 | Future> getRandomNumberTrivia() async { 36 | return await _getTrivia(() { 37 | return remoteDataSource.getRandomNumberTrivia(); 38 | }); 39 | } 40 | 41 | Future> _getTrivia( 42 | _ConcreteOrRandomChooser getConcreteOrRandom, 43 | ) async { 44 | if (await networkInfo.isConnected) { 45 | try { 46 | final remoteTrivia = await getConcreteOrRandom(); 47 | localDataSource.cacheNumberTrivia(remoteTrivia); 48 | return Right(remoteTrivia); 49 | } on ServerException { 50 | return Left(ServerFailure()); 51 | } 52 | } else { 53 | try { 54 | final localTrivia = await localDataSource.getLastNumberTrivia(); 55 | return Right(localTrivia); 56 | } on CacheException { 57 | return Left(CacheFailure()); 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /lib/features/number_trivia/domain/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/lib/features/number_trivia/domain/.gitkeep -------------------------------------------------------------------------------- /lib/features/number_trivia/domain/entities/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/lib/features/number_trivia/domain/entities/.gitkeep -------------------------------------------------------------------------------- /lib/features/number_trivia/domain/entities/number_trivia.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | import 'package:meta/meta.dart'; 3 | 4 | class NumberTrivia extends Equatable { 5 | final String text; 6 | final int number; 7 | 8 | NumberTrivia({ 9 | @required this.text, 10 | @required this.number, 11 | }); 12 | 13 | @override 14 | List get props => [text, number]; 15 | } 16 | -------------------------------------------------------------------------------- /lib/features/number_trivia/domain/repositories/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/lib/features/number_trivia/domain/repositories/.gitkeep -------------------------------------------------------------------------------- /lib/features/number_trivia/domain/repositories/number_trivia_repository.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | 3 | import '../../../../core/error/failures.dart'; 4 | import '../entities/number_trivia.dart'; 5 | 6 | abstract class NumberTriviaRepository { 7 | Future> getConcreteNumberTrivia(int number); 8 | Future> getRandomNumberTrivia(); 9 | } 10 | -------------------------------------------------------------------------------- /lib/features/number_trivia/domain/usecases/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/lib/features/number_trivia/domain/usecases/.gitkeep -------------------------------------------------------------------------------- /lib/features/number_trivia/domain/usecases/get_concrete_number_trivia.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:equatable/equatable.dart'; 3 | import 'package:meta/meta.dart'; 4 | 5 | import '../../../../core/error/failures.dart'; 6 | import '../../../../core/usecases/usecase.dart'; 7 | import '../entities/number_trivia.dart'; 8 | import '../repositories/number_trivia_repository.dart'; 9 | 10 | class GetConcreteNumberTrivia implements UseCase { 11 | final NumberTriviaRepository repository; 12 | 13 | GetConcreteNumberTrivia(this.repository); 14 | 15 | @override 16 | Future> call(Params params) async { 17 | return await repository.getConcreteNumberTrivia(params.number); 18 | } 19 | } 20 | 21 | class Params extends Equatable { 22 | final int number; 23 | 24 | Params({@required this.number}); 25 | 26 | @override 27 | List get props => [number]; 28 | } 29 | -------------------------------------------------------------------------------- /lib/features/number_trivia/domain/usecases/get_random_number_trivia.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | 3 | import '../../../../core/error/failures.dart'; 4 | import '../../../../core/usecases/usecase.dart'; 5 | import '../entities/number_trivia.dart'; 6 | import '../repositories/number_trivia_repository.dart'; 7 | 8 | class GetRandomNumberTrivia implements UseCase { 9 | final NumberTriviaRepository repository; 10 | 11 | GetRandomNumberTrivia(this.repository); 12 | 13 | @override 14 | Future> call(NoParams params) async { 15 | return await repository.getRandomNumberTrivia(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/lib/features/number_trivia/presentation/.gitkeep -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/bloc/bloc.dart: -------------------------------------------------------------------------------- 1 | export 'number_trivia_bloc.dart'; 2 | export 'number_trivia_event.dart'; 3 | export 'number_trivia_state.dart'; 4 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/bloc/number_trivia_bloc.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:bloc/bloc.dart'; 4 | import 'package:clean_architecture_tdd_course/core/error/failures.dart'; 5 | import 'package:clean_architecture_tdd_course/core/usecases/usecase.dart'; 6 | import 'package:clean_architecture_tdd_course/features/number_trivia/domain/entities/number_trivia.dart'; 7 | import 'package:dartz/dartz.dart'; 8 | import 'package:meta/meta.dart'; 9 | 10 | import './bloc.dart'; 11 | import '../../../../core/util/input_converter.dart'; 12 | import '../../domain/usecases/get_concrete_number_trivia.dart'; 13 | import '../../domain/usecases/get_random_number_trivia.dart'; 14 | 15 | const String SERVER_FAILURE_MESSAGE = 'Server Failure'; 16 | const String CACHE_FAILURE_MESSAGE = 'Cache Failure'; 17 | const String INVALID_INPUT_FAILURE_MESSAGE = 18 | 'Invalid Input - The number must be a positive integer or zero.'; 19 | 20 | class NumberTriviaBloc extends Bloc { 21 | final GetConcreteNumberTrivia getConcreteNumberTrivia; 22 | final GetRandomNumberTrivia getRandomNumberTrivia; 23 | final InputConverter inputConverter; 24 | 25 | NumberTriviaBloc({ 26 | @required GetConcreteNumberTrivia concrete, 27 | @required GetRandomNumberTrivia random, 28 | @required this.inputConverter, 29 | }) : assert(concrete != null), 30 | assert(random != null), 31 | assert(inputConverter != null), 32 | getConcreteNumberTrivia = concrete, 33 | getRandomNumberTrivia = random; 34 | 35 | @override 36 | NumberTriviaState get initialState => Empty(); 37 | 38 | @override 39 | Stream mapEventToState( 40 | NumberTriviaEvent event, 41 | ) async* { 42 | if (event is GetTriviaForConcreteNumber) { 43 | final inputEither = 44 | inputConverter.stringToUnsignedInteger(event.numberString); 45 | 46 | yield* inputEither.fold( 47 | (failure) async* { 48 | yield Error(message: INVALID_INPUT_FAILURE_MESSAGE); 49 | }, 50 | (integer) async* { 51 | yield Loading(); 52 | final failureOrTrivia = 53 | await getConcreteNumberTrivia(Params(number: integer)); 54 | yield* _eitherLoadedOrErrorState(failureOrTrivia); 55 | }, 56 | ); 57 | } else if (event is GetTriviaForRandomNumber) { 58 | yield Loading(); 59 | final failureOrTrivia = await getRandomNumberTrivia(NoParams()); 60 | yield* _eitherLoadedOrErrorState(failureOrTrivia); 61 | } 62 | } 63 | 64 | Stream _eitherLoadedOrErrorState( 65 | Either failureOrTrivia, 66 | ) async* { 67 | yield failureOrTrivia.fold( 68 | (failure) => Error(message: _mapFailureToMessage(failure)), 69 | (trivia) => Loaded(trivia: trivia), 70 | ); 71 | } 72 | 73 | String _mapFailureToMessage(Failure failure) { 74 | switch (failure.runtimeType) { 75 | case ServerFailure: 76 | return SERVER_FAILURE_MESSAGE; 77 | case CacheFailure: 78 | return CACHE_FAILURE_MESSAGE; 79 | default: 80 | return 'Unexpected error'; 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/bloc/number_trivia_event.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | import 'package:meta/meta.dart'; 3 | 4 | @immutable 5 | abstract class NumberTriviaEvent extends Equatable { 6 | @override 7 | List get props => []; 8 | } 9 | 10 | class GetTriviaForConcreteNumber extends NumberTriviaEvent { 11 | final String numberString; 12 | 13 | GetTriviaForConcreteNumber(this.numberString); 14 | 15 | @override 16 | List get props => [numberString]; 17 | } 18 | 19 | class GetTriviaForRandomNumber extends NumberTriviaEvent {} 20 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/bloc/number_trivia_state.dart: -------------------------------------------------------------------------------- 1 | import 'package:clean_architecture_tdd_course/features/number_trivia/domain/entities/number_trivia.dart'; 2 | import 'package:equatable/equatable.dart'; 3 | import 'package:meta/meta.dart'; 4 | 5 | @immutable 6 | abstract class NumberTriviaState extends Equatable { 7 | @override 8 | List get props => []; 9 | } 10 | 11 | class Empty extends NumberTriviaState {} 12 | 13 | class Loading extends NumberTriviaState {} 14 | 15 | class Loaded extends NumberTriviaState { 16 | final NumberTrivia trivia; 17 | 18 | Loaded({@required this.trivia}); 19 | 20 | @override 21 | List get props => [trivia]; 22 | } 23 | 24 | class Error extends NumberTriviaState { 25 | final String message; 26 | 27 | Error({@required this.message}); 28 | 29 | @override 30 | List get props => [message]; 31 | } 32 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/pages/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/lib/features/number_trivia/presentation/pages/.gitkeep -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/pages/number_trivia_page.dart: -------------------------------------------------------------------------------- 1 | import 'package:clean_architecture_tdd_course/features/number_trivia/presentation/bloc/bloc.dart'; 2 | import 'package:clean_architecture_tdd_course/features/number_trivia/presentation/bloc/number_trivia_bloc.dart'; 3 | import 'package:clean_architecture_tdd_course/features/number_trivia/presentation/widgets/widgets.dart'; 4 | import 'package:flutter/material.dart'; 5 | import 'package:flutter_bloc/flutter_bloc.dart'; 6 | 7 | import '../../../../injection_container.dart'; 8 | 9 | class NumberTriviaPage extends StatelessWidget { 10 | @override 11 | Widget build(BuildContext context) { 12 | return Scaffold( 13 | appBar: AppBar( 14 | title: Text('Number Trivia'), 15 | ), 16 | body: SingleChildScrollView( 17 | child: buildBody(context), 18 | ), 19 | ); 20 | } 21 | 22 | BlocProvider buildBody(BuildContext context) { 23 | return BlocProvider( 24 | create: (_) => sl(), 25 | child: Center( 26 | child: Padding( 27 | padding: const EdgeInsets.all(10), 28 | child: Column( 29 | children: [ 30 | SizedBox(height: 10), 31 | // Top half 32 | BlocBuilder( 33 | builder: (context, state) { 34 | if (state is Empty) { 35 | return MessageDisplay( 36 | message: 'Start searching!', 37 | ); 38 | } else if (state is Loading) { 39 | return LoadingWidget(); 40 | } else if (state is Loaded) { 41 | return TriviaDisplay(numberTrivia: state.trivia); 42 | } else if (state is Error) { 43 | return MessageDisplay( 44 | message: state.message, 45 | ); 46 | } 47 | }, 48 | ), 49 | SizedBox(height: 20), 50 | // Bottom half 51 | TriviaControls() 52 | ], 53 | ), 54 | ), 55 | ), 56 | ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/widgets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/lib/features/number_trivia/presentation/widgets/.gitkeep -------------------------------------------------------------------------------- /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 | return Container( 11 | height: MediaQuery.of(context).size.height / 3, 12 | child: Center( 13 | child: CircularProgressIndicator(), 14 | ), 15 | ); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /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 this.message, 9 | }) : super(key: key); 10 | 11 | @override 12 | Widget build(BuildContext context) { 13 | return Container( 14 | height: MediaQuery.of(context).size.height / 3, 15 | child: Center( 16 | child: SingleChildScrollView( 17 | child: Text( 18 | message, 19 | style: TextStyle(fontSize: 25), 20 | textAlign: TextAlign.center, 21 | ), 22 | ), 23 | ), 24 | ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/widgets/trivia_controls.dart: -------------------------------------------------------------------------------- 1 | import 'package:clean_architecture_tdd_course/features/number_trivia/presentation/bloc/bloc.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_bloc/flutter_bloc.dart'; 4 | 5 | class TriviaControls extends StatefulWidget { 6 | const TriviaControls({ 7 | Key key, 8 | }) : super(key: key); 9 | 10 | @override 11 | _TriviaControlsState createState() => _TriviaControlsState(); 12 | } 13 | 14 | class _TriviaControlsState extends State { 15 | final controller = TextEditingController(); 16 | String inputStr; 17 | 18 | @override 19 | Widget build(BuildContext context) { 20 | return Column( 21 | children: [ 22 | TextField( 23 | controller: controller, 24 | keyboardType: TextInputType.number, 25 | decoration: InputDecoration( 26 | border: OutlineInputBorder(), 27 | hintText: 'Input a number', 28 | ), 29 | onChanged: (value) { 30 | inputStr = value; 31 | }, 32 | onSubmitted: (_) { 33 | dispatchConcrete(); 34 | }, 35 | ), 36 | SizedBox(height: 10), 37 | Row( 38 | children: [ 39 | Expanded( 40 | child: RaisedButton( 41 | child: Text('Search'), 42 | color: Theme.of(context).accentColor, 43 | textTheme: ButtonTextTheme.primary, 44 | onPressed: dispatchConcrete, 45 | ), 46 | ), 47 | SizedBox(width: 10), 48 | Expanded( 49 | child: RaisedButton( 50 | child: Text('Get random trivia'), 51 | onPressed: dispatchRandom, 52 | ), 53 | ), 54 | ], 55 | ) 56 | ], 57 | ); 58 | } 59 | 60 | void dispatchConcrete() { 61 | controller.clear(); 62 | BlocProvider.of(context) 63 | .add(GetTriviaForConcreteNumber(inputStr)); 64 | } 65 | 66 | void dispatchRandom() { 67 | controller.clear(); 68 | BlocProvider.of(context).add(GetTriviaForRandomNumber()); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/widgets/trivia_display.dart: -------------------------------------------------------------------------------- 1 | import 'package:clean_architecture_tdd_course/features/number_trivia/domain/entities/number_trivia.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class TriviaDisplay extends StatelessWidget { 5 | final NumberTrivia numberTrivia; 6 | 7 | const TriviaDisplay({ 8 | Key key, 9 | @required this.numberTrivia, 10 | }) : super(key: key); 11 | 12 | @override 13 | Widget build(BuildContext context) { 14 | return Container( 15 | height: MediaQuery.of(context).size.height / 3, 16 | child: Column( 17 | children: [ 18 | Text( 19 | numberTrivia.number.toString(), 20 | style: TextStyle(fontSize: 50, fontWeight: FontWeight.bold), 21 | ), 22 | Expanded( 23 | child: Center( 24 | child: SingleChildScrollView( 25 | child: Text( 26 | numberTrivia.text, 27 | style: TextStyle(fontSize: 25), 28 | textAlign: TextAlign.center, 29 | ), 30 | ), 31 | ), 32 | ), 33 | ], 34 | ), 35 | ); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/features/number_trivia/presentation/widgets/widgets.dart: -------------------------------------------------------------------------------- 1 | export 'loading_widget.dart'; 2 | export 'message_display.dart'; 3 | export 'trivia_display.dart'; 4 | export 'trivia_controls.dart'; 5 | -------------------------------------------------------------------------------- /lib/injection_container.dart: -------------------------------------------------------------------------------- 1 | import 'package:data_connection_checker/data_connection_checker.dart'; 2 | import 'package:get_it/get_it.dart'; 3 | import 'package:http/http.dart' as http; 4 | import 'package:shared_preferences/shared_preferences.dart'; 5 | 6 | import 'core/network/network_info.dart'; 7 | import 'core/util/input_converter.dart'; 8 | import 'features/number_trivia/data/datasources/number_trivia_local_data_source.dart'; 9 | import 'features/number_trivia/data/datasources/number_trivia_remote_data_source.dart'; 10 | import 'features/number_trivia/data/repositories/number_trivia_repository_impl.dart'; 11 | import 'features/number_trivia/domain/repositories/number_trivia_repository.dart'; 12 | import 'features/number_trivia/domain/usecases/get_concrete_number_trivia.dart'; 13 | import 'features/number_trivia/domain/usecases/get_random_number_trivia.dart'; 14 | import 'features/number_trivia/presentation/bloc/number_trivia_bloc.dart'; 15 | 16 | final sl = GetIt.instance; 17 | 18 | Future init() async { 19 | //! Features - Number Trivia 20 | // Bloc 21 | sl.registerFactory( 22 | () => NumberTriviaBloc( 23 | concrete: sl(), 24 | inputConverter: sl(), 25 | random: sl(), 26 | ), 27 | ); 28 | 29 | // Use cases 30 | sl.registerLazySingleton(() => GetConcreteNumberTrivia(sl())); 31 | sl.registerLazySingleton(() => GetRandomNumberTrivia(sl())); 32 | 33 | // Repository 34 | sl.registerLazySingleton( 35 | () => NumberTriviaRepositoryImpl( 36 | localDataSource: sl(), 37 | networkInfo: sl(), 38 | remoteDataSource: sl(), 39 | ), 40 | ); 41 | 42 | // Data sources 43 | sl.registerLazySingleton( 44 | () => NumberTriviaRemoteDataSourceImpl(client: sl()), 45 | ); 46 | 47 | sl.registerLazySingleton( 48 | () => NumberTriviaLocalDataSourceImpl(sharedPreferences: sl()), 49 | ); 50 | 51 | //! Core 52 | sl.registerLazySingleton(() => InputConverter()); 53 | sl.registerLazySingleton(() => NetworkInfoImpl(sl())); 54 | 55 | //! External 56 | final sharedPreferences = await SharedPreferences.getInstance(); 57 | sl.registerLazySingleton(() => sharedPreferences); 58 | sl.registerLazySingleton(() => http.Client()); 59 | sl.registerLazySingleton(() => DataConnectionChecker()); 60 | } 61 | -------------------------------------------------------------------------------- /lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'features/number_trivia/presentation/pages/number_trivia_page.dart'; 3 | import 'injection_container.dart' as di; 4 | 5 | void main() async { 6 | WidgetsFlutterBinding.ensureInitialized(); 7 | await di.init(); 8 | runApp(MyApp()); 9 | } 10 | 11 | class MyApp extends StatelessWidget { 12 | @override 13 | Widget build(BuildContext context) { 14 | return MaterialApp( 15 | title: 'Number Trivia', 16 | theme: ThemeData( 17 | primaryColor: Colors.green.shade800, 18 | accentColor: Colors.green.shade600, 19 | ), 20 | home: NumberTriviaPage(), 21 | ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | archive: 5 | dependency: transitive 6 | description: 7 | name: archive 8 | url: "https://pub.dartlang.org" 9 | source: hosted 10 | version: "2.0.11" 11 | args: 12 | dependency: transitive 13 | description: 14 | name: args 15 | url: "https://pub.dartlang.org" 16 | source: hosted 17 | version: "1.5.2" 18 | async: 19 | dependency: transitive 20 | description: 21 | name: async 22 | url: "https://pub.dartlang.org" 23 | source: hosted 24 | version: "2.4.0" 25 | bloc: 26 | dependency: transitive 27 | description: 28 | name: bloc 29 | url: "https://pub.dartlang.org" 30 | source: hosted 31 | version: "3.0.0" 32 | boolean_selector: 33 | dependency: transitive 34 | description: 35 | name: boolean_selector 36 | url: "https://pub.dartlang.org" 37 | source: hosted 38 | version: "1.0.5" 39 | charcode: 40 | dependency: transitive 41 | description: 42 | name: charcode 43 | url: "https://pub.dartlang.org" 44 | source: hosted 45 | version: "1.1.2" 46 | collection: 47 | dependency: transitive 48 | description: 49 | name: collection 50 | url: "https://pub.dartlang.org" 51 | source: hosted 52 | version: "1.14.11" 53 | convert: 54 | dependency: transitive 55 | description: 56 | name: convert 57 | url: "https://pub.dartlang.org" 58 | source: hosted 59 | version: "2.1.1" 60 | crypto: 61 | dependency: transitive 62 | description: 63 | name: crypto 64 | url: "https://pub.dartlang.org" 65 | source: hosted 66 | version: "2.1.3" 67 | dartz: 68 | dependency: "direct main" 69 | description: 70 | name: dartz 71 | url: "https://pub.dartlang.org" 72 | source: hosted 73 | version: "0.8.9" 74 | data_connection_checker: 75 | dependency: "direct main" 76 | description: 77 | name: data_connection_checker 78 | url: "https://pub.dartlang.org" 79 | source: hosted 80 | version: "0.3.4" 81 | equatable: 82 | dependency: "direct main" 83 | description: 84 | name: equatable 85 | url: "https://pub.dartlang.org" 86 | source: hosted 87 | version: "1.0.1" 88 | flutter: 89 | dependency: "direct main" 90 | description: flutter 91 | source: sdk 92 | version: "0.0.0" 93 | flutter_bloc: 94 | dependency: "direct main" 95 | description: 96 | name: flutter_bloc 97 | url: "https://pub.dartlang.org" 98 | source: hosted 99 | version: "3.0.0" 100 | flutter_test: 101 | dependency: "direct dev" 102 | description: flutter 103 | source: sdk 104 | version: "0.0.0" 105 | flutter_web_plugins: 106 | dependency: transitive 107 | description: flutter 108 | source: sdk 109 | version: "0.0.0" 110 | get_it: 111 | dependency: "direct main" 112 | description: 113 | name: get_it 114 | url: "https://pub.dartlang.org" 115 | source: hosted 116 | version: "3.1.0" 117 | http: 118 | dependency: "direct main" 119 | description: 120 | name: http 121 | url: "https://pub.dartlang.org" 122 | source: hosted 123 | version: "0.12.0+3" 124 | http_parser: 125 | dependency: transitive 126 | description: 127 | name: http_parser 128 | url: "https://pub.dartlang.org" 129 | source: hosted 130 | version: "3.1.3" 131 | image: 132 | dependency: transitive 133 | description: 134 | name: image 135 | url: "https://pub.dartlang.org" 136 | source: hosted 137 | version: "2.1.4" 138 | matcher: 139 | dependency: transitive 140 | description: 141 | name: matcher 142 | url: "https://pub.dartlang.org" 143 | source: hosted 144 | version: "0.12.6" 145 | meta: 146 | dependency: transitive 147 | description: 148 | name: meta 149 | url: "https://pub.dartlang.org" 150 | source: hosted 151 | version: "1.1.8" 152 | mockito: 153 | dependency: "direct dev" 154 | description: 155 | name: mockito 156 | url: "https://pub.dartlang.org" 157 | source: hosted 158 | version: "4.1.1" 159 | nested: 160 | dependency: transitive 161 | description: 162 | name: nested 163 | url: "https://pub.dartlang.org" 164 | source: hosted 165 | version: "0.0.4" 166 | path: 167 | dependency: transitive 168 | description: 169 | name: path 170 | url: "https://pub.dartlang.org" 171 | source: hosted 172 | version: "1.6.4" 173 | pedantic: 174 | dependency: transitive 175 | description: 176 | name: pedantic 177 | url: "https://pub.dartlang.org" 178 | source: hosted 179 | version: "1.8.0+1" 180 | petitparser: 181 | dependency: transitive 182 | description: 183 | name: petitparser 184 | url: "https://pub.dartlang.org" 185 | source: hosted 186 | version: "2.4.0" 187 | provider: 188 | dependency: transitive 189 | description: 190 | name: provider 191 | url: "https://pub.dartlang.org" 192 | source: hosted 193 | version: "4.0.1" 194 | quiver: 195 | dependency: transitive 196 | description: 197 | name: quiver 198 | url: "https://pub.dartlang.org" 199 | source: hosted 200 | version: "2.0.5" 201 | rxdart: 202 | dependency: transitive 203 | description: 204 | name: rxdart 205 | url: "https://pub.dartlang.org" 206 | source: hosted 207 | version: "0.23.1" 208 | shared_preferences: 209 | dependency: "direct main" 210 | description: 211 | name: shared_preferences 212 | url: "https://pub.dartlang.org" 213 | source: hosted 214 | version: "0.5.6" 215 | shared_preferences_macos: 216 | dependency: transitive 217 | description: 218 | name: shared_preferences_macos 219 | url: "https://pub.dartlang.org" 220 | source: hosted 221 | version: "0.0.1+3" 222 | shared_preferences_platform_interface: 223 | dependency: transitive 224 | description: 225 | name: shared_preferences_platform_interface 226 | url: "https://pub.dartlang.org" 227 | source: hosted 228 | version: "1.0.1" 229 | shared_preferences_web: 230 | dependency: transitive 231 | description: 232 | name: shared_preferences_web 233 | url: "https://pub.dartlang.org" 234 | source: hosted 235 | version: "0.1.2+2" 236 | sky_engine: 237 | dependency: transitive 238 | description: flutter 239 | source: sdk 240 | version: "0.0.99" 241 | source_span: 242 | dependency: transitive 243 | description: 244 | name: source_span 245 | url: "https://pub.dartlang.org" 246 | source: hosted 247 | version: "1.5.5" 248 | stack_trace: 249 | dependency: transitive 250 | description: 251 | name: stack_trace 252 | url: "https://pub.dartlang.org" 253 | source: hosted 254 | version: "1.9.3" 255 | stream_channel: 256 | dependency: transitive 257 | description: 258 | name: stream_channel 259 | url: "https://pub.dartlang.org" 260 | source: hosted 261 | version: "2.0.0" 262 | string_scanner: 263 | dependency: transitive 264 | description: 265 | name: string_scanner 266 | url: "https://pub.dartlang.org" 267 | source: hosted 268 | version: "1.0.5" 269 | term_glyph: 270 | dependency: transitive 271 | description: 272 | name: term_glyph 273 | url: "https://pub.dartlang.org" 274 | source: hosted 275 | version: "1.1.0" 276 | test_api: 277 | dependency: transitive 278 | description: 279 | name: test_api 280 | url: "https://pub.dartlang.org" 281 | source: hosted 282 | version: "0.2.11" 283 | typed_data: 284 | dependency: transitive 285 | description: 286 | name: typed_data 287 | url: "https://pub.dartlang.org" 288 | source: hosted 289 | version: "1.1.6" 290 | vector_math: 291 | dependency: transitive 292 | description: 293 | name: vector_math 294 | url: "https://pub.dartlang.org" 295 | source: hosted 296 | version: "2.0.8" 297 | xml: 298 | dependency: transitive 299 | description: 300 | name: xml 301 | url: "https://pub.dartlang.org" 302 | source: hosted 303 | version: "3.5.0" 304 | sdks: 305 | dart: ">=2.6.0 <3.0.0" 306 | flutter: ">=1.12.13+hotfix.4 <2.0.0" 307 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: clean_architecture_tdd_course 2 | description: TDD Clean Architecture for Flutter 3 | 4 | version: 1.0.0+1 5 | 6 | environment: 7 | sdk: '>=2.6.0 <3.0.0' 8 | 9 | dependencies: 10 | flutter: 11 | sdk: flutter 12 | # Service locator 13 | get_it: ^3.1.0 14 | # Bloc for state management 15 | flutter_bloc: ^3.0.0 16 | # Value equality 17 | equatable: ^1.0.1 18 | # Functional programming thingies 19 | dartz: ^0.8.9 20 | # Remote API 21 | data_connection_checker: ^0.3.4 22 | http: ^0.12.0+3 23 | # Local cache 24 | shared_preferences: ^0.5.6 25 | 26 | dev_dependencies: 27 | flutter_test: 28 | sdk: flutter 29 | mockito: ^4.1.1 30 | 31 | flutter: 32 | uses-material-design: true 33 | -------------------------------------------------------------------------------- /test/core/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/test/core/.gitkeep -------------------------------------------------------------------------------- /test/core/error/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/test/core/error/.gitkeep -------------------------------------------------------------------------------- /test/core/network/network_info_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:clean_architecture_tdd_course/core/network/network_info.dart'; 2 | import 'package:mockito/mockito.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | import 'package:data_connection_checker/data_connection_checker.dart'; 5 | 6 | class MockDataConnectionChecker extends Mock implements DataConnectionChecker {} 7 | 8 | void main() { 9 | NetworkInfoImpl networkInfo; 10 | MockDataConnectionChecker mockDataConnectionChecker; 11 | 12 | setUp(() { 13 | mockDataConnectionChecker = MockDataConnectionChecker(); 14 | networkInfo = NetworkInfoImpl(mockDataConnectionChecker); 15 | }); 16 | 17 | group('isConnected', () { 18 | test( 19 | 'should forward the call to DataConnectionChecker.hasConnection', 20 | () async { 21 | // arrange 22 | final tHasConnectionFuture = Future.value(true); 23 | 24 | when(mockDataConnectionChecker.hasConnection) 25 | .thenAnswer((_) => tHasConnectionFuture); 26 | // act 27 | final result = networkInfo.isConnected; 28 | // assert 29 | verify(mockDataConnectionChecker.hasConnection); 30 | expect(result, tHasConnectionFuture); 31 | }, 32 | ); 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /test/core/usecases/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/test/core/usecases/.gitkeep -------------------------------------------------------------------------------- /test/core/util/input_converter_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:clean_architecture_tdd_course/core/util/input_converter.dart'; 2 | import 'package:dartz/dartz.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | 5 | void main() { 6 | InputConverter inputConverter; 7 | 8 | setUp(() { 9 | inputConverter = InputConverter(); 10 | }); 11 | 12 | group('stringToUnsignedInt', () { 13 | test( 14 | 'should return an integer when the string represents an unsigned integer', 15 | () async { 16 | // arrange 17 | final str = '123'; 18 | // act 19 | final result = inputConverter.stringToUnsignedInteger(str); 20 | // assert 21 | expect(result, Right(123)); 22 | }, 23 | ); 24 | 25 | test( 26 | 'should return a Failure when the string is not an integer', 27 | () async { 28 | // arrange 29 | final str = 'abc'; 30 | // act 31 | final result = inputConverter.stringToUnsignedInteger(str); 32 | // assert 33 | expect(result, Left(InvalidInputFailure())); 34 | }, 35 | ); 36 | 37 | test( 38 | 'should return a Failure when the string is a negative integer', 39 | () async { 40 | // arrange 41 | final str = '-123'; 42 | // act 43 | final result = inputConverter.stringToUnsignedInteger(str); 44 | // assert 45 | expect(result, Left(InvalidInputFailure())); 46 | }, 47 | ); 48 | }); 49 | } 50 | -------------------------------------------------------------------------------- /test/features/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/test/features/.gitkeep -------------------------------------------------------------------------------- /test/features/number_trivia/data/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/test/features/number_trivia/data/.gitkeep -------------------------------------------------------------------------------- /test/features/number_trivia/data/datasources/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/test/features/number_trivia/data/datasources/.gitkeep -------------------------------------------------------------------------------- /test/features/number_trivia/data/datasources/number_trivia_local_data_source_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:clean_architecture_tdd_course/core/error/exceptions.dart'; 4 | import 'package:clean_architecture_tdd_course/features/number_trivia/data/datasources/number_trivia_local_data_source.dart'; 5 | import 'package:clean_architecture_tdd_course/features/number_trivia/data/models/number_trivia_model.dart'; 6 | import 'package:mockito/mockito.dart'; 7 | import 'package:flutter_test/flutter_test.dart'; 8 | import 'package:shared_preferences/shared_preferences.dart'; 9 | import 'package:matcher/matcher.dart'; 10 | 11 | import '../../../../fixtures/fixture_reader.dart'; 12 | 13 | class MockSharedPreferences extends Mock implements SharedPreferences {} 14 | 15 | void main() { 16 | NumberTriviaLocalDataSourceImpl dataSource; 17 | MockSharedPreferences mockSharedPreferences; 18 | 19 | setUp(() { 20 | mockSharedPreferences = MockSharedPreferences(); 21 | dataSource = NumberTriviaLocalDataSourceImpl( 22 | sharedPreferences: mockSharedPreferences, 23 | ); 24 | }); 25 | 26 | group('getLastNumberTrivia', () { 27 | final tNumberTriviaModel = 28 | NumberTriviaModel.fromJson(json.decode(fixture('trivia_cached.json'))); 29 | 30 | test( 31 | 'should return NumberTrivia from SharedPreferences when there is one in the cache', 32 | () async { 33 | // arrange 34 | when(mockSharedPreferences.getString(any)) 35 | .thenReturn(fixture('trivia_cached.json')); 36 | // act 37 | final result = await dataSource.getLastNumberTrivia(); 38 | // assert 39 | verify(mockSharedPreferences.getString(CACHED_NUMBER_TRIVIA)); 40 | expect(result, equals(tNumberTriviaModel)); 41 | }, 42 | ); 43 | 44 | test( 45 | 'should throw a CacheExeption when there is not a cached value', 46 | () async { 47 | // arrange 48 | when(mockSharedPreferences.getString(any)).thenReturn(null); 49 | // act 50 | final call = dataSource.getLastNumberTrivia; 51 | // assert 52 | expect(() => call(), throwsA(TypeMatcher())); 53 | }, 54 | ); 55 | }); 56 | 57 | group('cacheNumberTrivia', () { 58 | final tNumberTriviaModel = 59 | NumberTriviaModel(number: 1, text: 'test trivia'); 60 | 61 | test( 62 | 'should call SharedPreferences to cache the data', 63 | () async { 64 | // act 65 | dataSource.cacheNumberTrivia(tNumberTriviaModel); 66 | // assert 67 | final expectedJsonString = json.encode(tNumberTriviaModel.toJson()); 68 | verify(mockSharedPreferences.setString( 69 | CACHED_NUMBER_TRIVIA, 70 | expectedJsonString, 71 | )); 72 | }, 73 | ); 74 | }); 75 | } 76 | -------------------------------------------------------------------------------- /test/features/number_trivia/data/datasources/number_trivia_remote_data_source_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:clean_architecture_tdd_course/core/error/exceptions.dart'; 4 | import 'package:clean_architecture_tdd_course/features/number_trivia/data/datasources/number_trivia_remote_data_source.dart'; 5 | import 'package:clean_architecture_tdd_course/features/number_trivia/data/models/number_trivia_model.dart'; 6 | import 'package:mockito/mockito.dart'; 7 | import 'package:flutter_test/flutter_test.dart'; 8 | import 'package:matcher/matcher.dart'; 9 | import 'package:http/http.dart' as http; 10 | 11 | import '../../../../fixtures/fixture_reader.dart'; 12 | 13 | class MockHttpClient extends Mock implements http.Client {} 14 | 15 | void main() { 16 | NumberTriviaRemoteDataSourceImpl dataSource; 17 | MockHttpClient mockHttpClient; 18 | 19 | setUp(() { 20 | mockHttpClient = MockHttpClient(); 21 | dataSource = NumberTriviaRemoteDataSourceImpl(client: mockHttpClient); 22 | }); 23 | 24 | void setUpMockHttpClientSuccess200() { 25 | when(mockHttpClient.get(any, headers: anyNamed('headers'))) 26 | .thenAnswer((_) async => http.Response(fixture('trivia.json'), 200)); 27 | } 28 | 29 | void setUpMockHttpClientFailure404() { 30 | when(mockHttpClient.get(any, headers: anyNamed('headers'))) 31 | .thenAnswer((_) async => http.Response('Something went wrong', 404)); 32 | } 33 | 34 | group('getConcreteNumberTrivia', () { 35 | final tNumber = 1; 36 | final tNumberTriviaModel = 37 | NumberTriviaModel.fromJson(json.decode(fixture('trivia.json'))); 38 | 39 | test( 40 | '''should perform a GET request on a URL with number 41 | being the endpoint and with application/json header''', 42 | () async { 43 | // arrange 44 | setUpMockHttpClientSuccess200(); 45 | // act 46 | dataSource.getConcreteNumberTrivia(tNumber); 47 | // assert 48 | verify(mockHttpClient.get( 49 | 'http://numbersapi.com/$tNumber', 50 | headers: { 51 | 'Content-Type': 'application/json', 52 | }, 53 | )); 54 | }, 55 | ); 56 | 57 | test( 58 | 'should return NumberTrivia when the response code is 200 (success)', 59 | () async { 60 | // arrange 61 | setUpMockHttpClientSuccess200(); 62 | // act 63 | final result = await dataSource.getConcreteNumberTrivia(tNumber); 64 | // assert 65 | expect(result, equals(tNumberTriviaModel)); 66 | }, 67 | ); 68 | 69 | test( 70 | 'should throw a ServerException when the response code is 404 or other', 71 | () async { 72 | // arrange 73 | setUpMockHttpClientFailure404(); 74 | // act 75 | final call = dataSource.getConcreteNumberTrivia; 76 | // assert 77 | expect(() => call(tNumber), throwsA(TypeMatcher())); 78 | }, 79 | ); 80 | }); 81 | 82 | group('getRandomNumberTrivia', () { 83 | final tNumberTriviaModel = 84 | NumberTriviaModel.fromJson(json.decode(fixture('trivia.json'))); 85 | 86 | test( 87 | '''should perform a GET request on a URL with number 88 | being the endpoint and with application/json header''', 89 | () async { 90 | // arrange 91 | setUpMockHttpClientSuccess200(); 92 | // act 93 | dataSource.getRandomNumberTrivia(); 94 | // assert 95 | verify(mockHttpClient.get( 96 | 'http://numbersapi.com/random', 97 | headers: { 98 | 'Content-Type': 'application/json', 99 | }, 100 | )); 101 | }, 102 | ); 103 | 104 | test( 105 | 'should return NumberTrivia when the response code is 200 (success)', 106 | () async { 107 | // arrange 108 | setUpMockHttpClientSuccess200(); 109 | // act 110 | final result = await dataSource.getRandomNumberTrivia(); 111 | // assert 112 | expect(result, equals(tNumberTriviaModel)); 113 | }, 114 | ); 115 | 116 | test( 117 | 'should throw a ServerException when the response code is 404 or other', 118 | () async { 119 | // arrange 120 | setUpMockHttpClientFailure404(); 121 | // act 122 | final call = dataSource.getRandomNumberTrivia; 123 | // assert 124 | expect(() => call(), throwsA(TypeMatcher())); 125 | }, 126 | ); 127 | }); 128 | } 129 | -------------------------------------------------------------------------------- /test/features/number_trivia/data/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/test/features/number_trivia/data/models/.gitkeep -------------------------------------------------------------------------------- /test/features/number_trivia/data/models/number_trivia_model_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:clean_architecture_tdd_course/features/number_trivia/data/models/number_trivia_model.dart'; 4 | import 'package:clean_architecture_tdd_course/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 | final tNumberTriviaModel = NumberTriviaModel(number: 1, text: 'Test Text'); 11 | 12 | test( 13 | 'should be a subclass of NumberTrivia entity', 14 | () async { 15 | // assert 16 | expect(tNumberTriviaModel, isA()); 17 | }, 18 | ); 19 | 20 | group('fromJson', () { 21 | test( 22 | 'should return a valid model when the JSON number is an integer', 23 | () async { 24 | // arrange 25 | final Map jsonMap = 26 | json.decode(fixture('trivia.json')); 27 | // act 28 | final result = NumberTriviaModel.fromJson(jsonMap); 29 | // assert 30 | expect(result, tNumberTriviaModel); 31 | }, 32 | ); 33 | 34 | test( 35 | 'should return a valid model when the JSON number is regarded as a double', 36 | () async { 37 | // arrange 38 | final Map jsonMap = 39 | json.decode(fixture('trivia_double.json')); 40 | // act 41 | final result = NumberTriviaModel.fromJson(jsonMap); 42 | // assert 43 | expect(result, tNumberTriviaModel); 44 | }, 45 | ); 46 | }); 47 | 48 | group('toJson', () { 49 | test( 50 | 'should return a JSON map containing the proper data', 51 | () async { 52 | // act 53 | final result = tNumberTriviaModel.toJson(); 54 | // assert 55 | final expectedMap = { 56 | "text": "Test Text", 57 | "number": 1, 58 | }; 59 | expect(result, expectedMap); 60 | }, 61 | ); 62 | }); 63 | } 64 | -------------------------------------------------------------------------------- /test/features/number_trivia/data/repositories/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/test/features/number_trivia/data/repositories/.gitkeep -------------------------------------------------------------------------------- /test/features/number_trivia/data/repositories/number_trivia_repository_impl_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:clean_architecture_tdd_course/core/error/exceptions.dart'; 2 | import 'package:clean_architecture_tdd_course/core/error/failures.dart'; 3 | import 'package:clean_architecture_tdd_course/core/network/network_info.dart'; 4 | import 'package:clean_architecture_tdd_course/features/number_trivia/data/datasources/number_trivia_local_data_source.dart'; 5 | import 'package:clean_architecture_tdd_course/features/number_trivia/data/datasources/number_trivia_remote_data_source.dart'; 6 | import 'package:clean_architecture_tdd_course/features/number_trivia/data/models/number_trivia_model.dart'; 7 | import 'package:clean_architecture_tdd_course/features/number_trivia/data/repositories/number_trivia_repository_impl.dart'; 8 | import 'package:clean_architecture_tdd_course/features/number_trivia/domain/entities/number_trivia.dart'; 9 | import 'package:dartz/dartz.dart'; 10 | import 'package:mockito/mockito.dart'; 11 | import 'package:flutter_test/flutter_test.dart'; 12 | 13 | class MockRemoteDataSource extends Mock 14 | implements NumberTriviaRemoteDataSource {} 15 | 16 | class MockLocalDataSource extends Mock implements NumberTriviaLocalDataSource {} 17 | 18 | class MockNetworkInfo extends Mock implements NetworkInfo {} 19 | 20 | void main() { 21 | NumberTriviaRepositoryImpl repository; 22 | MockRemoteDataSource mockRemoteDataSource; 23 | MockLocalDataSource mockLocalDataSource; 24 | MockNetworkInfo mockNetworkInfo; 25 | 26 | setUp(() { 27 | mockRemoteDataSource = MockRemoteDataSource(); 28 | mockLocalDataSource = MockLocalDataSource(); 29 | mockNetworkInfo = MockNetworkInfo(); 30 | repository = NumberTriviaRepositoryImpl( 31 | remoteDataSource: mockRemoteDataSource, 32 | localDataSource: mockLocalDataSource, 33 | networkInfo: mockNetworkInfo, 34 | ); 35 | }); 36 | 37 | void runTestsOnline(Function body) { 38 | group('device is online', () { 39 | setUp(() { 40 | when(mockNetworkInfo.isConnected).thenAnswer((_) async => true); 41 | }); 42 | 43 | body(); 44 | }); 45 | } 46 | 47 | void runTestsOffline(Function body) { 48 | group('device is offline', () { 49 | setUp(() { 50 | when(mockNetworkInfo.isConnected).thenAnswer((_) async => false); 51 | }); 52 | 53 | body(); 54 | }); 55 | } 56 | 57 | group('getConcreteNumberTrivia', () { 58 | final tNumber = 1; 59 | final tNumberTriviaModel = 60 | NumberTriviaModel(number: tNumber, text: 'test trivia'); 61 | final NumberTrivia tNumberTrivia = tNumberTriviaModel; 62 | 63 | test( 64 | 'should check if the device is online', 65 | () async { 66 | // arrange 67 | when(mockNetworkInfo.isConnected).thenAnswer((_) async => true); 68 | // act 69 | repository.getConcreteNumberTrivia(tNumber); 70 | // assert 71 | verify(mockNetworkInfo.isConnected); 72 | }, 73 | ); 74 | 75 | runTestsOnline(() { 76 | test( 77 | 'should return remote data when the call to remote data source is successful', 78 | () async { 79 | // arrange 80 | when(mockRemoteDataSource.getConcreteNumberTrivia(any)) 81 | .thenAnswer((_) async => tNumberTriviaModel); 82 | // act 83 | final result = await repository.getConcreteNumberTrivia(tNumber); 84 | // assert 85 | verify(mockRemoteDataSource.getConcreteNumberTrivia(tNumber)); 86 | expect(result, equals(Right(tNumberTrivia))); 87 | }, 88 | ); 89 | 90 | test( 91 | 'should cache the data locally when the call to remote data source is successful', 92 | () async { 93 | // arrange 94 | when(mockRemoteDataSource.getConcreteNumberTrivia(any)) 95 | .thenAnswer((_) async => tNumberTriviaModel); 96 | // act 97 | await repository.getConcreteNumberTrivia(tNumber); 98 | // assert 99 | verify(mockRemoteDataSource.getConcreteNumberTrivia(tNumber)); 100 | verify(mockLocalDataSource.cacheNumberTrivia(tNumberTriviaModel)); 101 | }, 102 | ); 103 | 104 | test( 105 | 'should return server failure when the call to remote data source is unsuccessful', 106 | () async { 107 | // arrange 108 | when(mockRemoteDataSource.getConcreteNumberTrivia(any)) 109 | .thenThrow(ServerException()); 110 | // act 111 | final result = await repository.getConcreteNumberTrivia(tNumber); 112 | // assert 113 | verify(mockRemoteDataSource.getConcreteNumberTrivia(tNumber)); 114 | verifyZeroInteractions(mockLocalDataSource); 115 | expect(result, equals(Left(ServerFailure()))); 116 | }, 117 | ); 118 | }); 119 | 120 | runTestsOffline(() { 121 | test( 122 | 'should return last locally cached data when the cached data is present', 123 | () async { 124 | // arrange 125 | when(mockLocalDataSource.getLastNumberTrivia()) 126 | .thenAnswer((_) async => tNumberTriviaModel); 127 | // act 128 | final result = await repository.getConcreteNumberTrivia(tNumber); 129 | // assert 130 | verifyZeroInteractions(mockRemoteDataSource); 131 | verify(mockLocalDataSource.getLastNumberTrivia()); 132 | expect(result, equals(Right(tNumberTrivia))); 133 | }, 134 | ); 135 | 136 | test( 137 | 'should return CacheFailure when there is no cached data present', 138 | () async { 139 | // arrange 140 | when(mockLocalDataSource.getLastNumberTrivia()) 141 | .thenThrow(CacheException()); 142 | // act 143 | final result = await repository.getConcreteNumberTrivia(tNumber); 144 | // assert 145 | verifyZeroInteractions(mockRemoteDataSource); 146 | verify(mockLocalDataSource.getLastNumberTrivia()); 147 | expect(result, equals(Left(CacheFailure()))); 148 | }, 149 | ); 150 | }); 151 | }); 152 | 153 | group('getRandomNumberTrivia', () { 154 | final tNumberTriviaModel = 155 | NumberTriviaModel(number: 123, text: 'test trivia'); 156 | final NumberTrivia tNumberTrivia = tNumberTriviaModel; 157 | 158 | test( 159 | 'should check if the device is online', 160 | () async { 161 | // arrange 162 | when(mockNetworkInfo.isConnected).thenAnswer((_) async => true); 163 | // act 164 | repository.getRandomNumberTrivia(); 165 | // assert 166 | verify(mockNetworkInfo.isConnected); 167 | }, 168 | ); 169 | 170 | runTestsOnline(() { 171 | test( 172 | 'should return remote data when the call to remote data source is successful', 173 | () async { 174 | // arrange 175 | when(mockRemoteDataSource.getRandomNumberTrivia()) 176 | .thenAnswer((_) async => tNumberTriviaModel); 177 | // act 178 | final result = await repository.getRandomNumberTrivia(); 179 | // assert 180 | verify(mockRemoteDataSource.getRandomNumberTrivia()); 181 | expect(result, equals(Right(tNumberTrivia))); 182 | }, 183 | ); 184 | 185 | test( 186 | 'should cache the data locally when the call to remote data source is successful', 187 | () async { 188 | // arrange 189 | when(mockRemoteDataSource.getRandomNumberTrivia()) 190 | .thenAnswer((_) async => tNumberTriviaModel); 191 | // act 192 | await repository.getRandomNumberTrivia(); 193 | // assert 194 | verify(mockRemoteDataSource.getRandomNumberTrivia()); 195 | verify(mockLocalDataSource.cacheNumberTrivia(tNumberTriviaModel)); 196 | }, 197 | ); 198 | 199 | test( 200 | 'should return server failure when the call to remote data source is unsuccessful', 201 | () async { 202 | // arrange 203 | when(mockRemoteDataSource.getRandomNumberTrivia()) 204 | .thenThrow(ServerException()); 205 | // act 206 | final result = await repository.getRandomNumberTrivia(); 207 | // assert 208 | verify(mockRemoteDataSource.getRandomNumberTrivia()); 209 | verifyZeroInteractions(mockLocalDataSource); 210 | expect(result, equals(Left(ServerFailure()))); 211 | }, 212 | ); 213 | }); 214 | 215 | runTestsOffline(() { 216 | test( 217 | 'should return last locally cached data when the cached data is present', 218 | () async { 219 | // arrange 220 | when(mockLocalDataSource.getLastNumberTrivia()) 221 | .thenAnswer((_) async => tNumberTriviaModel); 222 | // act 223 | final result = await repository.getRandomNumberTrivia(); 224 | // assert 225 | verifyZeroInteractions(mockRemoteDataSource); 226 | verify(mockLocalDataSource.getLastNumberTrivia()); 227 | expect(result, equals(Right(tNumberTrivia))); 228 | }, 229 | ); 230 | 231 | test( 232 | 'should return CacheFailure when there is no cached data present', 233 | () async { 234 | // arrange 235 | when(mockLocalDataSource.getLastNumberTrivia()) 236 | .thenThrow(CacheException()); 237 | // act 238 | final result = await repository.getRandomNumberTrivia(); 239 | // assert 240 | verifyZeroInteractions(mockRemoteDataSource); 241 | verify(mockLocalDataSource.getLastNumberTrivia()); 242 | expect(result, equals(Left(CacheFailure()))); 243 | }, 244 | ); 245 | }); 246 | }); 247 | } 248 | -------------------------------------------------------------------------------- /test/features/number_trivia/domain/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/test/features/number_trivia/domain/.gitkeep -------------------------------------------------------------------------------- /test/features/number_trivia/domain/entities/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/test/features/number_trivia/domain/entities/.gitkeep -------------------------------------------------------------------------------- /test/features/number_trivia/domain/repositories/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/test/features/number_trivia/domain/repositories/.gitkeep -------------------------------------------------------------------------------- /test/features/number_trivia/domain/usecases/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/test/features/number_trivia/domain/usecases/.gitkeep -------------------------------------------------------------------------------- /test/features/number_trivia/domain/usecases/get_concrete_number_trivia_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:clean_architecture_tdd_course/features/number_trivia/domain/entities/number_trivia.dart'; 2 | import 'package:clean_architecture_tdd_course/features/number_trivia/domain/repositories/number_trivia_repository.dart'; 3 | import 'package:clean_architecture_tdd_course/features/number_trivia/domain/usecases/get_concrete_number_trivia.dart'; 4 | import 'package:dartz/dartz.dart'; 5 | import 'package:mockito/mockito.dart'; 6 | import 'package:flutter_test/flutter_test.dart'; 7 | 8 | class MockNumberTriviaRepository extends Mock 9 | implements NumberTriviaRepository {} 10 | 11 | void main() { 12 | GetConcreteNumberTrivia usecase; 13 | MockNumberTriviaRepository mockNumberTriviaRepository; 14 | 15 | setUp(() { 16 | mockNumberTriviaRepository = MockNumberTriviaRepository(); 17 | usecase = GetConcreteNumberTrivia(mockNumberTriviaRepository); 18 | }); 19 | 20 | final tNumber = 1; 21 | final tNumberTrivia = NumberTrivia(number: 1, text: 'test'); 22 | 23 | test( 24 | 'should get trivia for the number from the repository', 25 | () async { 26 | // arrange 27 | when(mockNumberTriviaRepository.getConcreteNumberTrivia(any)) 28 | .thenAnswer((_) async => Right(tNumberTrivia)); 29 | // act 30 | final result = await usecase(Params(number: tNumber)); 31 | // assert 32 | expect(result, Right(tNumberTrivia)); 33 | verify(mockNumberTriviaRepository.getConcreteNumberTrivia(tNumber)); 34 | verifyNoMoreInteractions(mockNumberTriviaRepository); 35 | }, 36 | ); 37 | } 38 | -------------------------------------------------------------------------------- /test/features/number_trivia/domain/usecases/get_random_number_trivia_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:clean_architecture_tdd_course/core/usecases/usecase.dart'; 2 | import 'package:clean_architecture_tdd_course/features/number_trivia/domain/entities/number_trivia.dart'; 3 | import 'package:clean_architecture_tdd_course/features/number_trivia/domain/repositories/number_trivia_repository.dart'; 4 | import 'package:clean_architecture_tdd_course/features/number_trivia/domain/usecases/get_concrete_number_trivia.dart'; 5 | import 'package:clean_architecture_tdd_course/features/number_trivia/domain/usecases/get_random_number_trivia.dart'; 6 | import 'package:dartz/dartz.dart'; 7 | import 'package:mockito/mockito.dart'; 8 | import 'package:flutter_test/flutter_test.dart'; 9 | 10 | class MockNumberTriviaRepository extends Mock 11 | implements NumberTriviaRepository {} 12 | 13 | void main() { 14 | GetRandomNumberTrivia usecase; 15 | MockNumberTriviaRepository mockNumberTriviaRepository; 16 | 17 | setUp(() { 18 | mockNumberTriviaRepository = MockNumberTriviaRepository(); 19 | usecase = GetRandomNumberTrivia(mockNumberTriviaRepository); 20 | }); 21 | 22 | final tNumberTrivia = NumberTrivia(number: 1, text: 'test'); 23 | 24 | test( 25 | 'should get trivia from the repository', 26 | () async { 27 | // arrange 28 | when(mockNumberTriviaRepository.getRandomNumberTrivia()) 29 | .thenAnswer((_) async => Right(tNumberTrivia)); 30 | // act 31 | final result = await usecase(NoParams()); 32 | // assert 33 | expect(result, Right(tNumberTrivia)); 34 | verify(mockNumberTriviaRepository.getRandomNumberTrivia()); 35 | verifyNoMoreInteractions(mockNumberTriviaRepository); 36 | }, 37 | ); 38 | } 39 | -------------------------------------------------------------------------------- /test/features/number_trivia/presentation/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/test/features/number_trivia/presentation/.gitkeep -------------------------------------------------------------------------------- /test/features/number_trivia/presentation/bloc/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/test/features/number_trivia/presentation/bloc/.gitkeep -------------------------------------------------------------------------------- /test/features/number_trivia/presentation/bloc/number_trivia_bloc_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:clean_architecture_tdd_course/core/error/failures.dart'; 2 | import 'package:clean_architecture_tdd_course/core/usecases/usecase.dart'; 3 | import 'package:clean_architecture_tdd_course/core/util/input_converter.dart'; 4 | import 'package:clean_architecture_tdd_course/features/number_trivia/domain/entities/number_trivia.dart'; 5 | import 'package:clean_architecture_tdd_course/features/number_trivia/domain/usecases/get_concrete_number_trivia.dart'; 6 | import 'package:clean_architecture_tdd_course/features/number_trivia/domain/usecases/get_random_number_trivia.dart'; 7 | import 'package:clean_architecture_tdd_course/features/number_trivia/presentation/bloc/bloc.dart'; 8 | import 'package:dartz/dartz.dart'; 9 | import 'package:mockito/mockito.dart'; 10 | import 'package:flutter_test/flutter_test.dart'; 11 | 12 | class MockGetConcreteNumberTrivia extends Mock 13 | implements GetConcreteNumberTrivia {} 14 | 15 | class MockGetRandomNumberTrivia extends Mock implements GetRandomNumberTrivia {} 16 | 17 | class MockInputConverter extends Mock implements InputConverter {} 18 | 19 | void main() { 20 | NumberTriviaBloc bloc; 21 | MockGetConcreteNumberTrivia mockGetConcreteNumberTrivia; 22 | MockGetRandomNumberTrivia mockGetRandomNumberTrivia; 23 | MockInputConverter mockInputConverter; 24 | 25 | setUp(() { 26 | mockGetConcreteNumberTrivia = MockGetConcreteNumberTrivia(); 27 | mockGetRandomNumberTrivia = MockGetRandomNumberTrivia(); 28 | mockInputConverter = MockInputConverter(); 29 | 30 | bloc = NumberTriviaBloc( 31 | concrete: mockGetConcreteNumberTrivia, 32 | random: mockGetRandomNumberTrivia, 33 | inputConverter: mockInputConverter, 34 | ); 35 | }); 36 | 37 | test('initialState should be Empty', () { 38 | // assert 39 | expect(bloc.initialState, equals(Empty())); 40 | }); 41 | 42 | group('GetTriviaForConcreteNumber', () { 43 | final tNumberString = '1'; 44 | final tNumberParsed = 1; 45 | final tNumberTrivia = NumberTrivia(number: 1, text: 'test trivia'); 46 | 47 | void setUpMockInputConverterSuccess() => 48 | when(mockInputConverter.stringToUnsignedInteger(any)) 49 | .thenReturn(Right(tNumberParsed)); 50 | 51 | test( 52 | 'should call the InputConverter to validate and convert the string to an unsigned integer', 53 | () async { 54 | // arrange 55 | setUpMockInputConverterSuccess(); 56 | // act 57 | bloc.add(GetTriviaForConcreteNumber(tNumberString)); 58 | await untilCalled(mockInputConverter.stringToUnsignedInteger(any)); 59 | // assert 60 | verify(mockInputConverter.stringToUnsignedInteger(tNumberString)); 61 | }, 62 | ); 63 | 64 | test( 65 | 'should emit [Error] when the input is invalid', 66 | () async { 67 | // arrange 68 | when(mockInputConverter.stringToUnsignedInteger(any)) 69 | .thenReturn(Left(InvalidInputFailure())); 70 | // assert later 71 | final expected = [ 72 | Empty(), 73 | Error(message: INVALID_INPUT_FAILURE_MESSAGE), 74 | ]; 75 | expectLater(bloc, emitsInOrder(expected)); 76 | // act 77 | bloc.add(GetTriviaForConcreteNumber(tNumberString)); 78 | }, 79 | ); 80 | 81 | test( 82 | 'should get data from the concrete use case', 83 | () async { 84 | // arrange 85 | setUpMockInputConverterSuccess(); 86 | when(mockGetConcreteNumberTrivia(any)) 87 | .thenAnswer((_) async => Right(tNumberTrivia)); 88 | // act 89 | bloc.add(GetTriviaForConcreteNumber(tNumberString)); 90 | await untilCalled(mockGetConcreteNumberTrivia(any)); 91 | // assert 92 | verify(mockGetConcreteNumberTrivia(Params(number: tNumberParsed))); 93 | }, 94 | ); 95 | 96 | test( 97 | 'should emit [Loading, Loaded] when data is gotten successfully', 98 | () async { 99 | // arrange 100 | setUpMockInputConverterSuccess(); 101 | when(mockGetConcreteNumberTrivia(any)) 102 | .thenAnswer((_) async => Right(tNumberTrivia)); 103 | // assert later 104 | final expected = [ 105 | Empty(), 106 | Loading(), 107 | Loaded(trivia: tNumberTrivia), 108 | ]; 109 | expectLater(bloc, emitsInOrder(expected)); 110 | // act 111 | bloc.add(GetTriviaForConcreteNumber(tNumberString)); 112 | }, 113 | ); 114 | 115 | test( 116 | 'should emit [Loading, Error] when getting data fails', 117 | () async { 118 | // arrange 119 | setUpMockInputConverterSuccess(); 120 | when(mockGetConcreteNumberTrivia(any)) 121 | .thenAnswer((_) async => Left(ServerFailure())); 122 | // assert later 123 | final expected = [ 124 | Empty(), 125 | Loading(), 126 | Error(message: SERVER_FAILURE_MESSAGE), 127 | ]; 128 | expectLater(bloc, emitsInOrder(expected)); 129 | // act 130 | bloc.add(GetTriviaForConcreteNumber(tNumberString)); 131 | }, 132 | ); 133 | 134 | test( 135 | 'should emit [Loading, Error] with a proper message for the error when getting data fails', 136 | () async { 137 | // arrange 138 | setUpMockInputConverterSuccess(); 139 | when(mockGetConcreteNumberTrivia(any)) 140 | .thenAnswer((_) async => Left(CacheFailure())); 141 | // assert later 142 | final expected = [ 143 | Empty(), 144 | Loading(), 145 | Error(message: CACHE_FAILURE_MESSAGE), 146 | ]; 147 | expectLater(bloc, emitsInOrder(expected)); 148 | // act 149 | bloc.add(GetTriviaForConcreteNumber(tNumberString)); 150 | }, 151 | ); 152 | }); 153 | 154 | group('GetTriviaForRandomNumber', () { 155 | final tNumberTrivia = NumberTrivia(number: 1, text: 'test trivia'); 156 | 157 | test( 158 | 'should get data from the random use case', 159 | () async { 160 | // arrange 161 | when(mockGetRandomNumberTrivia(any)) 162 | .thenAnswer((_) async => Right(tNumberTrivia)); 163 | // act 164 | bloc.add(GetTriviaForRandomNumber()); 165 | await untilCalled(mockGetRandomNumberTrivia(any)); 166 | // assert 167 | verify(mockGetRandomNumberTrivia(NoParams())); 168 | }, 169 | ); 170 | 171 | test( 172 | 'should emit [Loading, Loaded] when data is gotten successfully', 173 | () async { 174 | // arrange 175 | when(mockGetRandomNumberTrivia(any)) 176 | .thenAnswer((_) async => Right(tNumberTrivia)); 177 | // assert later 178 | final expected = [ 179 | Empty(), 180 | Loading(), 181 | Loaded(trivia: tNumberTrivia), 182 | ]; 183 | expectLater(bloc, emitsInOrder(expected)); 184 | // act 185 | bloc.add(GetTriviaForRandomNumber()); 186 | }, 187 | ); 188 | 189 | test( 190 | 'should emit [Loading, Error] when getting data fails', 191 | () async { 192 | // arrange 193 | when(mockGetRandomNumberTrivia(any)) 194 | .thenAnswer((_) async => Left(ServerFailure())); 195 | // assert later 196 | final expected = [ 197 | Empty(), 198 | Loading(), 199 | Error(message: SERVER_FAILURE_MESSAGE), 200 | ]; 201 | expectLater(bloc, emitsInOrder(expected)); 202 | // act 203 | bloc.add(GetTriviaForRandomNumber()); 204 | }, 205 | ); 206 | 207 | test( 208 | 'should emit [Loading, Error] with a proper message for the error when getting data fails', 209 | () async { 210 | // arrange 211 | when(mockGetRandomNumberTrivia(any)) 212 | .thenAnswer((_) async => Left(CacheFailure())); 213 | // assert later 214 | final expected = [ 215 | Empty(), 216 | Loading(), 217 | Error(message: CACHE_FAILURE_MESSAGE), 218 | ]; 219 | expectLater(bloc, emitsInOrder(expected)); 220 | // act 221 | bloc.add(GetTriviaForRandomNumber()); 222 | }, 223 | ); 224 | }); 225 | } 226 | -------------------------------------------------------------------------------- /test/features/number_trivia/presentation/pages/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/test/features/number_trivia/presentation/pages/.gitkeep -------------------------------------------------------------------------------- /test/features/number_trivia/presentation/widgets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ResoCoder/flutter-tdd-clean-architecture-course/6c5156142f0e0ed84023793a417bc5e1e60d7ac0/test/features/number_trivia/presentation/widgets/.gitkeep -------------------------------------------------------------------------------- /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 | } 7 | -------------------------------------------------------------------------------- /test/fixtures/trivia_cached.json: -------------------------------------------------------------------------------- 1 | { 2 | "text": "Test Text", 3 | "number": 1 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/trivia_double.json: -------------------------------------------------------------------------------- 1 | { 2 | "text": "Test Text", 3 | "number": 1.0, 4 | "found": true, 5 | "type": "trivia" 6 | } 7 | --------------------------------------------------------------------------------