├── .github └── workflows │ └── codecov.yml ├── .gitignore ├── .metadata ├── README.md ├── analysis_options.yaml ├── android ├── .gitignore ├── app │ ├── build.gradle │ └── src │ │ ├── debug │ │ └── AndroidManifest.xml │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── kotlin │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── tdd_example │ │ │ │ └── MainActivity.kt │ │ └── res │ │ │ ├── drawable-v21 │ │ │ └── launch_background.xml │ │ │ ├── drawable │ │ │ └── launch_background.xml │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── values-night │ │ │ └── styles.xml │ │ │ └── values │ │ │ └── styles.xml │ │ └── profile │ │ └── AndroidManifest.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ └── gradle-wrapper.properties └── settings.gradle ├── coverage └── lcov.info ├── ios ├── .gitignore ├── Flutter │ ├── AppFrameworkInfo.plist │ ├── Debug.xcconfig │ └── Release.xcconfig ├── Podfile ├── Podfile.lock ├── Runner.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ └── WorkspaceSettings.xcsettings │ └── xcshareddata │ │ └── xcschemes │ │ └── Runner.xcscheme ├── Runner.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ ├── IDEWorkspaceChecks.plist │ │ └── WorkspaceSettings.xcsettings └── Runner │ ├── AppDelegate.swift │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── Icon-App-1024x1024@1x.png │ │ ├── Icon-App-20x20@1x.png │ │ ├── Icon-App-20x20@2x.png │ │ ├── Icon-App-20x20@3x.png │ │ ├── Icon-App-29x29@1x.png │ │ ├── Icon-App-29x29@2x.png │ │ ├── Icon-App-29x29@3x.png │ │ ├── Icon-App-40x40@1x.png │ │ ├── Icon-App-40x40@2x.png │ │ ├── Icon-App-40x40@3x.png │ │ ├── Icon-App-60x60@2x.png │ │ ├── Icon-App-60x60@3x.png │ │ ├── Icon-App-76x76@1x.png │ │ ├── Icon-App-76x76@2x.png │ │ └── Icon-App-83.5x83.5@2x.png │ └── LaunchImage.imageset │ │ ├── Contents.json │ │ ├── LaunchImage.png │ │ ├── LaunchImage@2x.png │ │ ├── LaunchImage@3x.png │ │ └── README.md │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ └── Runner-Bridging-Header.h ├── lib ├── core │ ├── error │ │ ├── exceptions.dart │ │ └── failure.dart │ ├── network │ │ └── network_info.dart │ ├── no_params.dart │ ├── states │ │ └── data_state.dart │ └── usecases │ │ └── usecase.dart ├── data │ ├── data_sources │ │ ├── post_remote_data_source.dart │ │ ├── post_remote_data_source.g.dart │ │ ├── user_local_data_source.dart │ │ ├── user_remote_data_source.dart │ │ └── user_remote_data_source.g.dart │ ├── models │ │ ├── post_model.dart │ │ ├── post_model.g.dart │ │ ├── user_model.dart │ │ └── user_model.g.dart │ └── repositories │ │ ├── post_repository_impl.dart │ │ └── user_repository_impl.dart ├── domain │ ├── entities │ │ ├── post.dart │ │ └── user.dart │ ├── repositories │ │ ├── post_repository.dart │ │ └── user_repository.dart │ └── use_cases │ │ ├── get_user_posts.dart │ │ └── get_users.dart ├── injection_container.dart ├── main.dart └── presentation │ ├── app_router.dart │ ├── bloc │ ├── user_posts_cubit.dart │ └── users_cubit.dart │ ├── pages │ ├── user_posts_page.dart │ └── users_page.dart │ └── widgets │ ├── failure_widget.dart │ ├── list_item.dart │ └── loading_widget.dart ├── pubspec.lock ├── pubspec.yaml ├── screenshots ├── image1.png └── image2.png ├── test ├── core │ ├── network │ │ └── network_info_test.dart │ └── states │ │ └── data_state_test.dart ├── data │ ├── data_sources │ │ ├── mock_response_stub.dart │ │ ├── post_remote_data_source_test.dart │ │ ├── user_local_data_source_test.dart │ │ └── user_remote_data_source_test.dart │ ├── models │ │ ├── post_model_test.dart │ │ └── user_model_test.dart │ └── repositories │ │ ├── post_repository_impl_test.dart │ │ └── user_repository_impl_test.dart ├── domain │ └── use_cases │ │ ├── get_user_posts_test.dart │ │ └── get_users_test.dart ├── fixtures │ ├── fixture_reader.dart │ ├── posts.json │ ├── users.json │ └── users_cached.json ├── mocks │ ├── generate_mocks.dart │ ├── generate_mocks.mocks.dart │ ├── mock_post_models.dart │ ├── mock_posts.dart │ ├── mock_user_models.dart │ └── mock_users.dart └── presentation │ ├── bloc │ ├── user_posts_cubit_test.dart │ └── users_cubit_test.dart │ └── global │ ├── failure_widget_test.dart │ └── loading_widget_test.dart └── web ├── favicon.png ├── icons ├── Icon-192.png ├── Icon-512.png ├── Icon-maskable-192.png └── Icon-maskable-512.png ├── index.html └── manifest.json /.github/workflows/codecov.yml: -------------------------------------------------------------------------------- 1 | name: Coverage 2 | on: 3 | pull_request: 4 | branches: 5 | - master 6 | 7 | jobs: 8 | build-and-test: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v1 12 | - uses: actions/setup-java@v1 13 | with: 14 | java-version: '12.x' 15 | - uses: subosito/flutter-action@v1 16 | with: 17 | channel: 'stable' 18 | - run: flutter pub get 19 | - run: flutter build apk --release 20 | # - run: flutter analyze 21 | - run: flutter test --coverage 22 | 23 | - uses: codecov/codecov-action@v1.0.2 24 | with: 25 | token: ${{secrets.CODECOV_TOKEN}} 26 | file: ./coverage/lcov.info 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | **/ios/Flutter/.last_build_id 26 | .dart_tool/ 27 | .flutter-plugins 28 | .flutter-plugins-dependencies 29 | .packages 30 | .pub-cache/ 31 | .pub/ 32 | /build/ 33 | 34 | # Web related 35 | lib/generated_plugin_registrant.dart 36 | 37 | # Symbolication related 38 | app.*.symbols 39 | 40 | # Obfuscation related 41 | app.*.map.json 42 | 43 | # Android Studio will place build artifacts here 44 | /android/app/debug 45 | /android/app/profile 46 | /android/app/release 47 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: cf4400006550b70f28e4b4af815151d1e74846c6 8 | channel: stable 9 | 10 | project_type: app 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/thisisyusub/tdd-learn-example/Coverage) 2 | [![codecov](https://codecov.io/gh/thisisyusub/tdd-learn-example/branch/master/graph/badge.svg)](https://app.codecov.io/gh/thisisyusub/tdd-learn-example) 3 | 4 | # Flutter Clean Architecture with TDD (Test Driven Development) 5 | 6 | It is an example about TDD with Clean Architecture in Flutter apps. 7 | 8 |
9 | 10 | 11 | 14 | 17 | 18 |
12 | 13 | 15 | 16 |
19 |
20 | 21 | ### You can use it, if you want to learn the following topics: 22 | 23 | - Clean Architecture based on Reso Coder Approach 24 | - DI (Depedency Injection) 25 | - Unit Testing 26 | - Widget Testing 27 | - Bloc Testing 28 | - Mockito 29 | - Json serialization 30 | - Bloc State Management 31 | - Multiple Result Management 32 | - Shared Preferences 33 | - Internet Connectivity 34 | - Retrofit 35 | 36 |
37 | 38 | ### Maintainers 39 | 40 | [Kanan Yusubov](https://www.github.com/thisisyusub) 41 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the analyzer, which statically analyzes Dart code to 2 | # check for errors, warnings, and lints. 3 | # 4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled 5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be 6 | # invoked from the command line by running `flutter analyze`. 7 | 8 | # The following line activates a set of recommended lints for Flutter apps, 9 | # packages, and plugins designed to encourage good coding practices. 10 | include: package:flutter_lints/flutter.yaml 11 | 12 | linter: 13 | # The lint rules applied to this project can be customized in the 14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml` 15 | # included above or to enable additional rules. A list of all available lints 16 | # and their documentation is published at 17 | # https://dart-lang.github.io/linter/lints/index.html. 18 | # 19 | # Instead of disabling a lint rule for the entire project in the 20 | # section below, it can also be suppressed for a single line of code 21 | # or a specific dart file by using the `// ignore: name_of_lint` and 22 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file 23 | # producing the lint. 24 | rules: 25 | # avoid_print: false # Uncomment to disable the `avoid_print` rule 26 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule 27 | 28 | # Additional information about this file can be found at 29 | # https://dart.dev/guides/language/analysis-options 30 | -------------------------------------------------------------------------------- /android/.gitignore: -------------------------------------------------------------------------------- 1 | gradle-wrapper.jar 2 | /.gradle 3 | /captures/ 4 | /gradlew 5 | /gradlew.bat 6 | /local.properties 7 | GeneratedPluginRegistrant.java 8 | 9 | # Remember to never publicly share your keystore. 10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app 11 | key.properties 12 | **/*.keystore 13 | **/*.jks 14 | -------------------------------------------------------------------------------- /android/app/build.gradle: -------------------------------------------------------------------------------- 1 | def localProperties = new Properties() 2 | def localPropertiesFile = rootProject.file('local.properties') 3 | if (localPropertiesFile.exists()) { 4 | localPropertiesFile.withReader('UTF-8') { reader -> 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 15 | if (flutterVersionCode == null) { 16 | flutterVersionCode = '1' 17 | } 18 | 19 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 20 | if (flutterVersionName == null) { 21 | flutterVersionName = '1.0' 22 | } 23 | 24 | apply plugin: 'com.android.application' 25 | apply plugin: 'kotlin-android' 26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 27 | 28 | android { 29 | compileSdkVersion flutter.compileSdkVersion 30 | 31 | compileOptions { 32 | sourceCompatibility JavaVersion.VERSION_1_8 33 | targetCompatibility JavaVersion.VERSION_1_8 34 | } 35 | 36 | kotlinOptions { 37 | jvmTarget = '1.8' 38 | } 39 | 40 | sourceSets { 41 | main.java.srcDirs += 'src/main/kotlin' 42 | } 43 | 44 | defaultConfig { 45 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 46 | applicationId "com.example.tdd_example" 47 | minSdkVersion flutter.minSdkVersion 48 | targetSdkVersion flutter.targetSdkVersion 49 | versionCode flutterVersionCode.toInteger() 50 | versionName flutterVersionName 51 | } 52 | 53 | buildTypes { 54 | release { 55 | // TODO: Add your own signing config for the release build. 56 | // Signing with the debug keys for now, so `flutter run --release` works. 57 | signingConfig signingConfigs.debug 58 | } 59 | } 60 | } 61 | 62 | flutter { 63 | source '../..' 64 | } 65 | 66 | dependencies { 67 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 68 | } 69 | -------------------------------------------------------------------------------- /android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 15 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 30 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /android/app/src/main/kotlin/com/example/tdd_example/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.tdd_example 2 | 3 | import io.flutter.embedding.android.FlutterActivity 4 | 5 | class MainActivity: FlutterActivity() { 6 | } 7 | -------------------------------------------------------------------------------- /android/app/src/main/res/drawable-v21/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/values-night/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.3.50' 3 | repositories { 4 | google() 5 | mavenCentral() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:4.1.0' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | mavenCentral() 18 | } 19 | } 20 | 21 | rootProject.buildDir = '../build' 22 | subprojects { 23 | project.buildDir = "${rootProject.buildDir}/${project.name}" 24 | } 25 | subprojects { 26 | project.evaluationDependsOn(':app') 27 | } 28 | 29 | task clean(type: Delete) { 30 | delete rootProject.buildDir 31 | } 32 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | android.useAndroidX=true 3 | android.enableJetifier=true 4 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #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-6.7-all.zip 7 | -------------------------------------------------------------------------------- /android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | 3 | def localPropertiesFile = new File(rootProject.projectDir, "local.properties") 4 | def properties = new Properties() 5 | 6 | assert localPropertiesFile.exists() 7 | localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } 8 | 9 | def flutterSdkPath = properties.getProperty("flutter.sdk") 10 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties" 11 | apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" 12 | -------------------------------------------------------------------------------- /coverage/lcov.info: -------------------------------------------------------------------------------- 1 | SF:lib\core\network\network_info.dart 2 | DA:10,1 3 | DA:13,1 4 | DA:14,3 5 | DA:16,1 6 | DA:17,1 7 | LF:5 8 | LH:5 9 | end_of_record 10 | SF:lib\features\get_users\domain\entities\user.dart 11 | DA:9,10 12 | DA:16,4 13 | DA:17,20 14 | LF:3 15 | LH:3 16 | end_of_record 17 | SF:lib\core\states\data_state.dart 18 | DA:10,4 19 | DA:18,2 20 | DA:20,2 21 | DA:22,2 22 | DA:24,2 23 | DA:26,4 24 | DA:28,1 25 | DA:29,1 26 | DA:30,1 27 | DA:31,1 28 | DA:32,1 29 | DA:33,1 30 | DA:34,1 31 | LF:13 32 | LH:13 33 | end_of_record 34 | SF:lib\features\get_users\data\data_sources\user_local_data_source.dart 35 | DA:23,1 36 | DA:26,1 37 | DA:27,1 38 | DA:29,2 39 | DA:30,3 40 | DA:33,4 41 | DA:37,1 42 | DA:38,2 43 | DA:41,1 44 | DA:43,4 45 | DA:45,1 46 | LF:11 47 | LH:11 48 | end_of_record 49 | SF:lib\features\get_users\data\models\user_model.dart 50 | DA:9,6 51 | DA:14,3 52 | DA:21,3 53 | DA:22,3 54 | DA:25,4 55 | LF:5 56 | LH:5 57 | end_of_record 58 | SF:lib\features\get_users\data\models\user_model.g.dart 59 | DA:9,6 60 | DA:10,3 61 | DA:11,3 62 | DA:12,3 63 | DA:13,3 64 | DA:16,4 65 | DA:17,2 66 | DA:18,2 67 | DA:19,2 68 | DA:20,2 69 | LF:10 70 | LH:10 71 | end_of_record 72 | SF:lib\core\widgets\failure_widget.dart 73 | DA:4,1 74 | DA:7,0 75 | DA:11,1 76 | DA:13,1 77 | DA:14,1 78 | DA:15,1 79 | DA:16,3 80 | LF:7 81 | LH:6 82 | end_of_record 83 | SF:lib\core\widgets\loading_widget.dart 84 | DA:4,1 85 | DA:6,1 86 | LF:2 87 | LH:2 88 | end_of_record 89 | SF:lib\features\get_users\data\data_sources\user_remote_data_source.dart 90 | DA:23,0 91 | LF:1 92 | LH:0 93 | end_of_record 94 | SF:lib\features\get_users\data\data_sources\user_remote_data_source.g.dart 95 | DA:10,1 96 | DA:11,1 97 | DA:19,1 98 | DA:21,1 99 | DA:22,1 100 | DA:23,1 101 | DA:24,3 102 | DA:25,1 103 | DA:26,1 104 | DA:27,3 105 | DA:29,2 106 | DA:30,1 107 | DA:31,3 108 | DA:32,1 109 | DA:37,1 110 | DA:39,1 111 | DA:40,1 112 | DA:41,1 113 | DA:42,3 114 | DA:43,1 115 | DA:44,1 116 | DA:45,4 117 | DA:47,2 118 | DA:48,2 119 | DA:52,1 120 | DA:53,1 121 | DA:54,2 122 | DA:55,2 123 | DA:56,1 124 | DA:57,0 125 | DA:59,1 126 | LF:31 127 | LH:30 128 | end_of_record 129 | SF:lib\core\error\failure.dart 130 | DA:4,1 131 | DA:5,1 132 | LF:2 133 | LH:2 134 | end_of_record 135 | SF:lib\features\get_users\data\repositories\user_repository_impl.dart 136 | DA:16,1 137 | DA:23,1 138 | DA:25,4 139 | DA:26,1 140 | DA:27,2 141 | DA:32,1 142 | DA:33,3 143 | DA:35,3 144 | DA:36,2 145 | DA:38,1 146 | DA:39,1 147 | DA:40,2 148 | DA:44,4 149 | DA:45,1 150 | DA:46,2 151 | LF:15 152 | LH:15 153 | end_of_record 154 | SF:lib\core\no_params.dart 155 | DA:6,5 156 | DA:8,0 157 | DA:9,0 158 | LF:3 159 | LH:1 160 | end_of_record 161 | SF:lib\features\get_users\domain\use_cases\get_users.dart 162 | DA:12,1 163 | DA:14,1 164 | DA:16,2 165 | LF:3 166 | LH:3 167 | end_of_record 168 | SF:lib\features\get_users\domain\use_cases\get_user_by_id.dart 169 | DA:11,1 170 | DA:13,1 171 | DA:14,2 172 | LF:3 173 | LH:3 174 | end_of_record 175 | SF:lib\features\get_users\presentation\bloc\users_cubit.dart 176 | DA:13,3 177 | DA:15,1 178 | DA:16,2 179 | DA:18,3 180 | DA:20,1 181 | DA:21,3 182 | DA:22,2 183 | DA:23,3 184 | LF:8 185 | LH:8 186 | end_of_record 187 | -------------------------------------------------------------------------------- /ios/.gitignore: -------------------------------------------------------------------------------- 1 | **/dgph 2 | *.mode1v3 3 | *.mode2v3 4 | *.moved-aside 5 | *.pbxuser 6 | *.perspectivev3 7 | **/*sync/ 8 | .sconsign.dblite 9 | .tags* 10 | **/.vagrant/ 11 | **/DerivedData/ 12 | Icon? 13 | **/Pods/ 14 | **/.symlinks/ 15 | profile 16 | xcuserdata 17 | **/.generated/ 18 | Flutter/App.framework 19 | Flutter/Flutter.framework 20 | Flutter/Flutter.podspec 21 | Flutter/Generated.xcconfig 22 | Flutter/ephemeral/ 23 | Flutter/app.flx 24 | Flutter/app.zip 25 | Flutter/flutter_assets/ 26 | Flutter/flutter_export_environment.sh 27 | ServiceDefinitions.json 28 | Runner/GeneratedPluginRegistrant.* 29 | 30 | # Exceptions to above rules. 31 | !default.mode1v3 32 | !default.mode2v3 33 | !default.pbxuser 34 | !default.perspectivev3 35 | -------------------------------------------------------------------------------- /ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | App 9 | CFBundleIdentifier 10 | io.flutter.flutter.app 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | App 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | MinimumOSVersion 24 | 9.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /ios/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment this line to define a global platform for your project 2 | # platform :ios, '9.0' 3 | 4 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency. 5 | ENV['COCOAPODS_DISABLE_STATS'] = 'true' 6 | 7 | project 'Runner', { 8 | 'Debug' => :debug, 9 | 'Profile' => :release, 10 | 'Release' => :release, 11 | } 12 | 13 | def flutter_root 14 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) 15 | unless File.exist?(generated_xcode_build_settings_path) 16 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" 17 | end 18 | 19 | File.foreach(generated_xcode_build_settings_path) do |line| 20 | matches = line.match(/FLUTTER_ROOT\=(.*)/) 21 | return matches[1].strip if matches 22 | end 23 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" 24 | end 25 | 26 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) 27 | 28 | flutter_ios_podfile_setup 29 | 30 | target 'Runner' do 31 | use_frameworks! 32 | use_modular_headers! 33 | 34 | flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) 35 | end 36 | 37 | post_install do |installer| 38 | installer.pods_project.targets.each do |target| 39 | flutter_additional_ios_build_settings(target) 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /ios/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - connectivity_plus (0.0.1): 3 | - Flutter 4 | - ReachabilitySwift 5 | - Flutter (1.0.0) 6 | - ReachabilitySwift (5.0.0) 7 | - shared_preferences_ios (0.0.1): 8 | - Flutter 9 | 10 | DEPENDENCIES: 11 | - connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`) 12 | - Flutter (from `Flutter`) 13 | - shared_preferences_ios (from `.symlinks/plugins/shared_preferences_ios/ios`) 14 | 15 | SPEC REPOS: 16 | trunk: 17 | - ReachabilitySwift 18 | 19 | EXTERNAL SOURCES: 20 | connectivity_plus: 21 | :path: ".symlinks/plugins/connectivity_plus/ios" 22 | Flutter: 23 | :path: Flutter 24 | shared_preferences_ios: 25 | :path: ".symlinks/plugins/shared_preferences_ios/ios" 26 | 27 | SPEC CHECKSUMS: 28 | connectivity_plus: 413a8857dd5d9f1c399a39130850d02fe0feaf7e 29 | Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a 30 | ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825 31 | shared_preferences_ios: aef470a42dc4675a1cdd50e3158b42e3d1232b32 32 | 33 | PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c 34 | 35 | COCOAPODS: 1.11.2 36 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 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 | 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 13 | 8161F18CA070A8CF47D9A116 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 07D7DBF62C94759FF5A3FE88 /* Pods_Runner.framework */; }; 14 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 15 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 16 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXCopyFilesBuildPhase section */ 20 | 9705A1C41CF9048500538489 /* Embed Frameworks */ = { 21 | isa = PBXCopyFilesBuildPhase; 22 | buildActionMask = 2147483647; 23 | dstPath = ""; 24 | dstSubfolderSpec = 10; 25 | files = ( 26 | ); 27 | name = "Embed Frameworks"; 28 | runOnlyForDeploymentPostprocessing = 0; 29 | }; 30 | /* End PBXCopyFilesBuildPhase section */ 31 | 32 | /* Begin PBXFileReference section */ 33 | 07D7DBF62C94759FF5A3FE88 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 34 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 35 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 36 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 37 | 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 38 | 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 39 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 40 | 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 41 | 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 42 | 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 44 | 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 45 | 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 46 | 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 47 | D2F5DCF40F9A716B2CEE3597 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; 48 | E856BD7EC5DC85214F0D4A0C /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; 49 | E8EAAFDD877FC5B6C6B12AC1 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; 50 | /* End PBXFileReference section */ 51 | 52 | /* Begin PBXFrameworksBuildPhase section */ 53 | 97C146EB1CF9000F007C117D /* Frameworks */ = { 54 | isa = PBXFrameworksBuildPhase; 55 | buildActionMask = 2147483647; 56 | files = ( 57 | 8161F18CA070A8CF47D9A116 /* Pods_Runner.framework in Frameworks */, 58 | ); 59 | runOnlyForDeploymentPostprocessing = 0; 60 | }; 61 | /* End PBXFrameworksBuildPhase section */ 62 | 63 | /* Begin PBXGroup section */ 64 | 22F60BEA048AAA293FA6E4AA /* Frameworks */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | 07D7DBF62C94759FF5A3FE88 /* Pods_Runner.framework */, 68 | ); 69 | name = Frameworks; 70 | sourceTree = ""; 71 | }; 72 | 9740EEB11CF90186004384FC /* Flutter */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 76 | 9740EEB21CF90195004384FC /* Debug.xcconfig */, 77 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, 78 | 9740EEB31CF90195004384FC /* Generated.xcconfig */, 79 | ); 80 | name = Flutter; 81 | sourceTree = ""; 82 | }; 83 | 97C146E51CF9000F007C117D = { 84 | isa = PBXGroup; 85 | children = ( 86 | 9740EEB11CF90186004384FC /* Flutter */, 87 | 97C146F01CF9000F007C117D /* Runner */, 88 | 97C146EF1CF9000F007C117D /* Products */, 89 | F6C44115A65D910C8FC309FA /* Pods */, 90 | 22F60BEA048AAA293FA6E4AA /* Frameworks */, 91 | ); 92 | sourceTree = ""; 93 | }; 94 | 97C146EF1CF9000F007C117D /* Products */ = { 95 | isa = PBXGroup; 96 | children = ( 97 | 97C146EE1CF9000F007C117D /* Runner.app */, 98 | ); 99 | name = Products; 100 | sourceTree = ""; 101 | }; 102 | 97C146F01CF9000F007C117D /* Runner */ = { 103 | isa = PBXGroup; 104 | children = ( 105 | 97C146FA1CF9000F007C117D /* Main.storyboard */, 106 | 97C146FD1CF9000F007C117D /* Assets.xcassets */, 107 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, 108 | 97C147021CF9000F007C117D /* Info.plist */, 109 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, 110 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, 111 | 74858FAE1ED2DC5600515810 /* AppDelegate.swift */, 112 | 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */, 113 | ); 114 | path = Runner; 115 | sourceTree = ""; 116 | }; 117 | F6C44115A65D910C8FC309FA /* Pods */ = { 118 | isa = PBXGroup; 119 | children = ( 120 | D2F5DCF40F9A716B2CEE3597 /* Pods-Runner.debug.xcconfig */, 121 | E856BD7EC5DC85214F0D4A0C /* Pods-Runner.release.xcconfig */, 122 | E8EAAFDD877FC5B6C6B12AC1 /* Pods-Runner.profile.xcconfig */, 123 | ); 124 | name = Pods; 125 | path = Pods; 126 | sourceTree = ""; 127 | }; 128 | /* End PBXGroup section */ 129 | 130 | /* Begin PBXNativeTarget section */ 131 | 97C146ED1CF9000F007C117D /* Runner */ = { 132 | isa = PBXNativeTarget; 133 | buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; 134 | buildPhases = ( 135 | 0ABB742711A3D0FB1EC34D57 /* [CP] Check Pods Manifest.lock */, 136 | 9740EEB61CF901F6004384FC /* Run Script */, 137 | 97C146EA1CF9000F007C117D /* Sources */, 138 | 97C146EB1CF9000F007C117D /* Frameworks */, 139 | 97C146EC1CF9000F007C117D /* Resources */, 140 | 9705A1C41CF9048500538489 /* Embed Frameworks */, 141 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */, 142 | EE9A42BFDACBD2620BADF29E /* [CP] Embed Pods Frameworks */, 143 | ); 144 | buildRules = ( 145 | ); 146 | dependencies = ( 147 | ); 148 | name = Runner; 149 | productName = Runner; 150 | productReference = 97C146EE1CF9000F007C117D /* Runner.app */; 151 | productType = "com.apple.product-type.application"; 152 | }; 153 | /* End PBXNativeTarget section */ 154 | 155 | /* Begin PBXProject section */ 156 | 97C146E61CF9000F007C117D /* Project object */ = { 157 | isa = PBXProject; 158 | attributes = { 159 | LastUpgradeCheck = 1300; 160 | ORGANIZATIONNAME = ""; 161 | TargetAttributes = { 162 | 97C146ED1CF9000F007C117D = { 163 | CreatedOnToolsVersion = 7.3.1; 164 | LastSwiftMigration = 1100; 165 | }; 166 | }; 167 | }; 168 | buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; 169 | compatibilityVersion = "Xcode 9.3"; 170 | developmentRegion = en; 171 | hasScannedForEncodings = 0; 172 | knownRegions = ( 173 | en, 174 | Base, 175 | ); 176 | mainGroup = 97C146E51CF9000F007C117D; 177 | productRefGroup = 97C146EF1CF9000F007C117D /* Products */; 178 | projectDirPath = ""; 179 | projectRoot = ""; 180 | targets = ( 181 | 97C146ED1CF9000F007C117D /* Runner */, 182 | ); 183 | }; 184 | /* End PBXProject section */ 185 | 186 | /* Begin PBXResourcesBuildPhase section */ 187 | 97C146EC1CF9000F007C117D /* Resources */ = { 188 | isa = PBXResourcesBuildPhase; 189 | buildActionMask = 2147483647; 190 | files = ( 191 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, 192 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 193 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, 194 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, 195 | ); 196 | runOnlyForDeploymentPostprocessing = 0; 197 | }; 198 | /* End PBXResourcesBuildPhase section */ 199 | 200 | /* Begin PBXShellScriptBuildPhase section */ 201 | 0ABB742711A3D0FB1EC34D57 /* [CP] Check Pods Manifest.lock */ = { 202 | isa = PBXShellScriptBuildPhase; 203 | buildActionMask = 2147483647; 204 | files = ( 205 | ); 206 | inputFileListPaths = ( 207 | ); 208 | inputPaths = ( 209 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 210 | "${PODS_ROOT}/Manifest.lock", 211 | ); 212 | name = "[CP] Check Pods Manifest.lock"; 213 | outputFileListPaths = ( 214 | ); 215 | outputPaths = ( 216 | "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", 217 | ); 218 | runOnlyForDeploymentPostprocessing = 0; 219 | shellPath = /bin/sh; 220 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 221 | showEnvVarsInLog = 0; 222 | }; 223 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { 224 | isa = PBXShellScriptBuildPhase; 225 | buildActionMask = 2147483647; 226 | files = ( 227 | ); 228 | inputPaths = ( 229 | ); 230 | name = "Thin Binary"; 231 | outputPaths = ( 232 | ); 233 | runOnlyForDeploymentPostprocessing = 0; 234 | shellPath = /bin/sh; 235 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; 236 | }; 237 | 9740EEB61CF901F6004384FC /* Run Script */ = { 238 | isa = PBXShellScriptBuildPhase; 239 | buildActionMask = 2147483647; 240 | files = ( 241 | ); 242 | inputPaths = ( 243 | ); 244 | name = "Run Script"; 245 | outputPaths = ( 246 | ); 247 | runOnlyForDeploymentPostprocessing = 0; 248 | shellPath = /bin/sh; 249 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; 250 | }; 251 | EE9A42BFDACBD2620BADF29E /* [CP] Embed Pods Frameworks */ = { 252 | isa = PBXShellScriptBuildPhase; 253 | buildActionMask = 2147483647; 254 | files = ( 255 | ); 256 | inputFileListPaths = ( 257 | "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", 258 | ); 259 | name = "[CP] Embed Pods Frameworks"; 260 | outputFileListPaths = ( 261 | "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", 262 | ); 263 | runOnlyForDeploymentPostprocessing = 0; 264 | shellPath = /bin/sh; 265 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; 266 | showEnvVarsInLog = 0; 267 | }; 268 | /* End PBXShellScriptBuildPhase section */ 269 | 270 | /* Begin PBXSourcesBuildPhase section */ 271 | 97C146EA1CF9000F007C117D /* Sources */ = { 272 | isa = PBXSourcesBuildPhase; 273 | buildActionMask = 2147483647; 274 | files = ( 275 | 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */, 276 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, 277 | ); 278 | runOnlyForDeploymentPostprocessing = 0; 279 | }; 280 | /* End PBXSourcesBuildPhase section */ 281 | 282 | /* Begin PBXVariantGroup section */ 283 | 97C146FA1CF9000F007C117D /* Main.storyboard */ = { 284 | isa = PBXVariantGroup; 285 | children = ( 286 | 97C146FB1CF9000F007C117D /* Base */, 287 | ); 288 | name = Main.storyboard; 289 | sourceTree = ""; 290 | }; 291 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { 292 | isa = PBXVariantGroup; 293 | children = ( 294 | 97C147001CF9000F007C117D /* Base */, 295 | ); 296 | name = LaunchScreen.storyboard; 297 | sourceTree = ""; 298 | }; 299 | /* End PBXVariantGroup section */ 300 | 301 | /* Begin XCBuildConfiguration section */ 302 | 249021D3217E4FDB00AE95B9 /* Profile */ = { 303 | isa = XCBuildConfiguration; 304 | buildSettings = { 305 | ALWAYS_SEARCH_USER_PATHS = NO; 306 | CLANG_ANALYZER_NONNULL = YES; 307 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 308 | CLANG_CXX_LIBRARY = "libc++"; 309 | CLANG_ENABLE_MODULES = YES; 310 | CLANG_ENABLE_OBJC_ARC = YES; 311 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 312 | CLANG_WARN_BOOL_CONVERSION = YES; 313 | CLANG_WARN_COMMA = YES; 314 | CLANG_WARN_CONSTANT_CONVERSION = YES; 315 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 316 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 317 | CLANG_WARN_EMPTY_BODY = YES; 318 | CLANG_WARN_ENUM_CONVERSION = YES; 319 | CLANG_WARN_INFINITE_RECURSION = YES; 320 | CLANG_WARN_INT_CONVERSION = YES; 321 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 322 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 323 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 324 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 325 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 326 | CLANG_WARN_STRICT_PROTOTYPES = YES; 327 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 328 | CLANG_WARN_UNREACHABLE_CODE = YES; 329 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 330 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 331 | COPY_PHASE_STRIP = NO; 332 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 333 | ENABLE_NS_ASSERTIONS = NO; 334 | ENABLE_STRICT_OBJC_MSGSEND = YES; 335 | GCC_C_LANGUAGE_STANDARD = gnu99; 336 | GCC_NO_COMMON_BLOCKS = YES; 337 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 338 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 339 | GCC_WARN_UNDECLARED_SELECTOR = YES; 340 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 341 | GCC_WARN_UNUSED_FUNCTION = YES; 342 | GCC_WARN_UNUSED_VARIABLE = YES; 343 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 344 | MTL_ENABLE_DEBUG_INFO = NO; 345 | SDKROOT = iphoneos; 346 | SUPPORTED_PLATFORMS = iphoneos; 347 | TARGETED_DEVICE_FAMILY = "1,2"; 348 | VALIDATE_PRODUCT = YES; 349 | }; 350 | name = Profile; 351 | }; 352 | 249021D4217E4FDB00AE95B9 /* Profile */ = { 353 | isa = XCBuildConfiguration; 354 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 355 | buildSettings = { 356 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 357 | CLANG_ENABLE_MODULES = YES; 358 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 359 | ENABLE_BITCODE = NO; 360 | INFOPLIST_FILE = Runner/Info.plist; 361 | LD_RUNPATH_SEARCH_PATHS = ( 362 | "$(inherited)", 363 | "@executable_path/Frameworks", 364 | ); 365 | PRODUCT_BUNDLE_IDENTIFIER = com.example.tddExample; 366 | PRODUCT_NAME = "$(TARGET_NAME)"; 367 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 368 | SWIFT_VERSION = 5.0; 369 | VERSIONING_SYSTEM = "apple-generic"; 370 | }; 371 | name = Profile; 372 | }; 373 | 97C147031CF9000F007C117D /* Debug */ = { 374 | isa = XCBuildConfiguration; 375 | buildSettings = { 376 | ALWAYS_SEARCH_USER_PATHS = NO; 377 | CLANG_ANALYZER_NONNULL = YES; 378 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 379 | CLANG_CXX_LIBRARY = "libc++"; 380 | CLANG_ENABLE_MODULES = YES; 381 | CLANG_ENABLE_OBJC_ARC = YES; 382 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 383 | CLANG_WARN_BOOL_CONVERSION = YES; 384 | CLANG_WARN_COMMA = YES; 385 | CLANG_WARN_CONSTANT_CONVERSION = YES; 386 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 387 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 388 | CLANG_WARN_EMPTY_BODY = YES; 389 | CLANG_WARN_ENUM_CONVERSION = YES; 390 | CLANG_WARN_INFINITE_RECURSION = YES; 391 | CLANG_WARN_INT_CONVERSION = YES; 392 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 393 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 394 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 395 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 396 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 397 | CLANG_WARN_STRICT_PROTOTYPES = YES; 398 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 399 | CLANG_WARN_UNREACHABLE_CODE = YES; 400 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 401 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 402 | COPY_PHASE_STRIP = NO; 403 | DEBUG_INFORMATION_FORMAT = dwarf; 404 | ENABLE_STRICT_OBJC_MSGSEND = YES; 405 | ENABLE_TESTABILITY = YES; 406 | GCC_C_LANGUAGE_STANDARD = gnu99; 407 | GCC_DYNAMIC_NO_PIC = NO; 408 | GCC_NO_COMMON_BLOCKS = YES; 409 | GCC_OPTIMIZATION_LEVEL = 0; 410 | GCC_PREPROCESSOR_DEFINITIONS = ( 411 | "DEBUG=1", 412 | "$(inherited)", 413 | ); 414 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 415 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 416 | GCC_WARN_UNDECLARED_SELECTOR = YES; 417 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 418 | GCC_WARN_UNUSED_FUNCTION = YES; 419 | GCC_WARN_UNUSED_VARIABLE = YES; 420 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 421 | MTL_ENABLE_DEBUG_INFO = YES; 422 | ONLY_ACTIVE_ARCH = YES; 423 | SDKROOT = iphoneos; 424 | TARGETED_DEVICE_FAMILY = "1,2"; 425 | }; 426 | name = Debug; 427 | }; 428 | 97C147041CF9000F007C117D /* Release */ = { 429 | isa = XCBuildConfiguration; 430 | buildSettings = { 431 | ALWAYS_SEARCH_USER_PATHS = NO; 432 | CLANG_ANALYZER_NONNULL = YES; 433 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 434 | CLANG_CXX_LIBRARY = "libc++"; 435 | CLANG_ENABLE_MODULES = YES; 436 | CLANG_ENABLE_OBJC_ARC = YES; 437 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 438 | CLANG_WARN_BOOL_CONVERSION = YES; 439 | CLANG_WARN_COMMA = YES; 440 | CLANG_WARN_CONSTANT_CONVERSION = YES; 441 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 442 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 443 | CLANG_WARN_EMPTY_BODY = YES; 444 | CLANG_WARN_ENUM_CONVERSION = YES; 445 | CLANG_WARN_INFINITE_RECURSION = YES; 446 | CLANG_WARN_INT_CONVERSION = YES; 447 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 448 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 449 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 450 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 451 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 452 | CLANG_WARN_STRICT_PROTOTYPES = YES; 453 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 454 | CLANG_WARN_UNREACHABLE_CODE = YES; 455 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 456 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 457 | COPY_PHASE_STRIP = NO; 458 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 459 | ENABLE_NS_ASSERTIONS = NO; 460 | ENABLE_STRICT_OBJC_MSGSEND = YES; 461 | GCC_C_LANGUAGE_STANDARD = gnu99; 462 | GCC_NO_COMMON_BLOCKS = YES; 463 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 464 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 465 | GCC_WARN_UNDECLARED_SELECTOR = YES; 466 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 467 | GCC_WARN_UNUSED_FUNCTION = YES; 468 | GCC_WARN_UNUSED_VARIABLE = YES; 469 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 470 | MTL_ENABLE_DEBUG_INFO = NO; 471 | SDKROOT = iphoneos; 472 | SUPPORTED_PLATFORMS = iphoneos; 473 | SWIFT_COMPILATION_MODE = wholemodule; 474 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 475 | TARGETED_DEVICE_FAMILY = "1,2"; 476 | VALIDATE_PRODUCT = YES; 477 | }; 478 | name = Release; 479 | }; 480 | 97C147061CF9000F007C117D /* Debug */ = { 481 | isa = XCBuildConfiguration; 482 | baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; 483 | buildSettings = { 484 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 485 | CLANG_ENABLE_MODULES = YES; 486 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 487 | ENABLE_BITCODE = NO; 488 | INFOPLIST_FILE = Runner/Info.plist; 489 | LD_RUNPATH_SEARCH_PATHS = ( 490 | "$(inherited)", 491 | "@executable_path/Frameworks", 492 | ); 493 | PRODUCT_BUNDLE_IDENTIFIER = com.example.tddExample; 494 | PRODUCT_NAME = "$(TARGET_NAME)"; 495 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 496 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 497 | SWIFT_VERSION = 5.0; 498 | VERSIONING_SYSTEM = "apple-generic"; 499 | }; 500 | name = Debug; 501 | }; 502 | 97C147071CF9000F007C117D /* Release */ = { 503 | isa = XCBuildConfiguration; 504 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 505 | buildSettings = { 506 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 507 | CLANG_ENABLE_MODULES = YES; 508 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 509 | ENABLE_BITCODE = NO; 510 | INFOPLIST_FILE = Runner/Info.plist; 511 | LD_RUNPATH_SEARCH_PATHS = ( 512 | "$(inherited)", 513 | "@executable_path/Frameworks", 514 | ); 515 | PRODUCT_BUNDLE_IDENTIFIER = com.example.tddExample; 516 | PRODUCT_NAME = "$(TARGET_NAME)"; 517 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 518 | SWIFT_VERSION = 5.0; 519 | VERSIONING_SYSTEM = "apple-generic"; 520 | }; 521 | name = Release; 522 | }; 523 | /* End XCBuildConfiguration section */ 524 | 525 | /* Begin XCConfigurationList section */ 526 | 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { 527 | isa = XCConfigurationList; 528 | buildConfigurations = ( 529 | 97C147031CF9000F007C117D /* Debug */, 530 | 97C147041CF9000F007C117D /* Release */, 531 | 249021D3217E4FDB00AE95B9 /* Profile */, 532 | ); 533 | defaultConfigurationIsVisible = 0; 534 | defaultConfigurationName = Release; 535 | }; 536 | 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { 537 | isa = XCConfigurationList; 538 | buildConfigurations = ( 539 | 97C147061CF9000F007C117D /* Debug */, 540 | 97C147071CF9000F007C117D /* Release */, 541 | 249021D4217E4FDB00AE95B9 /* Profile */, 542 | ); 543 | defaultConfigurationIsVisible = 0; 544 | defaultConfigurationName = Release; 545 | }; 546 | /* End XCConfigurationList section */ 547 | }; 548 | rootObject = 97C146E61CF9000F007C117D /* Project object */; 549 | } 550 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 69 | 71 | 77 | 78 | 79 | 80 | 82 | 83 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ios/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import Flutter 3 | 4 | @UIApplicationMain 5 | @objc class AppDelegate: FlutterAppDelegate { 6 | override func application( 7 | _ application: UIApplication, 8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? 9 | ) -> Bool { 10 | GeneratedPluginRegistrant.register(with: self) 11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "Icon-App-20x20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "Icon-App-20x20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "Icon-App-29x29@1x.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "Icon-App-29x29@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "29x29", 29 | "idiom" : "iphone", 30 | "filename" : "Icon-App-29x29@3x.png", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "Icon-App-40x40@2x.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "40x40", 41 | "idiom" : "iphone", 42 | "filename" : "Icon-App-40x40@3x.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "Icon-App-60x60@2x.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "60x60", 53 | "idiom" : "iphone", 54 | "filename" : "Icon-App-60x60@3x.png", 55 | "scale" : "3x" 56 | }, 57 | { 58 | "size" : "20x20", 59 | "idiom" : "ipad", 60 | "filename" : "Icon-App-20x20@1x.png", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "size" : "20x20", 65 | "idiom" : "ipad", 66 | "filename" : "Icon-App-20x20@2x.png", 67 | "scale" : "2x" 68 | }, 69 | { 70 | "size" : "29x29", 71 | "idiom" : "ipad", 72 | "filename" : "Icon-App-29x29@1x.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "29x29", 77 | "idiom" : "ipad", 78 | "filename" : "Icon-App-29x29@2x.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "40x40", 83 | "idiom" : "ipad", 84 | "filename" : "Icon-App-40x40@1x.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "40x40", 89 | "idiom" : "ipad", 90 | "filename" : "Icon-App-40x40@2x.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "76x76", 95 | "idiom" : "ipad", 96 | "filename" : "Icon-App-76x76@1x.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "76x76", 101 | "idiom" : "ipad", 102 | "filename" : "Icon-App-76x76@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "size" : "83.5x83.5", 107 | "idiom" : "ipad", 108 | "filename" : "Icon-App-83.5x83.5@2x.png", 109 | "scale" : "2x" 110 | }, 111 | { 112 | "size" : "1024x1024", 113 | "idiom" : "ios-marketing", 114 | "filename" : "Icon-App-1024x1024@1x.png", 115 | "scale" : "1x" 116 | } 117 | ], 118 | "info" : { 119 | "version" : 1, 120 | "author" : "xcode" 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/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/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/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/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/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/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/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/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/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/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/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/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/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/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/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/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/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/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/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/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/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/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/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/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/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/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/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/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/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/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md: -------------------------------------------------------------------------------- 1 | # Launch Screen Assets 2 | 3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory. 4 | 5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. -------------------------------------------------------------------------------- /ios/Runner/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /ios/Runner/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /ios/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDisplayName 8 | Tdd Example 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | tdd_example 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | $(FLUTTER_BUILD_NUMBER) 25 | LSRequiresIPhoneOS 26 | 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | UIViewControllerBasedStatusBarAppearance 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /lib/core/error/exceptions.dart: -------------------------------------------------------------------------------- 1 | class CacheException implements Exception {} 2 | -------------------------------------------------------------------------------- /lib/core/error/failure.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | 3 | abstract class Failure extends Equatable { 4 | @override 5 | List get props => []; 6 | } 7 | 8 | class ServerFailure extends Failure {} 9 | 10 | class CacheFailure extends Failure {} 11 | -------------------------------------------------------------------------------- /lib/core/network/network_info.dart: -------------------------------------------------------------------------------- 1 | import 'package:connectivity_plus/connectivity_plus.dart'; 2 | 3 | abstract class NetworkInfo { 4 | Future get isConnected; 5 | } 6 | 7 | class NetworkInfoImpl implements NetworkInfo { 8 | final Connectivity connectivity; 9 | 10 | NetworkInfoImpl(this.connectivity); 11 | 12 | @override 13 | Future get isConnected async { 14 | final connectivityResult = await connectivity.checkConnectivity(); 15 | 16 | return connectivityResult == ConnectivityResult.mobile || 17 | connectivityResult == ConnectivityResult.wifi; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/core/no_params.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | 3 | const noParams = NoParams(); 4 | 5 | class NoParams extends Equatable { 6 | const NoParams(); 7 | 8 | @override 9 | List get props => []; 10 | } 11 | -------------------------------------------------------------------------------- /lib/core/states/data_state.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | 3 | class DataState extends Equatable { 4 | final bool isInProgress; 5 | final bool isFailure; 6 | final bool isSuccess; 7 | final bool isEmpty; 8 | final T? data; 9 | 10 | const DataState({ 11 | this.isInProgress = false, 12 | this.isFailure = false, 13 | this.isSuccess = false, 14 | this.isEmpty = false, 15 | this.data, 16 | }); 17 | 18 | factory DataState.initial() => const DataState(); 19 | 20 | factory DataState.inProgress() => const DataState(isInProgress: true); 21 | 22 | factory DataState.failure() => const DataState(isFailure: true); 23 | 24 | factory DataState.empty() => const DataState(isEmpty: true); 25 | 26 | factory DataState.success(T data) => DataState(isSuccess: true, data: data); 27 | 28 | @override 29 | List get props => [ 30 | isInProgress, 31 | isFailure, 32 | isEmpty, 33 | isFailure, 34 | data, 35 | ]; 36 | } 37 | -------------------------------------------------------------------------------- /lib/core/usecases/usecase.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:tdd_example/core/error/failure.dart'; 3 | 4 | abstract class Usecase { 5 | Future> call(Params params); 6 | } 7 | -------------------------------------------------------------------------------- /lib/data/data_sources/post_remote_data_source.dart: -------------------------------------------------------------------------------- 1 | import 'package:dio/dio.dart'; 2 | import 'package:retrofit/retrofit.dart'; 3 | 4 | import '../models/post_model.dart'; 5 | 6 | part 'post_remote_data_source.g.dart'; 7 | 8 | abstract class PostRemoteDataSource { 9 | Future> getUserPosts(int userId); 10 | } 11 | 12 | @RestApi(baseUrl: 'https://jsonplaceholder.typicode.com/') 13 | abstract class PostRemoteDataSourceImpl implements PostRemoteDataSource { 14 | factory PostRemoteDataSourceImpl(Dio dio, {String baseUrl}) = 15 | _PostRemoteDataSourceImpl; 16 | 17 | @GET('/posts') 18 | @override 19 | Future> getUserPosts(@Query('userId') int userId); 20 | } 21 | -------------------------------------------------------------------------------- /lib/data/data_sources/post_remote_data_source.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'post_remote_data_source.dart'; 4 | 5 | // ************************************************************************** 6 | // RetrofitGenerator 7 | // ************************************************************************** 8 | 9 | class _PostRemoteDataSourceImpl implements PostRemoteDataSourceImpl { 10 | _PostRemoteDataSourceImpl(this._dio, {this.baseUrl}) { 11 | baseUrl ??= 'https://jsonplaceholder.typicode.com/'; 12 | } 13 | 14 | final Dio _dio; 15 | 16 | String? baseUrl; 17 | 18 | @override 19 | Future> getUserPosts(userId) async { 20 | const _extra = {}; 21 | final queryParameters = {r'userId': userId}; 22 | final _headers = {}; 23 | final _data = {}; 24 | final _result = await _dio.fetch>( 25 | _setStreamType>( 26 | Options(method: 'GET', headers: _headers, extra: _extra) 27 | .compose(_dio.options, '/posts', 28 | queryParameters: queryParameters, data: _data) 29 | .copyWith(baseUrl: baseUrl ?? _dio.options.baseUrl))); 30 | var value = _result.data! 31 | .map((dynamic i) => PostModel.fromJson(i as Map)) 32 | .toList(); 33 | return value; 34 | } 35 | 36 | RequestOptions _setStreamType(RequestOptions requestOptions) { 37 | if (T != dynamic && 38 | !(requestOptions.responseType == ResponseType.bytes || 39 | requestOptions.responseType == ResponseType.stream)) { 40 | if (T == String) { 41 | requestOptions.responseType = ResponseType.plain; 42 | } else { 43 | requestOptions.responseType = ResponseType.json; 44 | } 45 | } 46 | return requestOptions; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /lib/data/data_sources/user_local_data_source.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:shared_preferences/shared_preferences.dart'; 4 | 5 | import '../../../../core/error/exceptions.dart'; 6 | import '../models/user_model.dart'; 7 | 8 | abstract class UserLocalDataSource { 9 | /// Returns the last [UserModel]s when the last time 10 | /// user had a internet connection. 11 | /// 12 | /// Throws [CacheException] if no cached data is present. 13 | Future> getLastUsers(); 14 | 15 | Future cacheUsers(List usersToCache); 16 | } 17 | 18 | const cachedUsers = 'CACHED_USERS'; 19 | 20 | class UserLocalDataSourceImpl implements UserLocalDataSource { 21 | final SharedPreferences sharedPreferences; 22 | 23 | UserLocalDataSourceImpl(this.sharedPreferences); 24 | 25 | @override 26 | Future cacheUsers(List usersToCache) async { 27 | final usersString = []; 28 | 29 | for (var user in usersToCache) { 30 | usersString.add(json.encode(user.toJson())); 31 | } 32 | 33 | await sharedPreferences.setStringList(cachedUsers, usersString); 34 | } 35 | 36 | @override 37 | Future> getLastUsers() async { 38 | final cachedUsersString = sharedPreferences.getStringList(cachedUsers); 39 | 40 | final lastCachedUsers = []; 41 | 42 | if (cachedUsersString != null) { 43 | for (var user in cachedUsersString) { 44 | lastCachedUsers.add(UserModel.fromJson(json.decode(user))); 45 | } 46 | 47 | return lastCachedUsers; 48 | } else { 49 | throw CacheException(); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /lib/data/data_sources/user_remote_data_source.dart: -------------------------------------------------------------------------------- 1 | import 'package:dio/dio.dart'; 2 | import 'package:retrofit/http.dart'; 3 | 4 | import '../models/user_model.dart'; 5 | 6 | part 'user_remote_data_source.g.dart'; 7 | 8 | abstract class UserRemoteDataSource { 9 | /// Calls the https://jsonplaceholder.typicode.com/users endpoint. 10 | /// 11 | /// Throws a [ServerException] for all error codes. 12 | Future> getUsers(); 13 | } 14 | 15 | @RestApi(baseUrl: 'https://jsonplaceholder.typicode.com/') 16 | abstract class UserRemoteDataSourceImpl implements UserRemoteDataSource { 17 | factory UserRemoteDataSourceImpl(Dio dio, {String baseUrl}) = 18 | _UserRemoteDataSourceImpl; 19 | 20 | @GET('/users') 21 | @override 22 | Future> getUsers(); 23 | } 24 | -------------------------------------------------------------------------------- /lib/data/data_sources/user_remote_data_source.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'user_remote_data_source.dart'; 4 | 5 | // ************************************************************************** 6 | // RetrofitGenerator 7 | // ************************************************************************** 8 | 9 | class _UserRemoteDataSourceImpl implements UserRemoteDataSourceImpl { 10 | _UserRemoteDataSourceImpl(this._dio, {this.baseUrl}) { 11 | baseUrl ??= 'https://jsonplaceholder.typicode.com/'; 12 | } 13 | 14 | final Dio _dio; 15 | 16 | String? baseUrl; 17 | 18 | @override 19 | Future> getUsers() async { 20 | const _extra = {}; 21 | final queryParameters = {}; 22 | final _headers = {}; 23 | final _data = {}; 24 | final _result = await _dio.fetch>( 25 | _setStreamType>( 26 | Options(method: 'GET', headers: _headers, extra: _extra) 27 | .compose(_dio.options, '/users', 28 | queryParameters: queryParameters, data: _data) 29 | .copyWith(baseUrl: baseUrl ?? _dio.options.baseUrl))); 30 | var value = _result.data! 31 | .map((dynamic i) => UserModel.fromJson(i as Map)) 32 | .toList(); 33 | return value; 34 | } 35 | 36 | RequestOptions _setStreamType(RequestOptions requestOptions) { 37 | if (T != dynamic && 38 | !(requestOptions.responseType == ResponseType.bytes || 39 | requestOptions.responseType == ResponseType.stream)) { 40 | if (T == String) { 41 | requestOptions.responseType = ResponseType.plain; 42 | } else { 43 | requestOptions.responseType = ResponseType.json; 44 | } 45 | } 46 | return requestOptions; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /lib/data/models/post_model.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | import '../../domain/entities/post.dart'; 4 | 5 | part 'post_model.g.dart'; 6 | 7 | @JsonSerializable() 8 | class PostModel extends Post { 9 | const PostModel({ 10 | required int userId, 11 | required int id, 12 | required String title, 13 | required String body, 14 | }) : super( 15 | userId: userId, 16 | id: id, 17 | title: title, 18 | body: body, 19 | ); 20 | 21 | factory PostModel.fromJson(Map json) => 22 | _$PostModelFromJson(json); 23 | 24 | Map toJson() => _$PostModelToJson(this); 25 | } 26 | -------------------------------------------------------------------------------- /lib/data/models/post_model.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'post_model.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | PostModel _$PostModelFromJson(Map json) => PostModel( 10 | userId: json['userId'] as int, 11 | id: json['id'] as int, 12 | title: json['title'] as String, 13 | body: json['body'] as String, 14 | ); 15 | 16 | Map _$PostModelToJson(PostModel instance) => { 17 | 'userId': instance.userId, 18 | 'id': instance.id, 19 | 'title': instance.title, 20 | 'body': instance.body, 21 | }; 22 | -------------------------------------------------------------------------------- /lib/data/models/user_model.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | import '../../domain/entities/user.dart'; 4 | 5 | part 'user_model.g.dart'; 6 | 7 | @JsonSerializable() 8 | class UserModel extends User { 9 | const UserModel({ 10 | required int id, 11 | required String name, 12 | required String username, 13 | required String email, 14 | }) : super( 15 | id: id, 16 | name: name, 17 | username: username, 18 | email: email, 19 | ); 20 | 21 | factory UserModel.fromJson(Map json) => 22 | _$UserModelFromJson(json); 23 | 24 | Map toJson() => _$UserModelToJson(this); 25 | } 26 | -------------------------------------------------------------------------------- /lib/data/models/user_model.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'user_model.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | UserModel _$UserModelFromJson(Map json) => UserModel( 10 | id: json['id'] as int, 11 | name: json['name'] as String, 12 | username: json['username'] as String, 13 | email: json['email'] as String, 14 | ); 15 | 16 | Map _$UserModelToJson(UserModel instance) => { 17 | 'id': instance.id, 18 | 'name': instance.name, 19 | 'username': instance.username, 20 | 'email': instance.email, 21 | }; 22 | -------------------------------------------------------------------------------- /lib/data/repositories/post_repository_impl.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:dio/dio.dart'; 3 | 4 | import '../../core/error/failure.dart'; 5 | import '../../domain/entities/post.dart'; 6 | import '../../domain/repositories/post_repository.dart'; 7 | import '../data_sources/post_remote_data_source.dart'; 8 | 9 | class PostRepositoryImpl implements PostRepository { 10 | PostRepositoryImpl(this.postRemoteDataSource); 11 | 12 | final PostRemoteDataSource postRemoteDataSource; 13 | 14 | @override 15 | Future>> getUserPosts(int userId) async { 16 | try { 17 | return Right(await postRemoteDataSource.getUserPosts(userId)); 18 | } on DioError { 19 | return Left(ServerFailure()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lib/data/repositories/user_repository_impl.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:dio/dio.dart'; 3 | 4 | import '../../../../core/error/exceptions.dart'; 5 | import '../../../../core/error/failure.dart'; 6 | import '../../../../core/network/network_info.dart'; 7 | import '../../domain/entities/user.dart'; 8 | import '../../domain/repositories/user_repository.dart'; 9 | import '../data_sources/user_local_data_source.dart'; 10 | import '../data_sources/user_remote_data_source.dart'; 11 | 12 | class UserRepositoryImpl implements UserRepository { 13 | final UserRemoteDataSource remoteDataSource; 14 | final UserLocalDataSource localDataSource; 15 | final NetworkInfo networkInfo; 16 | 17 | UserRepositoryImpl({ 18 | required this.remoteDataSource, 19 | required this.localDataSource, 20 | required this.networkInfo, 21 | }); 22 | 23 | @override 24 | Future>> getUsers() async { 25 | if (await networkInfo.isConnected) { 26 | try { 27 | final users = await remoteDataSource.getUsers(); 28 | localDataSource.cacheUsers(users); 29 | 30 | return Right(users); 31 | } on DioError { 32 | return Left(ServerFailure()); 33 | } 34 | } else { 35 | try { 36 | return Right(await localDataSource.getLastUsers()); 37 | } on CacheException { 38 | return Left(CacheFailure()); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /lib/domain/entities/post.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | 3 | class Post extends Equatable { 4 | final int userId; 5 | final int id; 6 | final String title; 7 | final String body; 8 | 9 | const Post({ 10 | required this.userId, 11 | required this.id, 12 | required this.title, 13 | required this.body, 14 | }); 15 | 16 | @override 17 | List get props => [userId, id, title, body]; 18 | } 19 | -------------------------------------------------------------------------------- /lib/domain/entities/user.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | 3 | class User extends Equatable { 4 | final int id; 5 | final String name; 6 | final String username; 7 | final String email; 8 | 9 | const User({ 10 | required this.id, 11 | required this.name, 12 | required this.username, 13 | required this.email, 14 | }); 15 | 16 | @override 17 | List get props => [id, name, username, email]; 18 | } 19 | -------------------------------------------------------------------------------- /lib/domain/repositories/post_repository.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | 3 | import '../../core/error/failure.dart'; 4 | import '../entities/post.dart'; 5 | 6 | abstract class PostRepository { 7 | Future>> getUserPosts(int userId); 8 | } 9 | -------------------------------------------------------------------------------- /lib/domain/repositories/user_repository.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | 3 | import '../../../../core/error/failure.dart'; 4 | import '../entities/user.dart'; 5 | 6 | abstract class UserRepository { 7 | Future>> getUsers(); 8 | } 9 | -------------------------------------------------------------------------------- /lib/domain/use_cases/get_user_posts.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | 3 | import '../../../../core/error/failure.dart'; 4 | import '../../../../core/usecases/usecase.dart'; 5 | import '../entities/post.dart'; 6 | import '../repositories/post_repository.dart'; 7 | 8 | class GetUserPosts implements Usecase, int> { 9 | final PostRepository postRepository; 10 | 11 | GetUserPosts(this.postRepository); 12 | 13 | @override 14 | Future>> call(int userId) => 15 | postRepository.getUserPosts(userId); 16 | } 17 | -------------------------------------------------------------------------------- /lib/domain/use_cases/get_users.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | 3 | import '../../../../core/error/failure.dart'; 4 | import '../../../../core/no_params.dart'; 5 | import '../../../../core/usecases/usecase.dart'; 6 | import '../entities/user.dart'; 7 | import '../repositories/user_repository.dart'; 8 | 9 | class GetUsers implements Usecase, NoParams> { 10 | final UserRepository userRepository; 11 | 12 | GetUsers(this.userRepository); 13 | 14 | @override 15 | Future>> call(NoParams params) => 16 | userRepository.getUsers(); 17 | } 18 | -------------------------------------------------------------------------------- /lib/injection_container.dart: -------------------------------------------------------------------------------- 1 | import 'package:connectivity_plus/connectivity_plus.dart'; 2 | import 'package:dio/dio.dart'; 3 | import 'package:get_it/get_it.dart'; 4 | import 'package:shared_preferences/shared_preferences.dart'; 5 | 6 | import 'core/network/network_info.dart'; 7 | import 'data/data_sources/post_remote_data_source.dart'; 8 | import 'data/data_sources/user_local_data_source.dart'; 9 | import 'data/data_sources/user_remote_data_source.dart'; 10 | import 'data/repositories/post_repository_impl.dart'; 11 | import 'data/repositories/user_repository_impl.dart'; 12 | import 'domain/repositories/post_repository.dart'; 13 | import 'domain/repositories/user_repository.dart'; 14 | import 'domain/use_cases/get_user_posts.dart'; 15 | import 'domain/use_cases/get_users.dart'; 16 | import 'presentation/bloc/user_posts_cubit.dart'; 17 | import 'presentation/bloc/users_cubit.dart'; 18 | 19 | final getIt = GetIt.instance; 20 | 21 | Future init() async { 22 | initBlocs(); 23 | initUseCases(); 24 | initRepositories(); 25 | initDataSources(); 26 | initCores(); 27 | await initExternals(); 28 | } 29 | 30 | void initBlocs() { 31 | getIt.registerFactory(() => UsersCubit(getIt())); 32 | getIt.registerFactory(() => UserPostsCubit(getIt())); 33 | } 34 | 35 | void initUseCases() { 36 | getIt.registerLazySingleton(() => GetUsers(getIt())); 37 | getIt.registerLazySingleton(() => GetUserPosts(getIt())); 38 | } 39 | 40 | void initRepositories() { 41 | getIt.registerLazySingleton( 42 | () => UserRepositoryImpl( 43 | remoteDataSource: getIt(), 44 | localDataSource: getIt(), 45 | networkInfo: getIt(), 46 | ), 47 | ); 48 | 49 | getIt.registerLazySingleton( 50 | () => PostRepositoryImpl(getIt()), 51 | ); 52 | } 53 | 54 | void initDataSources() { 55 | getIt.registerLazySingleton( 56 | () => UserRemoteDataSourceImpl(getIt()), 57 | ); 58 | 59 | getIt.registerLazySingleton( 60 | () => UserLocalDataSourceImpl(getIt()), 61 | ); 62 | 63 | getIt.registerLazySingleton( 64 | () => PostRemoteDataSourceImpl(getIt()), 65 | ); 66 | } 67 | 68 | void initCores() { 69 | getIt.registerLazySingleton( 70 | () => NetworkInfoImpl(getIt()), 71 | ); 72 | } 73 | 74 | Future initExternals() async { 75 | final prefs = await SharedPreferences.getInstance(); 76 | getIt.registerLazySingleton(() => prefs); 77 | 78 | getIt.registerLazySingleton(() => Dio()); 79 | 80 | getIt.registerLazySingleton(() => Connectivity()); 81 | } 82 | -------------------------------------------------------------------------------- /lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | import 'injection_container.dart' as di; 4 | import 'presentation/app_router.dart'; 5 | import 'presentation/pages/users_page.dart'; 6 | 7 | void main() async { 8 | WidgetsFlutterBinding.ensureInitialized(); 9 | await di.init(); 10 | runApp(const MyApp()); 11 | } 12 | 13 | class MyApp extends StatelessWidget { 14 | const MyApp({Key? key}) : super(key: key); 15 | 16 | @override 17 | Widget build(BuildContext context) { 18 | return MaterialApp( 19 | title: 'Flutter Demo', 20 | theme: ThemeData( 21 | primarySwatch: Colors.indigo, 22 | ), 23 | home: const UsersPage(), 24 | onGenerateRoute: AppRouter.onGenerateRoute, 25 | ); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/presentation/app_router.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_bloc/flutter_bloc.dart'; 3 | 4 | import '../injection_container.dart'; 5 | import 'bloc/user_posts_cubit.dart'; 6 | import 'pages/user_posts_page.dart'; 7 | 8 | abstract class Routes { 9 | static const userPosts = '/userPosts'; 10 | } 11 | 12 | abstract class AppRouter { 13 | const AppRouter._(); 14 | 15 | static Route onGenerateRoute(RouteSettings settings) { 16 | final arguments = settings.arguments; 17 | 18 | switch (settings.name) { 19 | case Routes.userPosts: 20 | assert(arguments != null); 21 | assert(arguments is int); 22 | 23 | return MaterialPageRoute(builder: (_) { 24 | return BlocProvider( 25 | create: (_) => getIt() 26 | ..fetchUserPosts( 27 | arguments! as int, 28 | ), 29 | child: const UserPostsPage(), 30 | ); 31 | }); 32 | 33 | default: 34 | return MaterialPageRoute( 35 | builder: (_) { 36 | return Scaffold( 37 | body: Center( 38 | child: Text('${settings.name} page is not found!'), 39 | ), 40 | ); 41 | }, 42 | ); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/presentation/bloc/user_posts_cubit.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_bloc/flutter_bloc.dart'; 2 | 3 | import '../../core/states/data_state.dart'; 4 | import '../../domain/entities/post.dart'; 5 | import '../../domain/use_cases/get_user_posts.dart'; 6 | 7 | class UserPostsCubit extends Cubit>> { 8 | UserPostsCubit(this.getUserPosts) : super(DataState.initial()); 9 | 10 | final GetUserPosts getUserPosts; 11 | 12 | void fetchUserPosts(int userId) async { 13 | emit(DataState.inProgress()); 14 | 15 | final result = await getUserPosts(userId); 16 | 17 | result.fold( 18 | (failure) => emit(DataState.failure()), 19 | (success) { 20 | emit(success.isEmpty ? DataState.empty() : DataState.success(success)); 21 | }, 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lib/presentation/bloc/users_cubit.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_bloc/flutter_bloc.dart'; 2 | 3 | import '../../../../core/no_params.dart'; 4 | import '../../../../core/states/data_state.dart'; 5 | import '../../domain/entities/user.dart'; 6 | import '../../domain/use_cases/get_users.dart'; 7 | 8 | export '../../../../core/states/data_state.dart'; 9 | 10 | class UsersCubit extends Cubit>> { 11 | final GetUsers getUsers; 12 | 13 | UsersCubit(this.getUsers) : super(DataState.initial()); 14 | 15 | void fetchUsers() async { 16 | emit(DataState.inProgress()); 17 | 18 | final result = await getUsers(const NoParams()); 19 | 20 | result.fold( 21 | (failure) => emit(DataState.failure()), 22 | (success) => emit( 23 | success.isEmpty ? DataState.empty() : DataState.success(success), 24 | ), 25 | ); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/presentation/pages/user_posts_page.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_bloc/flutter_bloc.dart'; 3 | 4 | import '../../core/states/data_state.dart'; 5 | import '../../domain/entities/post.dart'; 6 | import '../bloc/user_posts_cubit.dart'; 7 | import '../widgets/failure_widget.dart'; 8 | import '../widgets/list_item.dart'; 9 | import '../widgets/loading_widget.dart'; 10 | 11 | class UserPostsPage extends StatelessWidget { 12 | const UserPostsPage({Key? key}) : super(key: key); 13 | 14 | @override 15 | Widget build(BuildContext context) { 16 | return BlocBuilder>>( 17 | builder: (context, state) { 18 | late final Widget body; 19 | 20 | if (state.isInProgress) { 21 | body = const LoadingWidget(); 22 | } else if (state.isFailure) { 23 | body = const FailureWidget(); 24 | } else if (state.isEmpty) { 25 | body = const Text('No Post!'); 26 | } else if (state.isSuccess) { 27 | body = ListView.builder( 28 | itemBuilder: (_, index) { 29 | final userPost = state.data![index]; 30 | 31 | return ListItem( 32 | leading: '${userPost.id}', 33 | title: userPost.title, 34 | body: userPost.body, 35 | ); 36 | }, 37 | itemCount: state.data!.length, 38 | ); 39 | } else { 40 | body = const SizedBox.shrink(); 41 | } 42 | 43 | return Scaffold( 44 | appBar: AppBar( 45 | title: const Text('Posts'), 46 | ), 47 | body: body, 48 | ); 49 | }, 50 | ); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /lib/presentation/pages/users_page.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_bloc/flutter_bloc.dart'; 3 | 4 | import '../../../../injection_container.dart'; 5 | import '../../domain/entities/user.dart'; 6 | import '../app_router.dart'; 7 | import '../bloc/users_cubit.dart'; 8 | import '../widgets/failure_widget.dart'; 9 | import '../widgets/list_item.dart'; 10 | import '../widgets/loading_widget.dart'; 11 | 12 | class UsersPage extends StatelessWidget { 13 | const UsersPage({Key? key}) : super(key: key); 14 | 15 | @override 16 | Widget build(BuildContext context) { 17 | return BlocProvider( 18 | create: (_) => getIt()..fetchUsers(), 19 | child: Scaffold( 20 | appBar: AppBar( 21 | title: const Text('Users'), 22 | ), 23 | body: BlocBuilder>>( 24 | builder: (context, state) { 25 | if (state.isInProgress) { 26 | return const LoadingWidget(); 27 | } else if (state.isFailure) { 28 | return const FailureWidget(); 29 | } else if (state.isEmpty) { 30 | return const Text('No User!'); 31 | } else if (state.isSuccess) { 32 | return ListView.builder( 33 | itemBuilder: (_, index) { 34 | final user = state.data![index]; 35 | 36 | return ListItem( 37 | leading: '${user.id}', 38 | title: user.name, 39 | body: user.email, 40 | onTap: () { 41 | Navigator.pushNamed( 42 | context, 43 | Routes.userPosts, 44 | arguments: user.id, 45 | ); 46 | }, 47 | ); 48 | }, 49 | itemCount: state.data!.length, 50 | ); 51 | } else { 52 | return const SizedBox.shrink(); 53 | } 54 | }, 55 | ), 56 | ), 57 | ); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /lib/presentation/widgets/failure_widget.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class FailureWidget extends StatelessWidget { 4 | const FailureWidget({ 5 | Key? key, 6 | this.message, 7 | }) : super(key: key); 8 | 9 | final String? message; 10 | 11 | @override 12 | Widget build(BuildContext context) { 13 | return Center( 14 | child: Text( 15 | message ?? 'Something went wrong!', 16 | style: Theme.of(context).textTheme.bodyText1, 17 | ), 18 | ); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/presentation/widgets/list_item.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class ListItem extends StatelessWidget { 4 | const ListItem({ 5 | Key? key, 6 | required this.leading, 7 | required this.title, 8 | required this.body, 9 | this.onTap, 10 | }) : super(key: key); 11 | 12 | final String leading; 13 | final String title; 14 | final String body; 15 | final VoidCallback? onTap; 16 | 17 | @override 18 | Widget build(BuildContext context) { 19 | return ListTile( 20 | onTap: onTap, 21 | leading: CircleAvatar( 22 | child: Text(leading), 23 | ), 24 | title: Text(title), 25 | subtitle: Text(body), 26 | ); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/presentation/widgets/loading_widget.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class LoadingWidget extends StatelessWidget { 4 | const LoadingWidget({Key? key}) : super(key: key); 5 | 6 | @override 7 | Widget build(BuildContext context) { 8 | return const Center( 9 | child: CircularProgressIndicator(), 10 | ); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | _fe_analyzer_shared: 5 | dependency: transitive 6 | description: 7 | name: _fe_analyzer_shared 8 | url: "https://pub.dartlang.org" 9 | source: hosted 10 | version: "31.0.0" 11 | analyzer: 12 | dependency: transitive 13 | description: 14 | name: analyzer 15 | url: "https://pub.dartlang.org" 16 | source: hosted 17 | version: "2.8.0" 18 | args: 19 | dependency: transitive 20 | description: 21 | name: args 22 | url: "https://pub.dartlang.org" 23 | source: hosted 24 | version: "2.3.0" 25 | async: 26 | dependency: transitive 27 | description: 28 | name: async 29 | url: "https://pub.dartlang.org" 30 | source: hosted 31 | version: "2.8.2" 32 | bloc: 33 | dependency: transitive 34 | description: 35 | name: bloc 36 | url: "https://pub.dartlang.org" 37 | source: hosted 38 | version: "8.0.1" 39 | bloc_test: 40 | dependency: "direct dev" 41 | description: 42 | name: bloc_test 43 | url: "https://pub.dartlang.org" 44 | source: hosted 45 | version: "9.0.1" 46 | boolean_selector: 47 | dependency: transitive 48 | description: 49 | name: boolean_selector 50 | url: "https://pub.dartlang.org" 51 | source: hosted 52 | version: "2.1.0" 53 | build: 54 | dependency: transitive 55 | description: 56 | name: build 57 | url: "https://pub.dartlang.org" 58 | source: hosted 59 | version: "2.2.0" 60 | build_config: 61 | dependency: transitive 62 | description: 63 | name: build_config 64 | url: "https://pub.dartlang.org" 65 | source: hosted 66 | version: "1.0.0" 67 | build_daemon: 68 | dependency: transitive 69 | description: 70 | name: build_daemon 71 | url: "https://pub.dartlang.org" 72 | source: hosted 73 | version: "3.0.1" 74 | build_resolvers: 75 | dependency: transitive 76 | description: 77 | name: build_resolvers 78 | url: "https://pub.dartlang.org" 79 | source: hosted 80 | version: "2.0.6" 81 | build_runner: 82 | dependency: "direct dev" 83 | description: 84 | name: build_runner 85 | url: "https://pub.dartlang.org" 86 | source: hosted 87 | version: "2.1.7" 88 | build_runner_core: 89 | dependency: transitive 90 | description: 91 | name: build_runner_core 92 | url: "https://pub.dartlang.org" 93 | source: hosted 94 | version: "7.2.3" 95 | built_collection: 96 | dependency: transitive 97 | description: 98 | name: built_collection 99 | url: "https://pub.dartlang.org" 100 | source: hosted 101 | version: "5.1.1" 102 | built_value: 103 | dependency: transitive 104 | description: 105 | name: built_value 106 | url: "https://pub.dartlang.org" 107 | source: hosted 108 | version: "8.1.3" 109 | characters: 110 | dependency: transitive 111 | description: 112 | name: characters 113 | url: "https://pub.dartlang.org" 114 | source: hosted 115 | version: "1.2.0" 116 | charcode: 117 | dependency: transitive 118 | description: 119 | name: charcode 120 | url: "https://pub.dartlang.org" 121 | source: hosted 122 | version: "1.3.1" 123 | checked_yaml: 124 | dependency: transitive 125 | description: 126 | name: checked_yaml 127 | url: "https://pub.dartlang.org" 128 | source: hosted 129 | version: "2.0.1" 130 | cli_util: 131 | dependency: transitive 132 | description: 133 | name: cli_util 134 | url: "https://pub.dartlang.org" 135 | source: hosted 136 | version: "0.3.5" 137 | clock: 138 | dependency: transitive 139 | description: 140 | name: clock 141 | url: "https://pub.dartlang.org" 142 | source: hosted 143 | version: "1.1.0" 144 | code_builder: 145 | dependency: transitive 146 | description: 147 | name: code_builder 148 | url: "https://pub.dartlang.org" 149 | source: hosted 150 | version: "4.1.0" 151 | collection: 152 | dependency: transitive 153 | description: 154 | name: collection 155 | url: "https://pub.dartlang.org" 156 | source: hosted 157 | version: "1.15.0" 158 | connectivity_plus: 159 | dependency: "direct main" 160 | description: 161 | name: connectivity_plus 162 | url: "https://pub.dartlang.org" 163 | source: hosted 164 | version: "2.1.0" 165 | connectivity_plus_linux: 166 | dependency: transitive 167 | description: 168 | name: connectivity_plus_linux 169 | url: "https://pub.dartlang.org" 170 | source: hosted 171 | version: "1.1.1" 172 | connectivity_plus_macos: 173 | dependency: transitive 174 | description: 175 | name: connectivity_plus_macos 176 | url: "https://pub.dartlang.org" 177 | source: hosted 178 | version: "1.2.1" 179 | connectivity_plus_platform_interface: 180 | dependency: transitive 181 | description: 182 | name: connectivity_plus_platform_interface 183 | url: "https://pub.dartlang.org" 184 | source: hosted 185 | version: "1.1.1" 186 | connectivity_plus_web: 187 | dependency: transitive 188 | description: 189 | name: connectivity_plus_web 190 | url: "https://pub.dartlang.org" 191 | source: hosted 192 | version: "1.1.0+1" 193 | connectivity_plus_windows: 194 | dependency: transitive 195 | description: 196 | name: connectivity_plus_windows 197 | url: "https://pub.dartlang.org" 198 | source: hosted 199 | version: "1.2.0" 200 | convert: 201 | dependency: transitive 202 | description: 203 | name: convert 204 | url: "https://pub.dartlang.org" 205 | source: hosted 206 | version: "3.0.1" 207 | coverage: 208 | dependency: transitive 209 | description: 210 | name: coverage 211 | url: "https://pub.dartlang.org" 212 | source: hosted 213 | version: "1.0.3" 214 | crypto: 215 | dependency: transitive 216 | description: 217 | name: crypto 218 | url: "https://pub.dartlang.org" 219 | source: hosted 220 | version: "3.0.1" 221 | cupertino_icons: 222 | dependency: "direct main" 223 | description: 224 | name: cupertino_icons 225 | url: "https://pub.dartlang.org" 226 | source: hosted 227 | version: "1.0.4" 228 | dart_style: 229 | dependency: transitive 230 | description: 231 | name: dart_style 232 | url: "https://pub.dartlang.org" 233 | source: hosted 234 | version: "2.2.1" 235 | dartz: 236 | dependency: "direct main" 237 | description: 238 | name: dartz 239 | url: "https://pub.dartlang.org" 240 | source: hosted 241 | version: "0.10.1" 242 | dbus: 243 | dependency: transitive 244 | description: 245 | name: dbus 246 | url: "https://pub.dartlang.org" 247 | source: hosted 248 | version: "0.6.6" 249 | diff_match_patch: 250 | dependency: transitive 251 | description: 252 | name: diff_match_patch 253 | url: "https://pub.dartlang.org" 254 | source: hosted 255 | version: "0.4.1" 256 | dio: 257 | dependency: transitive 258 | description: 259 | name: dio 260 | url: "https://pub.dartlang.org" 261 | source: hosted 262 | version: "4.0.4" 263 | equatable: 264 | dependency: "direct main" 265 | description: 266 | name: equatable 267 | url: "https://pub.dartlang.org" 268 | source: hosted 269 | version: "2.0.3" 270 | fake_async: 271 | dependency: transitive 272 | description: 273 | name: fake_async 274 | url: "https://pub.dartlang.org" 275 | source: hosted 276 | version: "1.2.0" 277 | ffi: 278 | dependency: transitive 279 | description: 280 | name: ffi 281 | url: "https://pub.dartlang.org" 282 | source: hosted 283 | version: "1.1.2" 284 | file: 285 | dependency: transitive 286 | description: 287 | name: file 288 | url: "https://pub.dartlang.org" 289 | source: hosted 290 | version: "6.1.2" 291 | fixnum: 292 | dependency: transitive 293 | description: 294 | name: fixnum 295 | url: "https://pub.dartlang.org" 296 | source: hosted 297 | version: "1.0.0" 298 | flutter: 299 | dependency: "direct main" 300 | description: flutter 301 | source: sdk 302 | version: "0.0.0" 303 | flutter_bloc: 304 | dependency: "direct main" 305 | description: 306 | name: flutter_bloc 307 | url: "https://pub.dartlang.org" 308 | source: hosted 309 | version: "8.0.0" 310 | flutter_lints: 311 | dependency: "direct dev" 312 | description: 313 | name: flutter_lints 314 | url: "https://pub.dartlang.org" 315 | source: hosted 316 | version: "1.0.4" 317 | flutter_test: 318 | dependency: "direct dev" 319 | description: flutter 320 | source: sdk 321 | version: "0.0.0" 322 | flutter_web_plugins: 323 | dependency: transitive 324 | description: flutter 325 | source: sdk 326 | version: "0.0.0" 327 | frontend_server_client: 328 | dependency: transitive 329 | description: 330 | name: frontend_server_client 331 | url: "https://pub.dartlang.org" 332 | source: hosted 333 | version: "2.1.2" 334 | get_it: 335 | dependency: "direct main" 336 | description: 337 | name: get_it 338 | url: "https://pub.dartlang.org" 339 | source: hosted 340 | version: "7.2.0" 341 | glob: 342 | dependency: transitive 343 | description: 344 | name: glob 345 | url: "https://pub.dartlang.org" 346 | source: hosted 347 | version: "2.0.2" 348 | graphs: 349 | dependency: transitive 350 | description: 351 | name: graphs 352 | url: "https://pub.dartlang.org" 353 | source: hosted 354 | version: "2.1.0" 355 | http_multi_server: 356 | dependency: transitive 357 | description: 358 | name: http_multi_server 359 | url: "https://pub.dartlang.org" 360 | source: hosted 361 | version: "3.0.1" 362 | http_parser: 363 | dependency: transitive 364 | description: 365 | name: http_parser 366 | url: "https://pub.dartlang.org" 367 | source: hosted 368 | version: "4.0.0" 369 | io: 370 | dependency: transitive 371 | description: 372 | name: io 373 | url: "https://pub.dartlang.org" 374 | source: hosted 375 | version: "1.0.3" 376 | js: 377 | dependency: transitive 378 | description: 379 | name: js 380 | url: "https://pub.dartlang.org" 381 | source: hosted 382 | version: "0.6.3" 383 | json_annotation: 384 | dependency: transitive 385 | description: 386 | name: json_annotation 387 | url: "https://pub.dartlang.org" 388 | source: hosted 389 | version: "4.4.0" 390 | json_serializable: 391 | dependency: "direct main" 392 | description: 393 | name: json_serializable 394 | url: "https://pub.dartlang.org" 395 | source: hosted 396 | version: "6.1.3" 397 | lints: 398 | dependency: transitive 399 | description: 400 | name: lints 401 | url: "https://pub.dartlang.org" 402 | source: hosted 403 | version: "1.0.1" 404 | logging: 405 | dependency: transitive 406 | description: 407 | name: logging 408 | url: "https://pub.dartlang.org" 409 | source: hosted 410 | version: "1.0.2" 411 | matcher: 412 | dependency: transitive 413 | description: 414 | name: matcher 415 | url: "https://pub.dartlang.org" 416 | source: hosted 417 | version: "0.12.11" 418 | meta: 419 | dependency: transitive 420 | description: 421 | name: meta 422 | url: "https://pub.dartlang.org" 423 | source: hosted 424 | version: "1.7.0" 425 | mime: 426 | dependency: transitive 427 | description: 428 | name: mime 429 | url: "https://pub.dartlang.org" 430 | source: hosted 431 | version: "1.0.1" 432 | mockito: 433 | dependency: "direct dev" 434 | description: 435 | name: mockito 436 | url: "https://pub.dartlang.org" 437 | source: hosted 438 | version: "5.0.16" 439 | mocktail: 440 | dependency: transitive 441 | description: 442 | name: mocktail 443 | url: "https://pub.dartlang.org" 444 | source: hosted 445 | version: "0.2.0" 446 | nested: 447 | dependency: transitive 448 | description: 449 | name: nested 450 | url: "https://pub.dartlang.org" 451 | source: hosted 452 | version: "1.0.0" 453 | nm: 454 | dependency: transitive 455 | description: 456 | name: nm 457 | url: "https://pub.dartlang.org" 458 | source: hosted 459 | version: "0.4.2" 460 | node_preamble: 461 | dependency: transitive 462 | description: 463 | name: node_preamble 464 | url: "https://pub.dartlang.org" 465 | source: hosted 466 | version: "2.0.1" 467 | package_config: 468 | dependency: transitive 469 | description: 470 | name: package_config 471 | url: "https://pub.dartlang.org" 472 | source: hosted 473 | version: "2.0.2" 474 | path: 475 | dependency: transitive 476 | description: 477 | name: path 478 | url: "https://pub.dartlang.org" 479 | source: hosted 480 | version: "1.8.0" 481 | path_provider_linux: 482 | dependency: transitive 483 | description: 484 | name: path_provider_linux 485 | url: "https://pub.dartlang.org" 486 | source: hosted 487 | version: "2.1.4" 488 | path_provider_platform_interface: 489 | dependency: transitive 490 | description: 491 | name: path_provider_platform_interface 492 | url: "https://pub.dartlang.org" 493 | source: hosted 494 | version: "2.0.1" 495 | path_provider_windows: 496 | dependency: transitive 497 | description: 498 | name: path_provider_windows 499 | url: "https://pub.dartlang.org" 500 | source: hosted 501 | version: "2.0.4" 502 | pedantic: 503 | dependency: transitive 504 | description: 505 | name: pedantic 506 | url: "https://pub.dartlang.org" 507 | source: hosted 508 | version: "1.11.1" 509 | petitparser: 510 | dependency: transitive 511 | description: 512 | name: petitparser 513 | url: "https://pub.dartlang.org" 514 | source: hosted 515 | version: "4.4.0" 516 | platform: 517 | dependency: transitive 518 | description: 519 | name: platform 520 | url: "https://pub.dartlang.org" 521 | source: hosted 522 | version: "3.1.0" 523 | plugin_platform_interface: 524 | dependency: transitive 525 | description: 526 | name: plugin_platform_interface 527 | url: "https://pub.dartlang.org" 528 | source: hosted 529 | version: "2.0.2" 530 | pool: 531 | dependency: transitive 532 | description: 533 | name: pool 534 | url: "https://pub.dartlang.org" 535 | source: hosted 536 | version: "1.5.0" 537 | process: 538 | dependency: transitive 539 | description: 540 | name: process 541 | url: "https://pub.dartlang.org" 542 | source: hosted 543 | version: "4.2.4" 544 | provider: 545 | dependency: transitive 546 | description: 547 | name: provider 548 | url: "https://pub.dartlang.org" 549 | source: hosted 550 | version: "6.0.1" 551 | pub_semver: 552 | dependency: transitive 553 | description: 554 | name: pub_semver 555 | url: "https://pub.dartlang.org" 556 | source: hosted 557 | version: "2.1.0" 558 | pubspec_parse: 559 | dependency: transitive 560 | description: 561 | name: pubspec_parse 562 | url: "https://pub.dartlang.org" 563 | source: hosted 564 | version: "1.2.0" 565 | quiver: 566 | dependency: transitive 567 | description: 568 | name: quiver 569 | url: "https://pub.dartlang.org" 570 | source: hosted 571 | version: "3.0.1+1" 572 | retrofit: 573 | dependency: "direct main" 574 | description: 575 | name: retrofit 576 | url: "https://pub.dartlang.org" 577 | source: hosted 578 | version: "3.0.0" 579 | retrofit_generator: 580 | dependency: "direct dev" 581 | description: 582 | name: retrofit_generator 583 | url: "https://pub.dartlang.org" 584 | source: hosted 585 | version: "3.0.0+2" 586 | shared_preferences: 587 | dependency: "direct main" 588 | description: 589 | name: shared_preferences 590 | url: "https://pub.dartlang.org" 591 | source: hosted 592 | version: "2.0.11" 593 | shared_preferences_android: 594 | dependency: transitive 595 | description: 596 | name: shared_preferences_android 597 | url: "https://pub.dartlang.org" 598 | source: hosted 599 | version: "2.0.9" 600 | shared_preferences_ios: 601 | dependency: transitive 602 | description: 603 | name: shared_preferences_ios 604 | url: "https://pub.dartlang.org" 605 | source: hosted 606 | version: "2.0.8" 607 | shared_preferences_linux: 608 | dependency: transitive 609 | description: 610 | name: shared_preferences_linux 611 | url: "https://pub.dartlang.org" 612 | source: hosted 613 | version: "2.0.3" 614 | shared_preferences_macos: 615 | dependency: transitive 616 | description: 617 | name: shared_preferences_macos 618 | url: "https://pub.dartlang.org" 619 | source: hosted 620 | version: "2.0.2" 621 | shared_preferences_platform_interface: 622 | dependency: transitive 623 | description: 624 | name: shared_preferences_platform_interface 625 | url: "https://pub.dartlang.org" 626 | source: hosted 627 | version: "2.0.0" 628 | shared_preferences_web: 629 | dependency: transitive 630 | description: 631 | name: shared_preferences_web 632 | url: "https://pub.dartlang.org" 633 | source: hosted 634 | version: "2.0.2" 635 | shared_preferences_windows: 636 | dependency: transitive 637 | description: 638 | name: shared_preferences_windows 639 | url: "https://pub.dartlang.org" 640 | source: hosted 641 | version: "2.0.3" 642 | shelf: 643 | dependency: transitive 644 | description: 645 | name: shelf 646 | url: "https://pub.dartlang.org" 647 | source: hosted 648 | version: "1.2.0" 649 | shelf_packages_handler: 650 | dependency: transitive 651 | description: 652 | name: shelf_packages_handler 653 | url: "https://pub.dartlang.org" 654 | source: hosted 655 | version: "3.0.0" 656 | shelf_static: 657 | dependency: transitive 658 | description: 659 | name: shelf_static 660 | url: "https://pub.dartlang.org" 661 | source: hosted 662 | version: "1.1.0" 663 | shelf_web_socket: 664 | dependency: transitive 665 | description: 666 | name: shelf_web_socket 667 | url: "https://pub.dartlang.org" 668 | source: hosted 669 | version: "1.0.1" 670 | sky_engine: 671 | dependency: transitive 672 | description: flutter 673 | source: sdk 674 | version: "0.0.99" 675 | source_gen: 676 | dependency: transitive 677 | description: 678 | name: source_gen 679 | url: "https://pub.dartlang.org" 680 | source: hosted 681 | version: "1.2.1" 682 | source_helper: 683 | dependency: transitive 684 | description: 685 | name: source_helper 686 | url: "https://pub.dartlang.org" 687 | source: hosted 688 | version: "1.3.1" 689 | source_map_stack_trace: 690 | dependency: transitive 691 | description: 692 | name: source_map_stack_trace 693 | url: "https://pub.dartlang.org" 694 | source: hosted 695 | version: "2.1.0" 696 | source_maps: 697 | dependency: transitive 698 | description: 699 | name: source_maps 700 | url: "https://pub.dartlang.org" 701 | source: hosted 702 | version: "0.10.10" 703 | source_span: 704 | dependency: transitive 705 | description: 706 | name: source_span 707 | url: "https://pub.dartlang.org" 708 | source: hosted 709 | version: "1.8.1" 710 | stack_trace: 711 | dependency: transitive 712 | description: 713 | name: stack_trace 714 | url: "https://pub.dartlang.org" 715 | source: hosted 716 | version: "1.10.0" 717 | stream_channel: 718 | dependency: transitive 719 | description: 720 | name: stream_channel 721 | url: "https://pub.dartlang.org" 722 | source: hosted 723 | version: "2.1.0" 724 | stream_transform: 725 | dependency: transitive 726 | description: 727 | name: stream_transform 728 | url: "https://pub.dartlang.org" 729 | source: hosted 730 | version: "2.0.0" 731 | string_scanner: 732 | dependency: transitive 733 | description: 734 | name: string_scanner 735 | url: "https://pub.dartlang.org" 736 | source: hosted 737 | version: "1.1.0" 738 | term_glyph: 739 | dependency: transitive 740 | description: 741 | name: term_glyph 742 | url: "https://pub.dartlang.org" 743 | source: hosted 744 | version: "1.2.0" 745 | test: 746 | dependency: transitive 747 | description: 748 | name: test 749 | url: "https://pub.dartlang.org" 750 | source: hosted 751 | version: "1.17.12" 752 | test_api: 753 | dependency: transitive 754 | description: 755 | name: test_api 756 | url: "https://pub.dartlang.org" 757 | source: hosted 758 | version: "0.4.3" 759 | test_core: 760 | dependency: transitive 761 | description: 762 | name: test_core 763 | url: "https://pub.dartlang.org" 764 | source: hosted 765 | version: "0.4.2" 766 | timing: 767 | dependency: transitive 768 | description: 769 | name: timing 770 | url: "https://pub.dartlang.org" 771 | source: hosted 772 | version: "1.0.0" 773 | tuple: 774 | dependency: transitive 775 | description: 776 | name: tuple 777 | url: "https://pub.dartlang.org" 778 | source: hosted 779 | version: "2.0.0" 780 | typed_data: 781 | dependency: transitive 782 | description: 783 | name: typed_data 784 | url: "https://pub.dartlang.org" 785 | source: hosted 786 | version: "1.3.0" 787 | vector_math: 788 | dependency: transitive 789 | description: 790 | name: vector_math 791 | url: "https://pub.dartlang.org" 792 | source: hosted 793 | version: "2.1.1" 794 | vm_service: 795 | dependency: transitive 796 | description: 797 | name: vm_service 798 | url: "https://pub.dartlang.org" 799 | source: hosted 800 | version: "7.5.0" 801 | watcher: 802 | dependency: transitive 803 | description: 804 | name: watcher 805 | url: "https://pub.dartlang.org" 806 | source: hosted 807 | version: "1.0.1" 808 | web_socket_channel: 809 | dependency: transitive 810 | description: 811 | name: web_socket_channel 812 | url: "https://pub.dartlang.org" 813 | source: hosted 814 | version: "2.1.0" 815 | webkit_inspection_protocol: 816 | dependency: transitive 817 | description: 818 | name: webkit_inspection_protocol 819 | url: "https://pub.dartlang.org" 820 | source: hosted 821 | version: "1.0.0" 822 | win32: 823 | dependency: transitive 824 | description: 825 | name: win32 826 | url: "https://pub.dartlang.org" 827 | source: hosted 828 | version: "2.3.1" 829 | xdg_directories: 830 | dependency: transitive 831 | description: 832 | name: xdg_directories 833 | url: "https://pub.dartlang.org" 834 | source: hosted 835 | version: "0.2.0" 836 | xml: 837 | dependency: transitive 838 | description: 839 | name: xml 840 | url: "https://pub.dartlang.org" 841 | source: hosted 842 | version: "5.3.1" 843 | yaml: 844 | dependency: transitive 845 | description: 846 | name: yaml 847 | url: "https://pub.dartlang.org" 848 | source: hosted 849 | version: "3.1.0" 850 | sdks: 851 | dart: ">=2.15.0 <3.0.0" 852 | flutter: ">=2.5.0" 853 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: tdd_example 2 | description: A new Flutter project. 3 | 4 | publish_to: 'none' # Remove this line if you wish to publish to pub.dev 5 | 6 | version: 1.0.0+1 7 | 8 | environment: 9 | sdk: ">=2.15.0 <3.0.0" 10 | 11 | dependencies: 12 | flutter: 13 | sdk: flutter 14 | get_it: ^7.2.0 15 | flutter_bloc: ^8.0.0 16 | equatable: ^2.0.3 17 | dartz: ^0.10.1 18 | connectivity_plus: ^2.1.0 19 | shared_preferences: ^2.0.11 20 | cupertino_icons: ^1.0.2 21 | retrofit: ^3.0.0 22 | json_serializable: ^6.1.3 23 | 24 | dev_dependencies: 25 | flutter_test: 26 | sdk: flutter 27 | mockito: ^5.0.16 28 | flutter_lints: ^1.0.0 29 | build_runner: ^2.1.7 30 | retrofit_generator: ^3.0.0+2 31 | bloc_test: ^9.0.1 32 | 33 | 34 | flutter: 35 | uses-material-design: true 36 | 37 | # To add assets to your application, add an assets section, like this: 38 | # assets: 39 | # - images/a_dot_burr.jpeg 40 | # - images/a_dot_ham.jpeg 41 | 42 | # An image asset can refer to one or more resolution-specific "variants", see 43 | # https://flutter.dev/assets-and-images/#resolution-aware. 44 | 45 | # For details regarding adding assets from package dependencies, see 46 | # https://flutter.dev/assets-and-images/#from-packages 47 | 48 | # To add custom fonts to your application, add a fonts section here, 49 | # in this "flutter" section. Each entry in this list should have a 50 | # "family" key with the font family name, and a "fonts" key with a 51 | # list giving the asset and other descriptors for the font. For 52 | # example: 53 | # fonts: 54 | # - family: Schyler 55 | # fonts: 56 | # - asset: fonts/Schyler-Regular.ttf 57 | # - asset: fonts/Schyler-Italic.ttf 58 | # style: italic 59 | # - family: Trajan Pro 60 | # fonts: 61 | # - asset: fonts/TrajanPro.ttf 62 | # - asset: fonts/TrajanPro_Bold.ttf 63 | # weight: 700 64 | # 65 | # For details regarding fonts from package dependencies, 66 | # see https://flutter.dev/custom-fonts/#from-packages 67 | -------------------------------------------------------------------------------- /screenshots/image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/screenshots/image1.png -------------------------------------------------------------------------------- /screenshots/image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/screenshots/image2.png -------------------------------------------------------------------------------- /test/core/network/network_info_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:connectivity_plus/connectivity_plus.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:mockito/mockito.dart'; 4 | import 'package:tdd_example/core/network/network_info.dart'; 5 | 6 | import '../../mocks/generate_mocks.mocks.dart'; 7 | 8 | void main() { 9 | late NetworkInfoImpl networkInfoImpl; 10 | late MockConnectivity mockConnectivity; 11 | 12 | setUp(() { 13 | mockConnectivity = MockConnectivity(); 14 | networkInfoImpl = NetworkInfoImpl(mockConnectivity); 15 | }); 16 | 17 | group('isConnected', () { 18 | test('should call Connectivity.checkConnectivity() to check network state', 19 | () async { 20 | when(mockConnectivity.checkConnectivity()).thenAnswer( 21 | (_) async => ConnectivityResult.wifi, 22 | ); 23 | 24 | final result = await networkInfoImpl.isConnected; 25 | 26 | verify(mockConnectivity.checkConnectivity()); 27 | verifyNoMoreInteractions(mockConnectivity); 28 | expect(result, true); 29 | }); 30 | }); 31 | } 32 | -------------------------------------------------------------------------------- /test/core/states/data_state_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_test/flutter_test.dart'; 2 | import 'package:tdd_example/core/states/data_state.dart'; 3 | 4 | import '../../mocks/mock_users.dart'; 5 | 6 | void main() { 7 | group( 8 | 'DataState', 9 | () { 10 | void buildExpectations( 11 | DataState state, { 12 | final bool isInProgress = false, 13 | final bool isFailure = false, 14 | final bool isSuccess = false, 15 | final bool isEmpty = false, 16 | final T? data, 17 | }) { 18 | expect(state.isInProgress, isInProgress); 19 | expect(state.isFailure, isFailure); 20 | expect(state.isSuccess, isSuccess); 21 | expect(state.isEmpty, isEmpty); 22 | expect(state.data, equals(data)); 23 | } 24 | 25 | test( 26 | 'should return default values', 27 | () { 28 | buildExpectations(DataState.initial()); 29 | }, 30 | ); 31 | 32 | test( 33 | 'should return [isInProgress = true]', 34 | () { 35 | buildExpectations( 36 | DataState.inProgress(), 37 | isInProgress: true, 38 | ); 39 | }, 40 | ); 41 | 42 | test( 43 | 'should return [isFailure = true]', 44 | () { 45 | buildExpectations( 46 | DataState.failure(), 47 | isFailure: true, 48 | ); 49 | }, 50 | ); 51 | 52 | test( 53 | 'should return [isEmpty = true]', 54 | () { 55 | buildExpectations( 56 | DataState.empty(), 57 | isEmpty: true, 58 | ); 59 | }, 60 | ); 61 | 62 | test( 63 | 'should return [isSuccess = true] and data', 64 | () { 65 | buildExpectations( 66 | DataState.success(users), 67 | isSuccess: true, 68 | data: users, 69 | ); 70 | }, 71 | ); 72 | }, 73 | ); 74 | } 75 | -------------------------------------------------------------------------------- /test/data/data_sources/mock_response_stub.dart: -------------------------------------------------------------------------------- 1 | import 'package:dio/dio.dart'; 2 | import 'package:mockito/mockito.dart'; 3 | 4 | import '../../mocks/generate_mocks.mocks.dart'; 5 | 6 | extension MockStub on MockHttpClientAdapter { 7 | void createMockResponseStub(String body, int statusCode) { 8 | final response = ResponseBody.fromString( 9 | body, 10 | statusCode, 11 | headers: { 12 | Headers.contentTypeHeader: [Headers.jsonContentType], 13 | }, 14 | ); 15 | 16 | when(fetch(any, any, any)).thenAnswer( 17 | (_) async { 18 | return response; 19 | }, 20 | ); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/data/data_sources/post_remote_data_source_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:dio/dio.dart'; 4 | import 'package:flutter_test/flutter_test.dart'; 5 | import 'package:tdd_example/data/data_sources/post_remote_data_source.dart'; 6 | import 'package:tdd_example/data/models/post_model.dart'; 7 | 8 | import '../../fixtures/fixture_reader.dart'; 9 | import '../../mocks/generate_mocks.mocks.dart'; 10 | import 'mock_response_stub.dart'; 11 | 12 | void main() { 13 | late MockHttpClientAdapter adapter; 14 | late PostRemoteDataSourceImpl postRemoteDataSourceImpl; 15 | 16 | setUp(() { 17 | adapter = MockHttpClientAdapter(); 18 | postRemoteDataSourceImpl = PostRemoteDataSourceImpl( 19 | Dio()..httpClientAdapter = adapter, 20 | ); 21 | }); 22 | 23 | final postsJsonMap = json.decode(fixture('posts.json')) as List; 24 | final posts = postsJsonMap.map((e) => PostModel.fromJson(e)).toList(); 25 | 26 | test('should return post list if request is successful', () async { 27 | adapter.createMockResponseStub(json.encode(postsJsonMap), 200); 28 | 29 | final result = await postRemoteDataSourceImpl.getUserPosts(1); 30 | 31 | expect(result, equals(posts)); 32 | }); 33 | 34 | test('should throw [ServerException] for response code is 404 or other', 35 | () async { 36 | adapter.createMockResponseStub('Something went wrong!', 404); 37 | 38 | final call = postRemoteDataSourceImpl.getUserPosts; 39 | 40 | expect(() => call(1), throwsA(const TypeMatcher())); 41 | }); 42 | } 43 | -------------------------------------------------------------------------------- /test/data/data_sources/user_local_data_source_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:flutter_test/flutter_test.dart'; 4 | import 'package:mockito/mockito.dart'; 5 | import 'package:tdd_example/core/error/exceptions.dart'; 6 | import 'package:tdd_example/data/data_sources/user_local_data_source.dart'; 7 | import 'package:tdd_example/data/models/user_model.dart'; 8 | 9 | import '../../fixtures/fixture_reader.dart'; 10 | import '../../mocks/generate_mocks.mocks.dart'; 11 | import '../../mocks/mock_user_models.dart'; 12 | 13 | void main() { 14 | late UserLocalDataSourceImpl dataSource; 15 | late MockSharedPreferences mockSharedPreferences; 16 | 17 | setUp(() { 18 | mockSharedPreferences = MockSharedPreferences(); 19 | dataSource = UserLocalDataSourceImpl(mockSharedPreferences); 20 | }); 21 | 22 | group('getLastUsers', () { 23 | final jsonMap = json.decode(fixture('users_cached.json')) as List; 24 | 25 | final expectedCachedUsers = jsonMap.map((user) { 26 | return UserModel.fromJson(user); 27 | }).toList(); 28 | test( 29 | 'should return [User]s from [SharedPreferences] when there is' 30 | ' data in the cache', 31 | () async { 32 | final usersString = []; 33 | 34 | for (var user in userModels) { 35 | usersString.add(json.encode(user.toJson())); 36 | } 37 | 38 | when(mockSharedPreferences.getStringList(any)).thenReturn(usersString); 39 | 40 | final result = await dataSource.getLastUsers(); 41 | 42 | verify(mockSharedPreferences.getStringList(cachedUsers)); 43 | expect(result, equals(expectedCachedUsers)); 44 | }, 45 | ); 46 | 47 | test( 48 | 'should throw [CacheException] when there is no cached ' 49 | 'data in the cache', 50 | () async { 51 | when(mockSharedPreferences.getStringList(any)).thenReturn(null); 52 | 53 | final call = dataSource.getLastUsers; 54 | 55 | expect(() => call(), throwsA(const TypeMatcher())); 56 | }, 57 | ); 58 | }); 59 | 60 | group('cache users', () { 61 | test('should call [SharedPreferences] to cache users', () async { 62 | when(mockSharedPreferences.setStringList(any, any)).thenAnswer( 63 | (_) async => true, 64 | ); 65 | 66 | await dataSource.cacheUsers(userModels); 67 | 68 | final usersString = []; 69 | 70 | for (var user in userModels) { 71 | usersString.add(json.encode(user.toJson())); 72 | } 73 | 74 | verify(mockSharedPreferences.setStringList(cachedUsers, usersString)); 75 | }); 76 | }); 77 | } 78 | -------------------------------------------------------------------------------- /test/data/data_sources/user_remote_data_source_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:dio/dio.dart'; 4 | import 'package:flutter_test/flutter_test.dart'; 5 | import 'package:tdd_example/data/data_sources/user_remote_data_source.dart'; 6 | import 'package:tdd_example/data/models/user_model.dart'; 7 | 8 | import '../../fixtures/fixture_reader.dart'; 9 | import '../../mocks/generate_mocks.mocks.dart'; 10 | import 'mock_response_stub.dart'; 11 | 12 | void main() { 13 | late MockHttpClientAdapter adapter; 14 | late UserRemoteDataSourceImpl dataSource; 15 | 16 | setUp(() { 17 | final dio = Dio(); 18 | adapter = MockHttpClientAdapter(); 19 | dio.httpClientAdapter = adapter; 20 | dataSource = UserRemoteDataSourceImpl(dio); 21 | }); 22 | 23 | group('getUsers', () { 24 | final usersJsonMap = json.decode(fixture('users.json')) as List; 25 | final users = usersJsonMap.map((e) => UserModel.fromJson(e)).toList(); 26 | 27 | test('should return users list if request is successful', () async { 28 | adapter.createMockResponseStub(json.encode(usersJsonMap), 200); 29 | 30 | final result = await dataSource.getUsers(); 31 | 32 | expect(result, equals(users)); 33 | }); 34 | 35 | test('should throw [ServerException] for response code is 404 or other', 36 | () async { 37 | adapter.createMockResponseStub('Something went wrong!', 404); 38 | 39 | final call = dataSource.getUsers; 40 | 41 | expect(() => call(), throwsA(const TypeMatcher())); 42 | }); 43 | }); 44 | } 45 | -------------------------------------------------------------------------------- /test/data/models/post_model_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:flutter_test/flutter_test.dart'; 4 | import 'package:tdd_example/data/models/post_model.dart'; 5 | import 'package:tdd_example/domain/entities/post.dart'; 6 | 7 | import '../../fixtures/fixture_reader.dart'; 8 | import '../../mocks/mock_post_models.dart'; 9 | 10 | void main() { 11 | test('should be a subclass of [Post] entity', () { 12 | for (var postModel in postModels) { 13 | expect(postModel, isA()); 14 | } 15 | }); 16 | 17 | test('should return a valid model when a Json a valid', () { 18 | final List jsonMap = json.decode(fixture('posts.json')); 19 | 20 | final result = jsonMap.map((e) => PostModel.fromJson(e)).toList(); 21 | 22 | expect(result, postModels); 23 | }); 24 | 25 | test('should return a valid Json when a model a valid', () { 26 | final postModel = postModels[0]; 27 | 28 | final jsonMap = { 29 | "userId": 1, 30 | "id": 1, 31 | "title": 'Post Title 1', 32 | "body": 'Post Body 1', 33 | }; 34 | 35 | final result = postModel.toJson(); 36 | 37 | expect(result, jsonMap); 38 | }); 39 | } 40 | -------------------------------------------------------------------------------- /test/data/models/user_model_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:flutter_test/flutter_test.dart'; 4 | import 'package:tdd_example/data/models/user_model.dart'; 5 | import 'package:tdd_example/domain/entities/user.dart'; 6 | 7 | import '../../fixtures/fixture_reader.dart'; 8 | import '../../mocks/mock_user_models.dart'; 9 | 10 | void main() { 11 | test('should be a subclass of [User] entity', () { 12 | expect(userModels[0], isA()); 13 | expect(userModels[1], isA()); 14 | }); 15 | 16 | test('should return a valid model when a Json a valid', () { 17 | final List jsonMap = json.decode(fixture('users.json')); 18 | 19 | final result = jsonMap.map((e) => UserModel.fromJson(e)).toList(); 20 | 21 | expect(result, userModels); 22 | }); 23 | 24 | test('should return a valid Json when a model a valid', () { 25 | final userModel = userModels[0]; 26 | 27 | final jsonMap = { 28 | "id": 1, 29 | "name": "Test User 1", 30 | "username": "Test Username 1", 31 | "email": "testuser1@gmail.com", 32 | }; 33 | 34 | final result = userModel.toJson(); 35 | 36 | expect(result, jsonMap); 37 | }); 38 | } 39 | -------------------------------------------------------------------------------- /test/data/repositories/post_repository_impl_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:dio/dio.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | import 'package:mockito/mockito.dart'; 5 | import 'package:tdd_example/core/error/failure.dart'; 6 | import 'package:tdd_example/data/repositories/post_repository_impl.dart'; 7 | import 'package:tdd_example/domain/entities/post.dart'; 8 | 9 | import '../../mocks/generate_mocks.mocks.dart'; 10 | import '../../mocks/mock_post_models.dart'; 11 | 12 | void main() { 13 | late PostRepositoryImpl postRepositoryImpl; 14 | late MockPostRemoteDataSource mockPostRemoteDataSource; 15 | late List posts; 16 | 17 | setUp(() { 18 | mockPostRemoteDataSource = MockPostRemoteDataSource(); 19 | postRepositoryImpl = PostRepositoryImpl(mockPostRemoteDataSource); 20 | posts = postModels; 21 | }); 22 | 23 | test( 24 | 'should return list of [Post] if it is successful', 25 | () async { 26 | when(mockPostRemoteDataSource.getUserPosts(any)) 27 | .thenAnswer((_) async => postModels); 28 | 29 | final result = await postRepositoryImpl.getUserPosts(1); 30 | 31 | expect(result, equals(Right(posts))); 32 | verify(mockPostRemoteDataSource.getUserPosts(1)); 33 | verifyNoMoreInteractions(mockPostRemoteDataSource); 34 | }, 35 | ); 36 | 37 | test( 38 | 'should return [ServerFailure] if it us successful', 39 | () async { 40 | when(mockPostRemoteDataSource.getUserPosts(any)).thenThrow( 41 | DioError( 42 | requestOptions: RequestOptions( 43 | path: '', 44 | ), 45 | ), 46 | ); 47 | 48 | final result = await postRepositoryImpl.getUserPosts(1); 49 | 50 | expect(result, equals((Left(ServerFailure())))); 51 | verify(mockPostRemoteDataSource.getUserPosts(1)); 52 | verifyNoMoreInteractions(mockPostRemoteDataSource); 53 | }, 54 | ); 55 | } 56 | -------------------------------------------------------------------------------- /test/data/repositories/user_repository_impl_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:dio/dio.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | import 'package:mockito/mockito.dart'; 5 | import 'package:tdd_example/core/error/exceptions.dart'; 6 | import 'package:tdd_example/core/error/failure.dart'; 7 | import 'package:tdd_example/data/repositories/user_repository_impl.dart'; 8 | import 'package:tdd_example/domain/entities/user.dart'; 9 | 10 | import '../../mocks/generate_mocks.mocks.dart'; 11 | import '../../mocks/mock_user_models.dart'; 12 | 13 | void main() { 14 | late UserRepositoryImpl userRepositoryImpl; 15 | late MockUserRemoteDataSource mockUserRemoteDataSource; 16 | late MockUserLocalDataSource mockUserLocalDataSource; 17 | late MockNetworkInfo mockNetworkInfo; 18 | late List users; 19 | 20 | setUp(() { 21 | mockUserRemoteDataSource = MockUserRemoteDataSource(); 22 | mockUserLocalDataSource = MockUserLocalDataSource(); 23 | mockNetworkInfo = MockNetworkInfo(); 24 | users = userModels; 25 | userRepositoryImpl = UserRepositoryImpl( 26 | remoteDataSource: mockUserRemoteDataSource, 27 | localDataSource: mockUserLocalDataSource, 28 | networkInfo: mockNetworkInfo, 29 | ); 30 | }); 31 | 32 | test( 33 | 'should check if the device is online', 34 | () async { 35 | when(mockNetworkInfo.isConnected).thenAnswer((_) async => true); 36 | 37 | when(mockUserRemoteDataSource.getUsers()).thenAnswer((_) async { 38 | return userModels; 39 | }); 40 | 41 | userRepositoryImpl.getUsers(); 42 | 43 | verify(mockNetworkInfo.isConnected); 44 | }, 45 | ); 46 | 47 | group('getUsers', () { 48 | group('device is online', () { 49 | setUp(() { 50 | when(mockNetworkInfo.isConnected).thenAnswer((_) async => true); 51 | }); 52 | 53 | test('should return remote users when it is successful', () async { 54 | when(mockUserRemoteDataSource.getUsers()).thenAnswer((_) async { 55 | return userModels; 56 | }); 57 | 58 | final result = await userRepositoryImpl.getUsers(); 59 | 60 | verify(mockUserRemoteDataSource.getUsers()); 61 | expect(result, equals(Right(users))); 62 | }); 63 | 64 | test('should cache remote users when it is successful', () async { 65 | when(mockUserRemoteDataSource.getUsers()).thenAnswer((_) async { 66 | return userModels; 67 | }); 68 | 69 | final result = await userRepositoryImpl.getUsers(); 70 | 71 | verify(mockUserRemoteDataSource.getUsers()); 72 | verify(mockUserLocalDataSource.cacheUsers(userModels)); 73 | expect(result, equals(Right(users))); 74 | }); 75 | 76 | test('should return server failure when it is unsuccessful', () async { 77 | when(mockUserRemoteDataSource.getUsers()).thenThrow( 78 | DioError(requestOptions: RequestOptions(path: '')), 79 | ); 80 | 81 | final result = await userRepositoryImpl.getUsers(); 82 | 83 | verify(mockUserRemoteDataSource.getUsers()); 84 | verifyZeroInteractions(mockUserLocalDataSource); 85 | expect(result, equals(Left(ServerFailure()))); 86 | }); 87 | }); 88 | 89 | group('device is offline', () { 90 | setUp(() { 91 | when(mockNetworkInfo.isConnected).thenAnswer((_) async => false); 92 | }); 93 | 94 | test( 95 | 'should return last cached users when the cached data is present', 96 | () async { 97 | when(mockUserLocalDataSource.getLastUsers()) 98 | .thenAnswer((_) async => userModels); 99 | 100 | final result = await userRepositoryImpl.getUsers(); 101 | 102 | verifyZeroInteractions(mockUserRemoteDataSource); 103 | verify(mockUserLocalDataSource.getLastUsers()); 104 | expect(result, equals(Right(users))); 105 | }, 106 | ); 107 | 108 | test( 109 | 'should return [CacheFailure] when there is no cached data', 110 | () async { 111 | when(mockUserLocalDataSource.getLastUsers()) 112 | .thenThrow(CacheException()); 113 | 114 | final result = await userRepositoryImpl.getUsers(); 115 | 116 | verifyZeroInteractions(mockUserRemoteDataSource); 117 | verify(mockUserLocalDataSource.getLastUsers()); 118 | expect(result, equals(Left(CacheFailure()))); 119 | }, 120 | ); 121 | }); 122 | }); 123 | } 124 | -------------------------------------------------------------------------------- /test/domain/use_cases/get_user_posts_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:mockito/mockito.dart'; 4 | import 'package:tdd_example/core/error/failure.dart'; 5 | import 'package:tdd_example/domain/use_cases/get_user_posts.dart'; 6 | 7 | import '../../mocks/generate_mocks.mocks.dart'; 8 | import '../../mocks/mock_posts.dart'; 9 | 10 | void main() { 11 | late GetUserPosts getUserPosts; 12 | late MockPostRepository mockPostRepository; 13 | 14 | setUp(() { 15 | mockPostRepository = MockPostRepository(); 16 | getUserPosts = GetUserPosts(mockPostRepository); 17 | }); 18 | 19 | test('GetUserPosts gets posts successfully', () async { 20 | when(mockPostRepository.getUserPosts(any)).thenAnswer( 21 | (_) async => const Right(posts), 22 | ); 23 | 24 | final result = await getUserPosts(1); 25 | 26 | expect(result, equals(const Right(posts))); 27 | verify(mockPostRepository.getUserPosts(1)); 28 | verifyNoMoreInteractions(mockPostRepository); 29 | }); 30 | 31 | test('GetUserPosts returns Failure', () async { 32 | when(mockPostRepository.getUserPosts(any)).thenAnswer( 33 | (_) async => Left(ServerFailure()), 34 | ); 35 | 36 | final result = await getUserPosts(1); 37 | 38 | expect(result, equals(Left(ServerFailure()))); 39 | }); 40 | } 41 | -------------------------------------------------------------------------------- /test/domain/use_cases/get_users_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:mockito/mockito.dart'; 4 | import 'package:tdd_example/core/no_params.dart'; 5 | import 'package:tdd_example/domain/use_cases/get_users.dart'; 6 | 7 | import '../../mocks/generate_mocks.mocks.dart'; 8 | import '../../mocks/mock_users.dart'; 9 | 10 | void main() { 11 | late GetUsers usecase; 12 | late MockUserRepository mockUsersRepository; 13 | 14 | group('GetUsers Usecase', () { 15 | setUp(() { 16 | mockUsersRepository = MockUserRepository(); 17 | usecase = GetUsers(mockUsersRepository); 18 | }); 19 | 20 | test( 21 | 'should get users from the repository', 22 | () async { 23 | when(mockUsersRepository.getUsers()).thenAnswer( 24 | (_) async => const Right(users), 25 | ); 26 | 27 | final result = await usecase(noParams); 28 | 29 | expect(result, const Right(users)); 30 | verify(mockUsersRepository.getUsers()); 31 | verifyNoMoreInteractions(mockUsersRepository); 32 | }, 33 | ); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /test/fixtures/fixture_reader.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | String fixture(String name) => File('test/fixtures/$name').readAsStringSync(); 4 | -------------------------------------------------------------------------------- /test/fixtures/posts.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "userId": 1, 4 | "id": 1, 5 | "title": "Post Title 1", 6 | "body": "Post Body 1" 7 | }, 8 | { 9 | "userId": 1, 10 | "id": 2, 11 | "title": "Post Title 2", 12 | "body": "Post Body 2" 13 | } 14 | ] -------------------------------------------------------------------------------- /test/fixtures/users.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 1, 4 | "name": "Test User 1", 5 | "username": "Test Username 1", 6 | "email": "testuser1@gmail.com" 7 | }, 8 | { 9 | "id": 2, 10 | "name": "Test User 2", 11 | "username": "Test Username 2", 12 | "email": "testuser2@gmail.com" 13 | } 14 | ] -------------------------------------------------------------------------------- /test/fixtures/users_cached.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 1, 4 | "name": "Test User 1", 5 | "username": "Test Username 1", 6 | "email": "testuser1@gmail.com" 7 | }, 8 | { 9 | "id": 2, 10 | "name": "Test User 2", 11 | "username": "Test Username 2", 12 | "email": "testuser2@gmail.com" 13 | } 14 | ] -------------------------------------------------------------------------------- /test/mocks/generate_mocks.dart: -------------------------------------------------------------------------------- 1 | import 'package:connectivity_plus/connectivity_plus.dart'; 2 | import 'package:dio/dio.dart'; 3 | import 'package:mockito/annotations.dart'; 4 | import 'package:shared_preferences/shared_preferences.dart'; 5 | import 'package:tdd_example/core/network/network_info.dart'; 6 | import 'package:tdd_example/data/data_sources/post_remote_data_source.dart'; 7 | import 'package:tdd_example/data/data_sources/user_local_data_source.dart'; 8 | import 'package:tdd_example/data/data_sources/user_remote_data_source.dart'; 9 | import 'package:tdd_example/domain/repositories/post_repository.dart'; 10 | import 'package:tdd_example/domain/repositories/user_repository.dart'; 11 | import 'package:tdd_example/domain/use_cases/get_user_posts.dart'; 12 | import 'package:tdd_example/domain/use_cases/get_users.dart'; 13 | 14 | @GenerateMocks( 15 | [ 16 | SharedPreferences, 17 | HttpClientAdapter, 18 | NetworkInfo, 19 | UserLocalDataSource, 20 | UserRemoteDataSource, 21 | UserRepository, 22 | Connectivity, 23 | GetUsers, 24 | PostRepository, 25 | PostRemoteDataSource, 26 | GetUserPosts, 27 | ], 28 | ) 29 | void generateMocks() {} 30 | -------------------------------------------------------------------------------- /test/mocks/generate_mocks.mocks.dart: -------------------------------------------------------------------------------- 1 | // Mocks generated by Mockito 5.0.16 from annotations 2 | // in tdd_example/test/mocks/generate_mocks.dart. 3 | // Do not manually edit this file. 4 | 5 | import 'dart:async' as _i7; 6 | import 'dart:typed_data' as _i9; 7 | 8 | import 'package:connectivity_plus/connectivity_plus.dart' as _i16; 9 | import 'package:dartz/dartz.dart' as _i3; 10 | import 'package:dio/dio.dart' as _i2; 11 | import 'package:dio/src/options.dart' as _i8; 12 | import 'package:mockito/mockito.dart' as _i1; 13 | import 'package:shared_preferences/shared_preferences.dart' as _i6; 14 | import 'package:tdd_example/core/error/failure.dart' as _i14; 15 | import 'package:tdd_example/core/network/network_info.dart' as _i10; 16 | import 'package:tdd_example/core/no_params.dart' as _i18; 17 | import 'package:tdd_example/data/data_sources/post_remote_data_source.dart' 18 | as _i20; 19 | import 'package:tdd_example/data/data_sources/user_local_data_source.dart' 20 | as _i11; 21 | import 'package:tdd_example/data/data_sources/user_remote_data_source.dart' 22 | as _i13; 23 | import 'package:tdd_example/data/models/post_model.dart' as _i21; 24 | import 'package:tdd_example/data/models/user_model.dart' as _i12; 25 | import 'package:tdd_example/domain/entities/post.dart' as _i19; 26 | import 'package:tdd_example/domain/entities/user.dart' as _i15; 27 | import 'package:tdd_example/domain/repositories/post_repository.dart' as _i5; 28 | import 'package:tdd_example/domain/repositories/user_repository.dart' as _i4; 29 | import 'package:tdd_example/domain/use_cases/get_user_posts.dart' as _i22; 30 | import 'package:tdd_example/domain/use_cases/get_users.dart' as _i17; 31 | 32 | // ignore_for_file: avoid_redundant_argument_values 33 | // ignore_for_file: avoid_setters_without_getters 34 | // ignore_for_file: comment_references 35 | // ignore_for_file: implementation_imports 36 | // ignore_for_file: invalid_use_of_visible_for_testing_member 37 | // ignore_for_file: prefer_const_constructors 38 | // ignore_for_file: unnecessary_parenthesis 39 | // ignore_for_file: camel_case_types 40 | 41 | class _FakeResponseBody_0 extends _i1.Fake implements _i2.ResponseBody {} 42 | 43 | class _FakeEither_1 extends _i1.Fake implements _i3.Either {} 44 | 45 | class _FakeUserRepository_2 extends _i1.Fake implements _i4.UserRepository {} 46 | 47 | class _FakePostRepository_3 extends _i1.Fake implements _i5.PostRepository {} 48 | 49 | /// A class which mocks [SharedPreferences]. 50 | /// 51 | /// See the documentation for Mockito's code generation for more information. 52 | class MockSharedPreferences extends _i1.Mock implements _i6.SharedPreferences { 53 | MockSharedPreferences() { 54 | _i1.throwOnMissingStub(this); 55 | } 56 | 57 | @override 58 | Set getKeys() => (super.noSuchMethod(Invocation.method(#getKeys, []), 59 | returnValue: {}) as Set); 60 | @override 61 | Object? get(String? key) => 62 | (super.noSuchMethod(Invocation.method(#get, [key])) as Object?); 63 | @override 64 | bool? getBool(String? key) => 65 | (super.noSuchMethod(Invocation.method(#getBool, [key])) as bool?); 66 | @override 67 | int? getInt(String? key) => 68 | (super.noSuchMethod(Invocation.method(#getInt, [key])) as int?); 69 | @override 70 | double? getDouble(String? key) => 71 | (super.noSuchMethod(Invocation.method(#getDouble, [key])) as double?); 72 | @override 73 | String? getString(String? key) => 74 | (super.noSuchMethod(Invocation.method(#getString, [key])) as String?); 75 | @override 76 | bool containsKey(String? key) => 77 | (super.noSuchMethod(Invocation.method(#containsKey, [key]), 78 | returnValue: false) as bool); 79 | @override 80 | List? getStringList(String? key) => 81 | (super.noSuchMethod(Invocation.method(#getStringList, [key])) 82 | as List?); 83 | @override 84 | _i7.Future setBool(String? key, bool? value) => 85 | (super.noSuchMethod(Invocation.method(#setBool, [key, value]), 86 | returnValue: Future.value(false)) as _i7.Future); 87 | @override 88 | _i7.Future setInt(String? key, int? value) => 89 | (super.noSuchMethod(Invocation.method(#setInt, [key, value]), 90 | returnValue: Future.value(false)) as _i7.Future); 91 | @override 92 | _i7.Future setDouble(String? key, double? value) => 93 | (super.noSuchMethod(Invocation.method(#setDouble, [key, value]), 94 | returnValue: Future.value(false)) as _i7.Future); 95 | @override 96 | _i7.Future setString(String? key, String? value) => 97 | (super.noSuchMethod(Invocation.method(#setString, [key, value]), 98 | returnValue: Future.value(false)) as _i7.Future); 99 | @override 100 | _i7.Future setStringList(String? key, List? value) => 101 | (super.noSuchMethod(Invocation.method(#setStringList, [key, value]), 102 | returnValue: Future.value(false)) as _i7.Future); 103 | @override 104 | _i7.Future remove(String? key) => 105 | (super.noSuchMethod(Invocation.method(#remove, [key]), 106 | returnValue: Future.value(false)) as _i7.Future); 107 | @override 108 | _i7.Future commit() => 109 | (super.noSuchMethod(Invocation.method(#commit, []), 110 | returnValue: Future.value(false)) as _i7.Future); 111 | @override 112 | _i7.Future clear() => (super.noSuchMethod(Invocation.method(#clear, []), 113 | returnValue: Future.value(false)) as _i7.Future); 114 | @override 115 | _i7.Future reload() => 116 | (super.noSuchMethod(Invocation.method(#reload, []), 117 | returnValue: Future.value(), 118 | returnValueForMissingStub: Future.value()) as _i7.Future); 119 | @override 120 | String toString() => super.toString(); 121 | } 122 | 123 | /// A class which mocks [HttpClientAdapter]. 124 | /// 125 | /// See the documentation for Mockito's code generation for more information. 126 | class MockHttpClientAdapter extends _i1.Mock implements _i2.HttpClientAdapter { 127 | MockHttpClientAdapter() { 128 | _i1.throwOnMissingStub(this); 129 | } 130 | 131 | @override 132 | _i7.Future<_i2.ResponseBody> fetch( 133 | _i8.RequestOptions? options, 134 | _i7.Stream<_i9.Uint8List>? requestStream, 135 | _i7.Future? cancelFuture) => 136 | (super.noSuchMethod( 137 | Invocation.method(#fetch, [options, requestStream, cancelFuture]), 138 | returnValue: 139 | Future<_i2.ResponseBody>.value(_FakeResponseBody_0())) 140 | as _i7.Future<_i2.ResponseBody>); 141 | @override 142 | void close({bool? force = false}) => 143 | super.noSuchMethod(Invocation.method(#close, [], {#force: force}), 144 | returnValueForMissingStub: null); 145 | @override 146 | String toString() => super.toString(); 147 | } 148 | 149 | /// A class which mocks [NetworkInfo]. 150 | /// 151 | /// See the documentation for Mockito's code generation for more information. 152 | class MockNetworkInfo extends _i1.Mock implements _i10.NetworkInfo { 153 | MockNetworkInfo() { 154 | _i1.throwOnMissingStub(this); 155 | } 156 | 157 | @override 158 | _i7.Future get isConnected => 159 | (super.noSuchMethod(Invocation.getter(#isConnected), 160 | returnValue: Future.value(false)) as _i7.Future); 161 | @override 162 | String toString() => super.toString(); 163 | } 164 | 165 | /// A class which mocks [UserLocalDataSource]. 166 | /// 167 | /// See the documentation for Mockito's code generation for more information. 168 | class MockUserLocalDataSource extends _i1.Mock 169 | implements _i11.UserLocalDataSource { 170 | MockUserLocalDataSource() { 171 | _i1.throwOnMissingStub(this); 172 | } 173 | 174 | @override 175 | _i7.Future> getLastUsers() => (super.noSuchMethod( 176 | Invocation.method(#getLastUsers, []), 177 | returnValue: Future>.value(<_i12.UserModel>[])) 178 | as _i7.Future>); 179 | @override 180 | _i7.Future cacheUsers(List<_i12.UserModel>? usersToCache) => 181 | (super.noSuchMethod(Invocation.method(#cacheUsers, [usersToCache]), 182 | returnValue: Future.value(), 183 | returnValueForMissingStub: Future.value()) as _i7.Future); 184 | @override 185 | String toString() => super.toString(); 186 | } 187 | 188 | /// A class which mocks [UserRemoteDataSource]. 189 | /// 190 | /// See the documentation for Mockito's code generation for more information. 191 | class MockUserRemoteDataSource extends _i1.Mock 192 | implements _i13.UserRemoteDataSource { 193 | MockUserRemoteDataSource() { 194 | _i1.throwOnMissingStub(this); 195 | } 196 | 197 | @override 198 | _i7.Future> getUsers() => (super.noSuchMethod( 199 | Invocation.method(#getUsers, []), 200 | returnValue: Future>.value(<_i12.UserModel>[])) 201 | as _i7.Future>); 202 | @override 203 | String toString() => super.toString(); 204 | } 205 | 206 | /// A class which mocks [UserRepository]. 207 | /// 208 | /// See the documentation for Mockito's code generation for more information. 209 | class MockUserRepository extends _i1.Mock implements _i4.UserRepository { 210 | MockUserRepository() { 211 | _i1.throwOnMissingStub(this); 212 | } 213 | 214 | @override 215 | _i7.Future<_i3.Either<_i14.Failure, List<_i15.User>>> getUsers() => 216 | (super.noSuchMethod(Invocation.method(#getUsers, []), 217 | returnValue: Future<_i3.Either<_i14.Failure, List<_i15.User>>>.value( 218 | _FakeEither_1<_i14.Failure, List<_i15.User>>())) as _i7 219 | .Future<_i3.Either<_i14.Failure, List<_i15.User>>>); 220 | @override 221 | String toString() => super.toString(); 222 | } 223 | 224 | /// A class which mocks [Connectivity]. 225 | /// 226 | /// See the documentation for Mockito's code generation for more information. 227 | class MockConnectivity extends _i1.Mock implements _i16.Connectivity { 228 | MockConnectivity() { 229 | _i1.throwOnMissingStub(this); 230 | } 231 | 232 | @override 233 | _i7.Stream<_i16.ConnectivityResult> get onConnectivityChanged => 234 | (super.noSuchMethod(Invocation.getter(#onConnectivityChanged), 235 | returnValue: Stream<_i16.ConnectivityResult>.empty()) 236 | as _i7.Stream<_i16.ConnectivityResult>); 237 | @override 238 | _i7.Future<_i16.ConnectivityResult> checkConnectivity() => 239 | (super.noSuchMethod(Invocation.method(#checkConnectivity, []), 240 | returnValue: Future<_i16.ConnectivityResult>.value( 241 | _i16.ConnectivityResult.wifi)) 242 | as _i7.Future<_i16.ConnectivityResult>); 243 | @override 244 | String toString() => super.toString(); 245 | } 246 | 247 | /// A class which mocks [GetUsers]. 248 | /// 249 | /// See the documentation for Mockito's code generation for more information. 250 | class MockGetUsers extends _i1.Mock implements _i17.GetUsers { 251 | MockGetUsers() { 252 | _i1.throwOnMissingStub(this); 253 | } 254 | 255 | @override 256 | _i4.UserRepository get userRepository => 257 | (super.noSuchMethod(Invocation.getter(#userRepository), 258 | returnValue: _FakeUserRepository_2()) as _i4.UserRepository); 259 | @override 260 | _i7.Future<_i3.Either<_i14.Failure, List<_i15.User>>> call( 261 | _i18.NoParams? params) => 262 | (super.noSuchMethod(Invocation.method(#call, [params]), 263 | returnValue: Future<_i3.Either<_i14.Failure, List<_i15.User>>>.value( 264 | _FakeEither_1<_i14.Failure, List<_i15.User>>())) as _i7 265 | .Future<_i3.Either<_i14.Failure, List<_i15.User>>>); 266 | @override 267 | String toString() => super.toString(); 268 | } 269 | 270 | /// A class which mocks [PostRepository]. 271 | /// 272 | /// See the documentation for Mockito's code generation for more information. 273 | class MockPostRepository extends _i1.Mock implements _i5.PostRepository { 274 | MockPostRepository() { 275 | _i1.throwOnMissingStub(this); 276 | } 277 | 278 | @override 279 | _i7.Future<_i3.Either<_i14.Failure, List<_i19.Post>>> getUserPosts( 280 | int? userId) => 281 | (super.noSuchMethod(Invocation.method(#getUserPosts, [userId]), 282 | returnValue: Future<_i3.Either<_i14.Failure, List<_i19.Post>>>.value( 283 | _FakeEither_1<_i14.Failure, List<_i19.Post>>())) as _i7 284 | .Future<_i3.Either<_i14.Failure, List<_i19.Post>>>); 285 | @override 286 | String toString() => super.toString(); 287 | } 288 | 289 | /// A class which mocks [PostRemoteDataSource]. 290 | /// 291 | /// See the documentation for Mockito's code generation for more information. 292 | class MockPostRemoteDataSource extends _i1.Mock 293 | implements _i20.PostRemoteDataSource { 294 | MockPostRemoteDataSource() { 295 | _i1.throwOnMissingStub(this); 296 | } 297 | 298 | @override 299 | _i7.Future> getUserPosts(int? userId) => 300 | (super.noSuchMethod(Invocation.method(#getUserPosts, [userId]), 301 | returnValue: 302 | Future>.value(<_i21.PostModel>[])) 303 | as _i7.Future>); 304 | @override 305 | String toString() => super.toString(); 306 | } 307 | 308 | /// A class which mocks [GetUserPosts]. 309 | /// 310 | /// See the documentation for Mockito's code generation for more information. 311 | class MockGetUserPosts extends _i1.Mock implements _i22.GetUserPosts { 312 | MockGetUserPosts() { 313 | _i1.throwOnMissingStub(this); 314 | } 315 | 316 | @override 317 | _i5.PostRepository get postRepository => 318 | (super.noSuchMethod(Invocation.getter(#postRepository), 319 | returnValue: _FakePostRepository_3()) as _i5.PostRepository); 320 | @override 321 | _i7.Future<_i3.Either<_i14.Failure, List<_i19.Post>>> call(int? userId) => 322 | (super.noSuchMethod(Invocation.method(#call, [userId]), 323 | returnValue: Future<_i3.Either<_i14.Failure, List<_i19.Post>>>.value( 324 | _FakeEither_1<_i14.Failure, List<_i19.Post>>())) as _i7 325 | .Future<_i3.Either<_i14.Failure, List<_i19.Post>>>); 326 | @override 327 | String toString() => super.toString(); 328 | } 329 | -------------------------------------------------------------------------------- /test/mocks/mock_post_models.dart: -------------------------------------------------------------------------------- 1 | import 'package:tdd_example/data/models/post_model.dart'; 2 | 3 | const postModels = [ 4 | PostModel( 5 | userId: 1, 6 | id: 1, 7 | title: 'Post Title 1', 8 | body: 'Post Body 1', 9 | ), 10 | PostModel( 11 | userId: 1, 12 | id: 2, 13 | title: 'Post Title 2', 14 | body: 'Post Body 2', 15 | ), 16 | ]; 17 | -------------------------------------------------------------------------------- /test/mocks/mock_posts.dart: -------------------------------------------------------------------------------- 1 | import 'package:tdd_example/domain/entities/post.dart'; 2 | 3 | const posts = [ 4 | Post( 5 | userId: 1, 6 | id: 1, 7 | title: 'Post Title 1', 8 | body: 'Post Body 1', 9 | ), 10 | Post( 11 | userId: 1, 12 | id: 2, 13 | title: 'Post Title 2', 14 | body: 'Post Body 2', 15 | ), 16 | ]; 17 | -------------------------------------------------------------------------------- /test/mocks/mock_user_models.dart: -------------------------------------------------------------------------------- 1 | import 'package:tdd_example/data/models/user_model.dart'; 2 | 3 | const userModels = [ 4 | UserModel( 5 | id: 1, 6 | name: 'Test User 1', 7 | username: 'Test Username 1', 8 | email: 'testuser1@gmail.com', 9 | ), 10 | UserModel( 11 | id: 2, 12 | name: 'Test User 2', 13 | username: 'Test Username 2', 14 | email: 'testuser2@gmail.com', 15 | ) 16 | ]; 17 | -------------------------------------------------------------------------------- /test/mocks/mock_users.dart: -------------------------------------------------------------------------------- 1 | import 'package:tdd_example/domain/entities/user.dart'; 2 | 3 | const users = [ 4 | User( 5 | id: 1, 6 | name: 'Test User 1', 7 | username: 'Test Username 1', 8 | email: 'testuser1@gmail.com', 9 | ), 10 | User( 11 | id: 2, 12 | name: 'Test User 2', 13 | username: 'Test Username 2', 14 | email: 'testuser2@gmail.com', 15 | ) 16 | ]; 17 | -------------------------------------------------------------------------------- /test/presentation/bloc/user_posts_cubit_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:bloc_test/bloc_test.dart'; 2 | import 'package:dartz/dartz.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | import 'package:mockito/mockito.dart'; 5 | import 'package:tdd_example/core/error/failure.dart'; 6 | import 'package:tdd_example/core/states/data_state.dart'; 7 | import 'package:tdd_example/domain/entities/post.dart'; 8 | import 'package:tdd_example/presentation/bloc/user_posts_cubit.dart'; 9 | 10 | import '../../mocks/generate_mocks.mocks.dart'; 11 | import '../../mocks/mock_posts.dart'; 12 | 13 | typedef Posts = List; 14 | 15 | void main() { 16 | late UserPostsCubit postsCubit; 17 | late MockGetUserPosts mockGetUserPosts; 18 | 19 | setUp(() { 20 | mockGetUserPosts = MockGetUserPosts(); 21 | postsCubit = UserPostsCubit(mockGetUserPosts); 22 | }); 23 | 24 | group('UserPostsCubit', () { 25 | blocTest>( 26 | 'should emit empty if nothing happened', 27 | build: () => postsCubit, 28 | expect: () => [], 29 | ); 30 | 31 | blocTest>( 32 | 'should emit [InProgress] when action is started', 33 | build: () => postsCubit, 34 | act: (cubit) => cubit.fetchUserPosts(1), 35 | expect: () => [DataState.inProgress()], 36 | ); 37 | 38 | blocTest>( 39 | 'should emit [Failure] when action is not successful', 40 | setUp: () { 41 | when(mockGetUserPosts.call(any)).thenAnswer( 42 | (_) async => Left(ServerFailure()), 43 | ); 44 | }, 45 | build: () => postsCubit, 46 | act: (cubit) => cubit.fetchUserPosts(1), 47 | expect: () => [ 48 | DataState.inProgress(), 49 | DataState.failure(), 50 | ], 51 | ); 52 | 53 | blocTest>( 54 | 'should emit [Empty] if there is no user', 55 | setUp: () { 56 | when(mockGetUserPosts.call(any)).thenAnswer( 57 | (_) async => const Right([]), 58 | ); 59 | }, 60 | build: () => postsCubit, 61 | act: (cubit) => cubit.fetchUserPosts(1), 62 | expect: () => [ 63 | DataState.inProgress(), 64 | DataState.empty(), 65 | ], 66 | ); 67 | 68 | blocTest>( 69 | 'should emit [Success] with the list of users when action is successful', 70 | setUp: () { 71 | when(mockGetUserPosts.call(any)).thenAnswer( 72 | (_) async => const Right(posts), 73 | ); 74 | }, 75 | build: () => postsCubit, 76 | act: (cubit) => cubit.fetchUserPosts(1), 77 | expect: () => [ 78 | DataState.inProgress(), 79 | DataState.success(posts), 80 | ], 81 | ); 82 | }); 83 | } 84 | -------------------------------------------------------------------------------- /test/presentation/bloc/users_cubit_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:bloc_test/bloc_test.dart'; 2 | import 'package:dartz/dartz.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | import 'package:mockito/mockito.dart'; 5 | import 'package:tdd_example/core/error/failure.dart' as error; 6 | import 'package:tdd_example/core/no_params.dart'; 7 | import 'package:tdd_example/domain/entities/user.dart'; 8 | import 'package:tdd_example/presentation/bloc/users_cubit.dart'; 9 | 10 | import '../../mocks/generate_mocks.mocks.dart'; 11 | import '../../mocks/mock_users.dart'; 12 | 13 | typedef Users = List; 14 | 15 | void main() { 16 | late UsersCubit userCubit; 17 | late MockGetUsers mockGetUsers; 18 | 19 | setUp(() { 20 | mockGetUsers = MockGetUsers(); 21 | userCubit = UsersCubit(mockGetUsers); 22 | }); 23 | 24 | group('UserCubit', () { 25 | blocTest>( 26 | 'should emit empty if nothing happened', 27 | build: () => userCubit, 28 | expect: () => [], 29 | ); 30 | 31 | blocTest>( 32 | 'should emit [InProgress] when action is started', 33 | build: () => userCubit, 34 | act: (cubit) => cubit.fetchUsers(), 35 | expect: () => [DataState.inProgress()], 36 | ); 37 | 38 | blocTest>( 39 | 'should emit [Failure] when action is not successful', 40 | setUp: () { 41 | when(mockGetUsers.call(const NoParams())).thenAnswer( 42 | (_) async => Left(error.ServerFailure()), 43 | ); 44 | }, 45 | build: () => userCubit, 46 | act: (cubit) => cubit.fetchUsers(), 47 | expect: () => [ 48 | DataState.inProgress(), 49 | DataState.failure(), 50 | ], 51 | ); 52 | 53 | blocTest>( 54 | 'should emit [Empty] if there is no user', 55 | setUp: () { 56 | when(mockGetUsers.call(const NoParams())).thenAnswer( 57 | (_) async => const Right([]), 58 | ); 59 | }, 60 | build: () => userCubit, 61 | act: (cubit) => cubit.fetchUsers(), 62 | expect: () => [ 63 | DataState.inProgress(), 64 | DataState.empty(), 65 | ], 66 | ); 67 | 68 | blocTest>( 69 | 'should emit [Success] with the list of users when action is successful', 70 | setUp: () { 71 | when(mockGetUsers.call(const NoParams())).thenAnswer( 72 | (_) async => const Right(users), 73 | ); 74 | }, 75 | build: () => userCubit, 76 | act: (cubit) => cubit.fetchUsers(), 77 | expect: () => [ 78 | DataState.inProgress(), 79 | DataState.success(users), 80 | ], 81 | ); 82 | }); 83 | } 84 | -------------------------------------------------------------------------------- /test/presentation/global/failure_widget_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:tdd_example/presentation/widgets/failure_widget.dart'; 4 | 5 | void main() { 6 | testWidgets( 7 | 'should return a [Text] contains default message with [Center]', 8 | (WidgetTester tester) async { 9 | await tester.pumpWidget( 10 | const MaterialApp( 11 | home: FailureWidget(), 12 | ), 13 | ); 14 | 15 | final centerFinder = find.byType(Center); 16 | final textFinder = find.text('Something went wrong!'); 17 | 18 | expect(centerFinder, findsOneWidget); 19 | expect(textFinder, findsOneWidget); 20 | }, 21 | ); 22 | 23 | testWidgets( 24 | 'should return a [Text] contains given message with [Center]', 25 | (WidgetTester tester) async { 26 | await tester.pumpWidget( 27 | const MaterialApp( 28 | home: FailureWidget( 29 | message: 'Error!', 30 | ), 31 | ), 32 | ); 33 | 34 | final centerFinder = find.byType(Center); 35 | final textFinder = find.text('Error!'); 36 | 37 | expect(centerFinder, findsOneWidget); 38 | expect(textFinder, findsOneWidget); 39 | }, 40 | ); 41 | } 42 | -------------------------------------------------------------------------------- /test/presentation/global/loading_widget_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:tdd_example/presentation/widgets/loading_widget.dart'; 4 | 5 | void main() { 6 | testWidgets( 7 | 'should return a [CircularProgressIndicator] with ' 8 | '[Center]', 9 | (WidgetTester tester) async { 10 | await tester.pumpWidget(const LoadingWidget()); 11 | 12 | final centerFinder = find.byType(Center); 13 | final progressFinder = find.byType(CircularProgressIndicator); 14 | 15 | expect(centerFinder, findsOneWidget); 16 | expect(progressFinder, findsOneWidget); 17 | }, 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/web/favicon.png -------------------------------------------------------------------------------- /web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/web/icons/Icon-192.png -------------------------------------------------------------------------------- /web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/web/icons/Icon-512.png -------------------------------------------------------------------------------- /web/icons/Icon-maskable-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/web/icons/Icon-maskable-192.png -------------------------------------------------------------------------------- /web/icons/Icon-maskable-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thisisyusub/tdd-learn-example/6d532baba9c95f91c60cd7d59de5fa6896af9964/web/icons/Icon-maskable-512.png -------------------------------------------------------------------------------- /web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | tdd_example 33 | 34 | 35 | 36 | 39 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tdd_example", 3 | "short_name": "tdd_example", 4 | "start_url": ".", 5 | "display": "standalone", 6 | "background_color": "#0175C2", 7 | "theme_color": "#0175C2", 8 | "description": "A new Flutter project.", 9 | "orientation": "portrait-primary", 10 | "prefer_related_applications": false, 11 | "icons": [ 12 | { 13 | "src": "icons/Icon-192.png", 14 | "sizes": "192x192", 15 | "type": "image/png" 16 | }, 17 | { 18 | "src": "icons/Icon-512.png", 19 | "sizes": "512x512", 20 | "type": "image/png" 21 | }, 22 | { 23 | "src": "icons/Icon-maskable-192.png", 24 | "sizes": "192x192", 25 | "type": "image/png", 26 | "purpose": "maskable" 27 | }, 28 | { 29 | "src": "icons/Icon-maskable-512.png", 30 | "sizes": "512x512", 31 | "type": "image/png", 32 | "purpose": "maskable" 33 | } 34 | ] 35 | } 36 | --------------------------------------------------------------------------------