├── lib ├── presentation │ ├── home │ │ ├── profile │ │ │ ├── profile_tab_router.dart │ │ │ └── profile_tab.dart │ │ ├── primary │ │ │ ├── bloc │ │ │ │ ├── primary_tab_event.dart │ │ │ │ ├── primary_tab_state.dart │ │ │ │ └── primary_tab_bloc.dart │ │ │ ├── component │ │ │ │ └── product_item_component.dart │ │ │ ├── primary_tab_router.dart │ │ │ └── primary_tab.dart │ │ └── home_page.dart │ ├── common │ │ ├── shared_component │ │ │ ├── text_header.shared_component.dart │ │ │ ├── danger_button.shared_component.dart │ │ │ └── primary_button.shared_component.dart │ │ └── infra │ │ │ └── router.dart │ ├── login │ │ ├── bloc │ │ │ ├── login_event.dart │ │ │ ├── login_state.dart │ │ │ └── login_bloc.dart │ │ └── login_page.dart │ ├── register │ │ ├── bloc │ │ │ ├── register_event.dart │ │ │ ├── register_state.dart │ │ │ └── register_bloc.dart │ │ └── register.page.dart │ ├── create_product │ │ ├── bloc │ │ │ ├── create_product_event.dart │ │ │ ├── create_product_state.dart │ │ │ └── create_product_bloc.dart │ │ └── create_product_page.dart │ ├── detail │ │ ├── bloc │ │ │ ├── detail_product_event.dart │ │ │ ├── detail_product_state.dart │ │ │ └── detail_product_bloc.dart │ │ └── detail_page.dart │ └── splash │ │ └── splash.page.dart ├── data │ ├── common │ │ ├── util │ │ │ └── serializable.dart │ │ ├── module │ │ │ ├── shared_pref_module.dart │ │ │ └── network_module.dart │ │ ├── errors │ │ │ └── error.mapper.dart │ │ ├── interceptor │ │ │ └── request_interceptor.dart │ │ └── response │ │ │ └── response_wrapper.dart │ ├── login │ │ ├── remote │ │ │ ├── api │ │ │ │ ├── login_api.dart │ │ │ │ └── login_api_impl.dart │ │ │ └── dto │ │ │ │ ├── login_request.dart │ │ │ │ └── login_response.dart │ │ └── repository │ │ │ └── login_repository_impl.dart │ ├── register │ │ ├── remote │ │ │ ├── api │ │ │ │ ├── register_api.dart │ │ │ │ └── register_api_impl.dart │ │ │ └── dto │ │ │ │ ├── register_request.dart │ │ │ │ └── register_response.dart │ │ └── repository │ │ │ └── register_repository_impl.dart │ └── product │ │ ├── remote │ │ ├── dto │ │ │ ├── create_product_request.dart │ │ │ ├── update_product_request.dart │ │ │ ├── product_user_response.dart │ │ │ └── product_response.dart │ │ └── api │ │ │ ├── product_api.dart │ │ │ └── product_api_impl.dart │ │ └── repository │ │ └── product_repository_impl.dart ├── domain │ ├── product │ │ ├── repository │ │ │ ├── delete_product_repository.dart │ │ │ ├── get_product_repository.dart │ │ │ ├── create_product_repository.dart │ │ │ └── update_product_repository.dart │ │ ├── usecase │ │ │ ├── delete_product_usecase.dart │ │ │ ├── find_all_product_usecase.dart │ │ │ ├── find_product_by_id_usecase.dart │ │ │ ├── create_product_usecase.dart │ │ │ └── update_product_usecase.dart │ │ └── entity │ │ │ ├── user_product_entity.dart │ │ │ └── product_entity.dart │ ├── login │ │ ├── repository │ │ │ └── login_repository.dart │ │ ├── usecase │ │ │ └── login_usecase.dart │ │ └── entity │ │ │ └── login_entity.dart │ ├── register │ │ ├── repository │ │ │ └── register_repository.dart │ │ ├── usecase │ │ │ └── register_usecase.dart │ │ └── entity │ │ │ └── register_entity.dart │ └── common │ │ └── base │ │ ├── base_exception.dart │ │ ├── base_result.dart │ │ └── base_failure.dart └── main.dart ├── ios ├── Flutter │ ├── Debug.xcconfig │ ├── Release.xcconfig │ └── AppFrameworkInfo.plist ├── Runner │ ├── Runner-Bridging-Header.h │ ├── Assets.xcassets │ │ ├── LaunchImage.imageset │ │ │ ├── LaunchImage.png │ │ │ ├── LaunchImage@2x.png │ │ │ ├── LaunchImage@3x.png │ │ │ ├── README.md │ │ │ └── Contents.json │ │ └── AppIcon.appiconset │ │ │ ├── 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-1024x1024@1x.png │ │ │ ├── Icon-App-83.5x83.5@2x.png │ │ │ └── Contents.json │ ├── AppDelegate.swift │ ├── Base.lproj │ │ ├── Main.storyboard │ │ └── LaunchScreen.storyboard │ └── Info.plist ├── Runner.xcodeproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ ├── WorkspaceSettings.xcsettings │ │ │ └── IDEWorkspaceChecks.plist │ ├── xcshareddata │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ └── project.pbxproj ├── Runner.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ ├── WorkspaceSettings.xcsettings │ │ └── IDEWorkspaceChecks.plist └── .gitignore ├── web ├── favicon.png ├── icons │ ├── Icon-192.png │ └── Icon-512.png ├── manifest.json └── index.html ├── android ├── gradle.properties ├── app │ ├── src │ │ ├── main │ │ │ ├── res │ │ │ │ ├── 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 │ │ │ │ ├── drawable │ │ │ │ │ └── launch_background.xml │ │ │ │ ├── drawable-v21 │ │ │ │ │ └── launch_background.xml │ │ │ │ ├── values │ │ │ │ │ └── styles.xml │ │ │ │ └── values-night │ │ │ │ │ └── styles.xml │ │ │ ├── kotlin │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── flutter_clean_architecture │ │ │ │ │ └── MainActivity.kt │ │ │ └── AndroidManifest.xml │ │ ├── debug │ │ │ └── AndroidManifest.xml │ │ └── profile │ │ │ └── AndroidManifest.xml │ └── build.gradle ├── gradle │ └── wrapper │ │ └── gradle-wrapper.properties ├── .gitignore ├── settings.gradle └── build.gradle ├── .metadata ├── README.md ├── .gitignore ├── test └── widget_test.dart ├── pubspec.yaml └── pubspec.lock /lib/presentation/home/profile/profile_tab_router.dart: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ydhnwb/flutter-clean-architecture/HEAD/web/favicon.png -------------------------------------------------------------------------------- /lib/data/common/util/serializable.dart: -------------------------------------------------------------------------------- 1 | abstract class Serializable { 2 | Map toJson(); 3 | } -------------------------------------------------------------------------------- /web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ydhnwb/flutter-clean-architecture/HEAD/web/icons/Icon-192.png -------------------------------------------------------------------------------- /web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ydhnwb/flutter-clean-architecture/HEAD/web/icons/Icon-512.png -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | android.useAndroidX=true 3 | android.enableJetifier=true 4 | -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ydhnwb/flutter-clean-architecture/HEAD/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ydhnwb/flutter-clean-architecture/HEAD/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ydhnwb/flutter-clean-architecture/HEAD/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ydhnwb/flutter-clean-architecture/HEAD/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ydhnwb/flutter-clean-architecture/HEAD/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ydhnwb/flutter-clean-architecture/HEAD/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ydhnwb/flutter-clean-architecture/HEAD/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/ydhnwb/flutter-clean-architecture/HEAD/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/ydhnwb/flutter-clean-architecture/HEAD/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/ydhnwb/flutter-clean-architecture/HEAD/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/ydhnwb/flutter-clean-architecture/HEAD/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/ydhnwb/flutter-clean-architecture/HEAD/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/ydhnwb/flutter-clean-architecture/HEAD/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/ydhnwb/flutter-clean-architecture/HEAD/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/ydhnwb/flutter-clean-architecture/HEAD/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/ydhnwb/flutter-clean-architecture/HEAD/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/ydhnwb/flutter-clean-architecture/HEAD/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/ydhnwb/flutter-clean-architecture/HEAD/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/ydhnwb/flutter-clean-architecture/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ydhnwb/flutter-clean-architecture/HEAD/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ydhnwb/flutter-clean-architecture/HEAD/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ydhnwb/flutter-clean-architecture/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ydhnwb/flutter-clean-architecture/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /android/app/src/main/kotlin/com/example/flutter_clean_architecture/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.flutter_clean_architecture 2 | 3 | import io.flutter.embedding.android.FlutterActivity 4 | 5 | class MainActivity: FlutterActivity() { 6 | } 7 | -------------------------------------------------------------------------------- /lib/domain/product/repository/delete_product_repository.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:flutter_clean_architecture/domain/common/base/base_failure.dart'; 3 | 4 | 5 | abstract class DeleteProductRepository { 6 | Future> delete(String id); 7 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/data/login/remote/api/login_api.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_clean_architecture/data/login/remote/dto/login_request.dart'; 2 | import 'package:flutter_clean_architecture/domain/login/entity/login_entity.dart'; 3 | 4 | abstract class LoginApi { 5 | Future login(LoginRequest loginRequest); 6 | } 7 | -------------------------------------------------------------------------------- /ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /lib/data/register/remote/api/register_api.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_clean_architecture/data/register/remote/dto/register_request.dart'; 2 | import 'package:flutter_clean_architecture/domain/register/entity/register_entity.dart'; 3 | 4 | abstract class RegisterApi { 5 | Future register(RegisterRequest registerRequest); 6 | } -------------------------------------------------------------------------------- /lib/data/login/remote/dto/login_request.dart: -------------------------------------------------------------------------------- 1 | 2 | 3 | class LoginRequest { 4 | late String email; 5 | late String password; 6 | 7 | LoginRequest({required this.email, required this.password}); 8 | 9 | Map toJson(){ 10 | return { 11 | "email": email, 12 | "password": password 13 | }; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lib/data/product/remote/dto/create_product_request.dart: -------------------------------------------------------------------------------- 1 | class CreateProductRequest { 2 | late String name; 3 | late int price; 4 | 5 | CreateProductRequest({required this.name, required this.price}); 6 | 7 | Map toJson(){ 8 | return { 9 | "name": this.name, 10 | "price": this.price 11 | }; 12 | } 13 | } -------------------------------------------------------------------------------- /lib/data/product/remote/dto/update_product_request.dart: -------------------------------------------------------------------------------- 1 | class UpdateProductRequest { 2 | late String name; 3 | late int price; 4 | 5 | UpdateProductRequest({required this.name, required this.price}); 6 | 7 | Map toJson(){ 8 | return { 9 | "name": this.name, 10 | "price": this.price 11 | }; 12 | } 13 | } -------------------------------------------------------------------------------- /lib/presentation/home/primary/bloc/primary_tab_event.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | 3 | abstract class PrimaryTabEvent extends Equatable{} 4 | 5 | class PrimaryTabEventGetProducts implements PrimaryTabEvent { 6 | @override 7 | List get props => []; 8 | 9 | @override 10 | bool? get stringify => false; 11 | 12 | } -------------------------------------------------------------------------------- /.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: 02c026b03cd31dd3f867e5faeb7e104cce174c5f 8 | channel: stable 9 | 10 | project_type: app 11 | -------------------------------------------------------------------------------- /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. -------------------------------------------------------------------------------- /android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /lib/data/register/remote/dto/register_request.dart: -------------------------------------------------------------------------------- 1 | class RegisterRequest { 2 | final String name; 3 | final String email; 4 | final String password; 5 | 6 | RegisterRequest({ required this.name, required this.email, required this.password }); 7 | 8 | Map toJson(){ 9 | return { 10 | "name": this.name, 11 | "email": this.email, 12 | "password": this.password 13 | }; 14 | } 15 | } -------------------------------------------------------------------------------- /lib/presentation/common/shared_component/text_header.shared_component.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class TextHeader extends StatelessWidget { 4 | final String text; 5 | const TextHeader({Key? key, required this.text}) : super(key: key); 6 | 7 | @override 8 | Widget build(BuildContext context) { 9 | return Text(this.text, style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold),); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lib/domain/product/repository/get_product_repository.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:flutter_clean_architecture/domain/common/base/base_failure.dart'; 3 | import 'package:flutter_clean_architecture/domain/product/entity/product_entity.dart'; 4 | 5 | abstract class GetProductRepository { 6 | Future, Failure>> getAllProduct(); 7 | Future> getSingleProduct(String id); 8 | } -------------------------------------------------------------------------------- /lib/domain/login/repository/login_repository.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:flutter_clean_architecture/data/login/remote/dto/login_request.dart'; 3 | import 'package:flutter_clean_architecture/domain/common/base/base_failure.dart'; 4 | import 'package:flutter_clean_architecture/domain/login/entity/login_entity.dart'; 5 | 6 | abstract class LoginRepository { 7 | Future> login(LoginRequest loginRequest); 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 | -------------------------------------------------------------------------------- /lib/domain/register/repository/register_repository.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:flutter_clean_architecture/data/register/remote/dto/register_request.dart'; 3 | import 'package:flutter_clean_architecture/domain/common/base/base_failure.dart'; 4 | import 'package:flutter_clean_architecture/domain/register/entity/register_entity.dart'; 5 | 6 | abstract class RegisterRepository { 7 | Future> register(RegisterRequest registerRequest); 8 | } -------------------------------------------------------------------------------- /lib/domain/product/repository/create_product_repository.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:flutter_clean_architecture/data/product/remote/dto/create_product_request.dart'; 3 | import 'package:flutter_clean_architecture/domain/common/base/base_failure.dart'; 4 | import 'package:flutter_clean_architecture/domain/product/entity/product_entity.dart'; 5 | 6 | abstract class CreateProductRepository { 7 | Future> createProduct(CreateProductRequest createProductRequest); 8 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/domain/product/repository/update_product_repository.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:flutter_clean_architecture/data/product/remote/dto/update_product_request.dart'; 3 | import 'package:flutter_clean_architecture/domain/common/base/base_failure.dart'; 4 | import 'package:flutter_clean_architecture/domain/product/entity/product_entity.dart'; 5 | 6 | abstract class UpdateProductRepository { 7 | Future> updateProduct(UpdateProductRequest updateProductRequest, String id); 8 | } -------------------------------------------------------------------------------- /lib/presentation/login/bloc/login_event.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | import 'package:flutter_clean_architecture/data/login/remote/dto/login_request.dart'; 3 | 4 | abstract class LoginEvent extends Equatable{} 5 | 6 | class LoginEventDoLogin implements LoginEvent { 7 | final LoginRequest loginRequest; 8 | 9 | LoginEventDoLogin({required this.loginRequest}); 10 | 11 | @override 12 | List get props => [loginRequest]; 13 | 14 | @override 15 | bool? get stringify => false; 16 | 17 | } -------------------------------------------------------------------------------- /android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /lib/domain/common/base/base_exception.dart: -------------------------------------------------------------------------------- 1 | // class ServerException implements Exception{ 2 | // final int httpStatusCode; 3 | 4 | // ServerException({required this.httpStatusCode}); 5 | // } 6 | 7 | // class CacheException implements Exception{ 8 | // final int localStatusCode; 9 | 10 | // CacheException({required this.localStatusCode}); 11 | // } 12 | 13 | class BaseException implements Exception { 14 | final String message; 15 | int? code = 0; 16 | 17 | BaseException({required this.message, this.code}); 18 | } 19 | -------------------------------------------------------------------------------- /android/app/src/main/res/drawable-v21/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/domain/product/usecase/delete_product_usecase.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:flutter_clean_architecture/domain/common/base/base_failure.dart'; 3 | import 'package:flutter_clean_architecture/domain/product/repository/delete_product_repository.dart'; 4 | 5 | class DeleteProductUseCase { 6 | final DeleteProductRepository deleteProductRepository; 7 | 8 | DeleteProductUseCase({required this.deleteProductRepository}); 9 | 10 | Future> invoke(String id){ 11 | return deleteProductRepository.delete(id); 12 | } 13 | } -------------------------------------------------------------------------------- /lib/data/common/module/shared_pref_module.dart: -------------------------------------------------------------------------------- 1 | import 'package:shared_preferences/shared_preferences.dart'; 2 | 3 | class SharedPreferenceModule { 4 | final SharedPreferences pref; 5 | static const String _PREF_USER = "user_data"; 6 | 7 | SharedPreferenceModule({required this.pref}); 8 | 9 | void clear() => pref.clear(); 10 | 11 | void saveUserData(String userDataInJson) => pref.setString(_PREF_USER, userDataInJson); 12 | 13 | String getUserData() { 14 | String userDataInJson = pref.getString(_PREF_USER) ?? ""; 15 | return userDataInJson; 16 | } 17 | 18 | 19 | 20 | } -------------------------------------------------------------------------------- /lib/presentation/register/bloc/register_event.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | import 'package:flutter_clean_architecture/data/register/remote/dto/register_request.dart'; 3 | 4 | abstract class RegisterPageEvent extends Equatable{} 5 | 6 | 7 | class RegisterPageEventDoRegister implements RegisterPageEvent { 8 | final RegisterRequest registerRequest; 9 | 10 | RegisterPageEventDoRegister({ required this.registerRequest }); 11 | 12 | @override 13 | List get props => [registerRequest]; 14 | 15 | @override 16 | bool? get stringify => false; 17 | 18 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # flutter_clean_architecture 2 | 3 | A new Flutter project. 4 | 5 | ## Getting Started 6 | 7 | This project is a starting point for a Flutter application. 8 | 9 | A few resources to get you started if this is your first Flutter project: 10 | 11 | - [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab) 12 | - [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook) 13 | 14 | For help getting started with Flutter, view our 15 | [online documentation](https://flutter.dev/docs), which offers tutorials, 16 | samples, guidance on mobile development, and a full API reference. 17 | -------------------------------------------------------------------------------- /lib/data/common/errors/error.mapper.dart: -------------------------------------------------------------------------------- 1 | class ErrorMapper { 2 | static const _HTTP_CODE_UNAUTHORIZED = 401; 3 | static const _HTTP_CODE_NOT_FOUND = 404; 4 | static const _LOCAL_DB_NOT_FOUND = 1404; 5 | 6 | 7 | static String getErrorMessage(int statusCode){ 8 | switch(statusCode){ 9 | case _HTTP_CODE_NOT_FOUND: 10 | return "Data not found"; 11 | case _HTTP_CODE_UNAUTHORIZED: 12 | return "Wrong credentials."; 13 | case _LOCAL_DB_NOT_FOUND: 14 | return "Data not found on local database"; 15 | default: 16 | return "Something wrong. [$statusCode]"; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /lib/presentation/create_product/bloc/create_product_event.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | import 'package:flutter_clean_architecture/data/product/remote/dto/create_product_request.dart'; 3 | 4 | abstract class CreateProductPageEvent extends Equatable {} 5 | 6 | class CreateProductPageEventCreateProduct implements CreateProductPageEvent { 7 | final CreateProductRequest createProductRequest; 8 | 9 | CreateProductPageEventCreateProduct({required this.createProductRequest}); 10 | 11 | @override 12 | List get props => [createProductRequest]; 13 | 14 | @override 15 | bool? get stringify => false; 16 | 17 | } -------------------------------------------------------------------------------- /lib/domain/product/usecase/find_all_product_usecase.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:flutter_clean_architecture/domain/common/base/base_failure.dart'; 3 | import 'package:flutter_clean_architecture/domain/product/entity/product_entity.dart'; 4 | import 'package:flutter_clean_architecture/domain/product/repository/get_product_repository.dart'; 5 | 6 | class FindAllProductUseCase { 7 | final GetProductRepository getProductRepository; 8 | 9 | FindAllProductUseCase({required this.getProductRepository}); 10 | 11 | Future, Failure>> invoke(){ 12 | return getProductRepository.getAllProduct(); 13 | } 14 | } -------------------------------------------------------------------------------- /lib/domain/product/usecase/find_product_by_id_usecase.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:flutter_clean_architecture/domain/common/base/base_failure.dart'; 3 | import 'package:flutter_clean_architecture/domain/product/entity/product_entity.dart'; 4 | import 'package:flutter_clean_architecture/domain/product/repository/get_product_repository.dart'; 5 | 6 | class FindProductByIdUseCase { 7 | final GetProductRepository getProductRepository; 8 | 9 | FindProductByIdUseCase({required this.getProductRepository}); 10 | 11 | Future> invoke(String id){ 12 | return getProductRepository.getSingleProduct(id); 13 | } 14 | } -------------------------------------------------------------------------------- /lib/data/product/remote/api/product_api.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_clean_architecture/data/product/remote/dto/create_product_request.dart'; 2 | import 'package:flutter_clean_architecture/data/product/remote/dto/update_product_request.dart'; 3 | import 'package:flutter_clean_architecture/domain/product/entity/product_entity.dart'; 4 | 5 | abstract class ProductApi { 6 | Future> findAllProduct(); 7 | Future findProductById(String id); 8 | Future create(CreateProductRequest createProductRequest); 9 | Future update(UpdateProductRequest updateProductRequest, String id); 10 | Future delete(String id); 11 | } -------------------------------------------------------------------------------- /lib/domain/common/base/base_result.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | 3 | class BaseResult extends Equatable{ 4 | BaseResult(); 5 | 6 | factory BaseResult.success(T data) { 7 | var success = Success(data); 8 | return success; 9 | } 10 | 11 | factory BaseResult.error(U err) { 12 | var error = Error(err); 13 | return error; 14 | } 15 | 16 | @override 17 | List get props => []; 18 | } 19 | 20 | class Success extends BaseResult { 21 | final T data; 22 | Success(this.data); 23 | } 24 | 25 | class Error extends BaseResult { 26 | final U error; 27 | Error(this.error); 28 | } 29 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.3.50' 3 | repositories { 4 | google() 5 | jcenter() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:4.1.0' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | jcenter() 18 | } 19 | } 20 | 21 | rootProject.buildDir = '../build' 22 | subprojects { 23 | project.buildDir = "${rootProject.buildDir}/${project.name}" 24 | project.evaluationDependsOn(':app') 25 | } 26 | 27 | task clean(type: Delete) { 28 | delete rootProject.buildDir 29 | } 30 | -------------------------------------------------------------------------------- /ios/.gitignore: -------------------------------------------------------------------------------- 1 | *.mode1v3 2 | *.mode2v3 3 | *.moved-aside 4 | *.pbxuser 5 | *.perspectivev3 6 | **/*sync/ 7 | .sconsign.dblite 8 | .tags* 9 | **/.vagrant/ 10 | **/DerivedData/ 11 | Icon? 12 | **/Pods/ 13 | **/.symlinks/ 14 | profile 15 | xcuserdata 16 | **/.generated/ 17 | Flutter/App.framework 18 | Flutter/Flutter.framework 19 | Flutter/Flutter.podspec 20 | Flutter/Generated.xcconfig 21 | Flutter/ephemeral/ 22 | Flutter/app.flx 23 | Flutter/app.zip 24 | Flutter/flutter_assets/ 25 | Flutter/flutter_export_environment.sh 26 | ServiceDefinitions.json 27 | Runner/GeneratedPluginRegistrant.* 28 | 29 | # Exceptions to above rules. 30 | !default.mode1v3 31 | !default.mode2v3 32 | !default.pbxuser 33 | !default.perspectivev3 34 | -------------------------------------------------------------------------------- /web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "flutter_clean_architecture", 3 | "short_name": "flutter_clean_architecture", 4 | "start_url": ".", 5 | "display": "standalone", 6 | "background_color": "#0175C2", 7 | "theme_color": "#0175C2", 8 | "description": "A new Flutter project.", 9 | "orientation": "portrait-primary", 10 | "prefer_related_applications": false, 11 | "icons": [ 12 | { 13 | "src": "icons/Icon-192.png", 14 | "sizes": "192x192", 15 | "type": "image/png" 16 | }, 17 | { 18 | "src": "icons/Icon-512.png", 19 | "sizes": "512x512", 20 | "type": "image/png" 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /lib/domain/login/usecase/login_usecase.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:flutter_clean_architecture/data/login/remote/dto/login_request.dart'; 3 | import 'package:flutter_clean_architecture/domain/common/base/base_failure.dart'; 4 | import 'package:flutter_clean_architecture/domain/login/entity/login_entity.dart'; 5 | import 'package:flutter_clean_architecture/domain/login/repository/login_repository.dart'; 6 | 7 | class LoginUseCase { 8 | final LoginRepository loginRepository; 9 | 10 | LoginUseCase({required this.loginRepository}); 11 | 12 | Future> login(LoginRequest loginRequest) async { 13 | return await loginRepository.login(loginRequest); 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /lib/data/login/remote/dto/login_response.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_clean_architecture/data/common/util/serializable.dart'; 2 | 3 | class LoginResponse implements Serializable { 4 | int? id; 5 | String? name; 6 | String? email; 7 | String? token; 8 | 9 | LoginResponse({ this.id, this.name, this.email, this.token }); 10 | 11 | factory LoginResponse.fromJson(Map json) { 12 | return LoginResponse(id: json["id"], name: json["name"], email: json["email"], token: json["token"]); 13 | } 14 | 15 | @override 16 | Map toJson() { 17 | return { 18 | "id" : this.id, 19 | "name": this.name, 20 | "email": this.email, 21 | "token": this.token 22 | }; 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /lib/data/product/remote/dto/product_user_response.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_clean_architecture/data/common/util/serializable.dart'; 2 | 3 | class UserProductResponse implements Serializable { 4 | int? id; 5 | String? name; 6 | String? email; 7 | 8 | UserProductResponse({ 9 | required this.id, 10 | required this.name, 11 | required this.email 12 | }); 13 | 14 | factory UserProductResponse.fromJson(Map json){ 15 | return UserProductResponse(id: json["id"], name: json["name"], email: json["email"]); 16 | } 17 | 18 | @override 19 | Map toJson() { 20 | return { 21 | "id": this.id, 22 | "name": this.name, 23 | "email": this.email 24 | }; 25 | } 26 | 27 | 28 | } -------------------------------------------------------------------------------- /lib/domain/register/usecase/register_usecase.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_clean_architecture/data/register/remote/dto/register_request.dart'; 2 | import 'package:flutter_clean_architecture/domain/common/base/base_failure.dart'; 3 | import 'package:flutter_clean_architecture/domain/register/entity/register_entity.dart'; 4 | import 'package:flutter_clean_architecture/domain/register/repository/register_repository.dart'; 5 | import 'package:dartz/dartz.dart'; 6 | 7 | class RegisterUseCase { 8 | final RegisterRepository registerRepository; 9 | 10 | RegisterUseCase({required this.registerRepository}); 11 | 12 | Future> invoke(RegisterRequest registerRequest) async { 13 | return await registerRepository.register(registerRequest); 14 | } 15 | } -------------------------------------------------------------------------------- /lib/domain/product/usecase/create_product_usecase.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:flutter_clean_architecture/data/product/remote/dto/create_product_request.dart'; 3 | import 'package:flutter_clean_architecture/domain/common/base/base_failure.dart'; 4 | import 'package:flutter_clean_architecture/domain/product/entity/product_entity.dart'; 5 | import 'package:flutter_clean_architecture/domain/product/repository/create_product_repository.dart'; 6 | 7 | class CreateProductUseCase { 8 | final CreateProductRepository createProductRepository; 9 | 10 | CreateProductUseCase({required this.createProductRepository}); 11 | 12 | Future> invoke(CreateProductRequest request){ 13 | return createProductRepository.createProduct(request); 14 | } 15 | } -------------------------------------------------------------------------------- /lib/data/register/remote/dto/register_response.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_clean_architecture/data/common/util/serializable.dart'; 2 | 3 | class RegisterResponse extends Serializable{ 4 | late int id; 5 | late String name; 6 | late String email; 7 | late String token; 8 | 9 | RegisterResponse({ required this.id,required this.name, required this.email, required this.token }); 10 | 11 | factory RegisterResponse.fromJson(Map json) { 12 | return RegisterResponse(id: json["id"], name: json["name"], email: json["email"], token: json["token"]); 13 | } 14 | 15 | 16 | @override 17 | Map toJson(){ 18 | return { 19 | "id": this.id, 20 | "name": this.name, 21 | "email": this.email, 22 | "token": this.token 23 | }; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /lib/domain/login/entity/login_entity.dart: -------------------------------------------------------------------------------- 1 | 2 | import 'package:flutter_clean_architecture/data/login/remote/dto/login_response.dart'; 3 | 4 | class LoginEntity { 5 | int id; 6 | String name; 7 | String email; 8 | String token; 9 | 10 | LoginEntity({ 11 | required this.id, 12 | required this.name, 13 | required this.email, 14 | required this.token 15 | }); 16 | 17 | factory LoginEntity.toEntity(LoginResponse loginResponse){ 18 | return LoginEntity( 19 | id: loginResponse.id!, 20 | name: loginResponse.name!, 21 | email: loginResponse.email!, 22 | token: loginResponse.token! 23 | ); 24 | } 25 | 26 | Map toJson() => { 27 | "id": id, 28 | "name": name, 29 | "email": email, 30 | "token": token 31 | }; 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /lib/domain/register/entity/register_entity.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_clean_architecture/data/register/remote/dto/register_response.dart'; 2 | 3 | class RegisterEntity { 4 | late int id; 5 | late String name; 6 | late String email; 7 | late String token; 8 | 9 | RegisterEntity({ required this.id, required this.name, required this.email, required this.token }); 10 | 11 | factory RegisterEntity.toEntity(RegisterResponse registerResponse){ 12 | return RegisterEntity( 13 | id: registerResponse.id, 14 | name: registerResponse.name, 15 | email: registerResponse.email, 16 | token: registerResponse.token 17 | ); 18 | } 19 | 20 | // Map toJson() => { 21 | // "id": id, 22 | // "name": name, 23 | // "email": email, 24 | // "token": token 25 | // }; 26 | } -------------------------------------------------------------------------------- /lib/domain/product/usecase/update_product_usecase.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:flutter_clean_architecture/data/product/remote/dto/update_product_request.dart'; 3 | import 'package:flutter_clean_architecture/domain/common/base/base_failure.dart'; 4 | import 'package:flutter_clean_architecture/domain/product/entity/product_entity.dart'; 5 | import 'package:flutter_clean_architecture/domain/product/repository/update_product_repository.dart'; 6 | 7 | class UpdateProductUseCase { 8 | final UpdateProductRepository updateProductRepository; 9 | 10 | UpdateProductUseCase({required this.updateProductRepository}); 11 | 12 | Future> invoke(UpdateProductRequest request, String id){ 13 | return updateProductRepository.updateProduct(request, id); 14 | } 15 | } -------------------------------------------------------------------------------- /lib/data/common/module/network_module.dart: -------------------------------------------------------------------------------- 1 | import 'package:dio/dio.dart'; 2 | import 'package:flutter_clean_architecture/data/common/interceptor/request_interceptor.dart'; 3 | 4 | class NetworkModule { 5 | final Dio _dio = new Dio(); 6 | final String _baseUrl = "https://golang-heroku.herokuapp.com/api/"; 7 | final RequestInterceptor requestInterceptor; 8 | 9 | NetworkModule({required this.requestInterceptor}); 10 | 11 | BaseOptions _dioOptions(){ 12 | BaseOptions opts = BaseOptions(); 13 | opts.baseUrl = _baseUrl; 14 | opts.connectTimeout = 60000; 15 | opts.receiveTimeout = 60000; 16 | opts.sendTimeout = 60000; 17 | return opts; 18 | } 19 | 20 | 21 | Dio provideDio(){ 22 | _dio.options = _dioOptions(); 23 | _dio.interceptors.add(requestInterceptor); 24 | return _dio; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib/domain/common/base/base_failure.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | 3 | abstract class Failure extends Equatable { 4 | final int code; 5 | final String message; 6 | 7 | Failure({required this.message, required this.code}); 8 | 9 | @override 10 | List get props => []; 11 | } 12 | 13 | class BaseFailure extends Failure { 14 | final int code; 15 | final String message; 16 | 17 | BaseFailure({required this.message, required this.code}) : super(message: message, code: code); 18 | 19 | 20 | } 21 | 22 | // class ServerFailure extends Failure{ 23 | // final String message; 24 | 25 | // ServerFailure({required this.message}) : super(message: message); 26 | // } 27 | // class CacheFailure extends Failure{ 28 | // final String message; 29 | 30 | // CacheFailure({required this.message}) : super(message: message); 31 | // } -------------------------------------------------------------------------------- /lib/domain/product/entity/user_product_entity.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_clean_architecture/data/product/remote/dto/product_user_response.dart'; 2 | 3 | class UserProductEntity { 4 | late int id; 5 | late String name; 6 | late String email; 7 | 8 | 9 | UserProductEntity({required this.id, required this.name, required this.email}); 10 | 11 | factory UserProductEntity.fromJson(Map json){ 12 | return UserProductEntity(id: json["id"], name: json["name"], email: json["email"]); 13 | } 14 | 15 | factory UserProductEntity.toEntity(UserProductResponse res){ 16 | return UserProductEntity( 17 | id: res.id!, 18 | name: res.name!, 19 | email: res.email! 20 | ); 21 | } 22 | 23 | Map toJson(){ 24 | return { 25 | "id": this.id, 26 | "name": this.name, 27 | "email": this.email 28 | }; 29 | } 30 | } -------------------------------------------------------------------------------- /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 | 8.0 25 | 26 | 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 | -------------------------------------------------------------------------------- /lib/data/product/remote/dto/product_response.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_clean_architecture/data/common/util/serializable.dart'; 2 | import 'package:flutter_clean_architecture/data/product/remote/dto/product_user_response.dart'; 3 | 4 | class ProductResponse implements Serializable { 5 | int? id; 6 | String? name; 7 | int? price; 8 | UserProductResponse? user; 9 | 10 | ProductResponse( 11 | {required this.id, 12 | required this.name, 13 | required this.price, 14 | required this.user}); 15 | 16 | factory ProductResponse.fromJson(Map json) { 17 | return ProductResponse( 18 | id: json["id"], 19 | name: json["product_name"], 20 | price: json["price"], 21 | user: UserProductResponse.fromJson(json["user"])); 22 | } 23 | 24 | @override 25 | Map toJson() { 26 | return { 27 | "id": this.id, 28 | "product_name": this.name, 29 | "price": this.price, 30 | "user": this.user?.toJson() 31 | }; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /android/app/src/main/res/values-night/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /lib/presentation/common/shared_component/danger_button.shared_component.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class DangerButton extends StatelessWidget { 4 | final String text; 5 | final VoidCallback? onClick; 6 | const DangerButton({Key? key, required this.text, required this.onClick}) : super(key: key); 7 | 8 | 9 | 10 | @override 11 | Widget build(BuildContext context) { 12 | return ConstrainedBox( 13 | constraints: BoxConstraints.tightFor( 14 | width: double.infinity, 15 | height: 46, 16 | ), 17 | child: ElevatedButton( 18 | style: ElevatedButton.styleFrom( 19 | primary: Colors.red, 20 | shape: RoundedRectangleBorder( 21 | borderRadius: BorderRadius.circular(14) 22 | ) 23 | ), 24 | onPressed: onClick, 25 | child: Text(text.toUpperCase(), 26 | style: TextStyle( 27 | fontWeight: FontWeight.bold, 28 | fontSize: 16, 29 | ) 30 | ) 31 | ), 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lib/presentation/common/shared_component/primary_button.shared_component.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class PrimaryButton extends StatelessWidget { 5 | final String text; 6 | final VoidCallback? onClick; 7 | const PrimaryButton({Key? key, required this.text, required this.onClick}) : super(key: key); 8 | 9 | 10 | 11 | @override 12 | Widget build(BuildContext context) { 13 | return ConstrainedBox( 14 | constraints: BoxConstraints.tightFor( 15 | width: double.infinity, 16 | height: 46, 17 | ), 18 | child: ElevatedButton( 19 | style: ElevatedButton.styleFrom( 20 | shape: RoundedRectangleBorder( 21 | borderRadius: BorderRadius.circular(14) 22 | ) 23 | ), 24 | onPressed: onClick, 25 | child: Text(text.toUpperCase(), 26 | style: TextStyle( 27 | fontWeight: FontWeight.bold, 28 | fontSize: 16, 29 | ) 30 | ) 31 | ), 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lib/domain/product/entity/product_entity.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_clean_architecture/data/product/remote/dto/product_response.dart'; 2 | import 'package:flutter_clean_architecture/domain/product/entity/user_product_entity.dart'; 3 | 4 | class ProductEntity { 5 | late int id; 6 | late String name; 7 | late int price; 8 | late UserProductEntity user; 9 | 10 | ProductEntity({required this.id, required this.name, required this.price, required this.user}); 11 | 12 | factory ProductEntity.fromJson(Map json) { 13 | return ProductEntity(id: json["id"], name: json["name"], price: json["price"], user: UserProductEntity.fromJson(json["user"])); 14 | } 15 | 16 | factory ProductEntity.toEntity(ProductResponse res){ 17 | return ProductEntity( 18 | id: res.id!, 19 | name: res.name!, 20 | price: res.price!, 21 | user: UserProductEntity.toEntity(res.user!) 22 | ); 23 | } 24 | 25 | Map toJson(){ 26 | return { 27 | "id": this.id, 28 | "name": this.name, 29 | "price": this.price, 30 | "user": this.user.toJson() 31 | }; 32 | } 33 | } -------------------------------------------------------------------------------- /lib/presentation/home/primary/component/product_item_component.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_clean_architecture/domain/product/entity/product_entity.dart'; 3 | 4 | class ProductItem extends StatelessWidget { 5 | final ProductEntity productEntity; 6 | final VoidCallback? click; 7 | const ProductItem({ Key? key, required this.productEntity, required this.click }) : super(key: key); 8 | 9 | @override 10 | Widget build(BuildContext context) { 11 | return Card( 12 | child: InkWell( 13 | onTap: click, 14 | child: Padding( 15 | padding: const EdgeInsets.all(16), 16 | child: Column( 17 | crossAxisAlignment: CrossAxisAlignment.start, 18 | children: [ 19 | Text( 20 | productEntity.name, 21 | style: TextStyle( 22 | fontWeight: FontWeight.w600, 23 | fontSize: 18 24 | ), 25 | ), 26 | Text("Rp. ${productEntity.price}") 27 | ], 28 | ), 29 | ) 30 | ), 31 | 32 | ); 33 | } 34 | } -------------------------------------------------------------------------------- /lib/data/common/interceptor/request_interceptor.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:dio/dio.dart'; 4 | import 'package:flutter_clean_architecture/data/common/module/shared_pref_module.dart'; 5 | 6 | class RequestInterceptor extends Interceptor { 7 | final SharedPreferenceModule pref; 8 | 9 | RequestInterceptor({required this.pref}); 10 | 11 | @override 12 | void onRequest(RequestOptions options, RequestInterceptorHandler handler) { 13 | String userData = pref.getUserData(); 14 | if(userData.isNotEmpty){ 15 | String token = jsonDecode(userData)['token']; 16 | options.headers["Authorization"] = token; 17 | } 18 | return super.onRequest(options, handler); 19 | } 20 | 21 | @override 22 | void onError(DioError err, ErrorInterceptorHandler handler) { 23 | print("=== Dio Error Occured ==="); 24 | print(err.message); 25 | // consider to remap this error to generic error. 26 | return super.onError(err, handler); 27 | 28 | } 29 | 30 | @override 31 | void onResponse(Response response, ResponseInterceptorHandler handler) { 32 | return super.onResponse(response, handler); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /lib/presentation/create_product/bloc/create_product_state.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | 3 | abstract class CreateProductPageState extends Equatable{} 4 | 5 | class CreateProductPageStateInit implements CreateProductPageState{ 6 | @override 7 | List get props => []; 8 | 9 | @override 10 | bool? get stringify => false; 11 | } 12 | 13 | class CreateProductPageStateIsLoading implements CreateProductPageState { 14 | final bool isLoading; 15 | 16 | CreateProductPageStateIsLoading({required this.isLoading}); 17 | 18 | @override 19 | List get props => [isLoading]; 20 | 21 | @override 22 | bool? get stringify => false; 23 | } 24 | 25 | class CreateProductPageStateSuccessCreate implements CreateProductPageState { 26 | @override 27 | List get props => []; 28 | 29 | @override 30 | bool? get stringify => false; 31 | 32 | } 33 | 34 | class CreateProductPageStateShowMessage implements CreateProductPageState { 35 | final String message; 36 | CreateProductPageStateShowMessage({required this.message}); 37 | 38 | @override 39 | List get props => [message]; 40 | 41 | @override 42 | bool? get stringify => false; 43 | } -------------------------------------------------------------------------------- /test/widget_test.dart: -------------------------------------------------------------------------------- 1 | // This is a basic Flutter widget test. 2 | // 3 | // To perform an interaction with a widget in your test, use the WidgetTester 4 | // utility that Flutter provides. For example, you can send tap and scroll 5 | // gestures. You can also use WidgetTester to find child widgets in the widget 6 | // tree, read text, and verify that the values of widget properties are correct. 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:flutter_test/flutter_test.dart'; 10 | 11 | import 'package:flutter_clean_architecture/main.dart'; 12 | 13 | void main() { 14 | testWidgets('Counter increments smoke test', (WidgetTester tester) async { 15 | // Build our app and trigger a frame. 16 | await tester.pumpWidget(MyApp()); 17 | 18 | // Verify that our counter starts at 0. 19 | expect(find.text('0'), findsOneWidget); 20 | expect(find.text('1'), findsNothing); 21 | 22 | // Tap the '+' icon and trigger a frame. 23 | await tester.tap(find.byIcon(Icons.add)); 24 | await tester.pump(); 25 | 26 | // Verify that our counter has incremented. 27 | expect(find.text('0'), findsNothing); 28 | expect(find.text('1'), findsOneWidget); 29 | }); 30 | } 31 | -------------------------------------------------------------------------------- /lib/data/register/repository/register_repository_impl.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_clean_architecture/data/common/errors/error.mapper.dart'; 2 | import 'package:flutter_clean_architecture/data/register/remote/api/register_api.dart'; 3 | import 'package:flutter_clean_architecture/domain/common/base/base_exception.dart'; 4 | import 'package:flutter_clean_architecture/domain/register/entity/register_entity.dart'; 5 | import 'package:flutter_clean_architecture/domain/common/base/base_failure.dart'; 6 | import 'package:flutter_clean_architecture/data/register/remote/dto/register_request.dart'; 7 | import 'package:dartz/dartz.dart'; 8 | import 'package:flutter_clean_architecture/domain/register/repository/register_repository.dart'; 9 | 10 | class RegisterRepositoryImpl implements RegisterRepository { 11 | final RegisterApi registerApi; 12 | 13 | RegisterRepositoryImpl({required this.registerApi}); 14 | 15 | @override 16 | Future> register(RegisterRequest registerRequest) async { 17 | try{ 18 | var response = await registerApi.register(registerRequest); 19 | return Left(response); 20 | }on BaseException catch(e){ 21 | return Right(BaseFailure(message: e.message, code: e.code!)); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /lib/presentation/login/bloc/login_state.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | import 'package:flutter_clean_architecture/domain/login/entity/login_entity.dart'; 3 | 4 | abstract class LoginState extends Equatable {} 5 | 6 | class LoginStateInit implements LoginState{ 7 | @override 8 | List get props => []; 9 | 10 | @override 11 | bool? get stringify => false; 12 | } 13 | 14 | class LoginStateLoading implements LoginState { 15 | final bool isLoading; 16 | 17 | LoginStateLoading({required this.isLoading}); 18 | 19 | @override 20 | List get props => []; 21 | 22 | @override 23 | bool? get stringify => false; 24 | } 25 | 26 | class LoginStateSuccessLogin implements LoginState { 27 | final LoginEntity loginEntity; 28 | 29 | LoginStateSuccessLogin({required this.loginEntity}); 30 | 31 | @override 32 | List get props => [loginEntity]; 33 | 34 | @override 35 | bool? get stringify => false; 36 | } 37 | 38 | class LoginStateErrorLogin implements LoginState { 39 | final String message; 40 | 41 | LoginStateErrorLogin({required this.message}); 42 | 43 | @override 44 | List get props => [message]; 45 | 46 | @override 47 | bool? get stringify => false; 48 | } 49 | 50 | 51 | -------------------------------------------------------------------------------- /lib/presentation/detail/bloc/detail_product_event.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | import 'package:flutter_clean_architecture/data/product/remote/dto/update_product_request.dart'; 3 | 4 | abstract class DetailProductPageEvent extends Equatable{} 5 | 6 | class DetailProductPageEventFindProductById implements DetailProductPageEvent { 7 | final String id; 8 | 9 | DetailProductPageEventFindProductById({required this.id}); 10 | 11 | @override 12 | List get props => [id]; 13 | 14 | @override 15 | bool? get stringify => false; 16 | } 17 | 18 | class DetailProductPageEventUpdateProduct implements DetailProductPageEvent { 19 | final UpdateProductRequest updateProductRequest; 20 | final String id; 21 | 22 | DetailProductPageEventUpdateProduct({required this.updateProductRequest, required this.id}); 23 | 24 | @override 25 | List get props => [updateProductRequest, id]; 26 | 27 | @override 28 | bool? get stringify => false; 29 | 30 | } 31 | 32 | class DetailProductPageEvenetDeleteById implements DetailProductPageEvent { 33 | final String id; 34 | 35 | DetailProductPageEvenetDeleteById({required this.id}); 36 | 37 | @override 38 | List get props => [id]; 39 | 40 | @override 41 | bool? get stringify => false; 42 | } -------------------------------------------------------------------------------- /lib/presentation/home/primary/primary_tab_router.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_clean_architecture/main.dart'; 3 | import 'package:flutter_clean_architecture/presentation/create_product/create_product_page.dart'; 4 | import 'package:flutter_clean_architecture/presentation/detail/detail_page.dart'; 5 | import 'package:flutter_clean_architecture/presentation/home/primary/primary_tab.dart'; 6 | 7 | class PrimaryTabRouter { 8 | static const PRIMARY_TAB_ROOT = "/"; 9 | static const PRIMARY_TAB_CREATE = "/create"; 10 | static const PRIMARY_TAB_DETAIL = "/detail"; 11 | 12 | 13 | static Route generateRoute(RouteSettings settings) { 14 | switch (settings.name) { 15 | case PRIMARY_TAB_ROOT: 16 | return MaterialPageRoute(builder: (_) => PrimaryTab(primaryTabBloc: sl())); 17 | case PRIMARY_TAB_CREATE: 18 | return MaterialPageRoute(builder: (_) => CreateProductPage(bloc: sl(),)); 19 | case PRIMARY_TAB_DETAIL: 20 | String productId = settings.arguments as String; 21 | return MaterialPageRoute(builder: (_) => DetailPage(productId: productId, bloc: sl())); 22 | default: 23 | return MaterialPageRoute(builder: (_) => Scaffold(body: Center(child: Text("No route")))); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /lib/presentation/splash/splash.page.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_clean_architecture/data/common/module/shared_pref_module.dart'; 5 | import 'package:flutter_clean_architecture/main.dart'; 6 | import 'package:flutter_clean_architecture/presentation/common/infra/router.dart'; 7 | 8 | class SplashPage extends StatefulWidget { 9 | const SplashPage({ Key? key }) : super(key: key); 10 | 11 | @override 12 | _SplashPageState createState() => _SplashPageState(); 13 | } 14 | 15 | class _SplashPageState extends State { 16 | final SharedPreferenceModule pref = sl.get(); 17 | 18 | startSplash() async { 19 | return Timer(Duration(seconds: 2), (){ 20 | if(pref.getUserData().isNotEmpty){ 21 | Navigator.pushReplacementNamed(context, AppRouter.ROUTE_HOME); 22 | }else{ 23 | Navigator.pushReplacementNamed(context, AppRouter.ROUTE_LOGIN); 24 | } 25 | 26 | }); 27 | } 28 | 29 | @override 30 | void initState() { 31 | super.initState(); 32 | startSplash(); 33 | } 34 | 35 | 36 | @override 37 | Widget build(BuildContext context) { 38 | return Scaffold( 39 | body: SafeArea(child: Center( 40 | child: Text("Splash screen"), 41 | )), 42 | ); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /lib/data/login/repository/login_repository_impl.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:flutter_clean_architecture/data/common/errors/error.mapper.dart'; 3 | import 'package:flutter_clean_architecture/data/login/remote/api/login_api.dart'; 4 | import 'package:flutter_clean_architecture/domain/common/base/base_exception.dart'; 5 | import 'package:flutter_clean_architecture/domain/common/base/base_failure.dart'; 6 | import 'package:flutter_clean_architecture/domain/login/entity/login_entity.dart'; 7 | import 'package:flutter_clean_architecture/data/login/remote/dto/login_request.dart'; 8 | import 'package:flutter_clean_architecture/domain/login/repository/login_repository.dart'; 9 | 10 | class LoginRepositoryImpl implements LoginRepository { 11 | final LoginApi loginApi; 12 | 13 | LoginRepositoryImpl({ required this.loginApi }); 14 | 15 | @override 16 | Future> login(LoginRequest loginRequest) async { 17 | try{ 18 | var result = await loginApi.login(loginRequest); 19 | return Left(result); 20 | } on BaseException catch(e){ 21 | return Right(BaseFailure(message: e.message, code: e.code!)); 22 | // String errorMessage = ErrorMapper.getErrorMessage(e.httpStatusCode); 23 | // return Right(Failure(message: errorMessage)); 24 | } 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /lib/presentation/home/primary/bloc/primary_tab_state.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | import 'package:flutter_clean_architecture/domain/product/entity/product_entity.dart'; 3 | 4 | abstract class PrimaryTabState extends Equatable{} 5 | 6 | 7 | class PrimaryTabStateInit implements PrimaryTabState { 8 | @override 9 | List get props => []; 10 | 11 | @override 12 | bool? get stringify => false; 13 | } 14 | 15 | class PrimaryTabStateLoading implements PrimaryTabState { 16 | final bool isLoading; 17 | 18 | PrimaryTabStateLoading({required this.isLoading}); 19 | 20 | @override 21 | List get props => [isLoading]; 22 | 23 | @override 24 | bool? get stringify => false; 25 | 26 | } 27 | 28 | class PrimaryTabStateShowMessage implements PrimaryTabState { 29 | final String message; 30 | 31 | PrimaryTabStateShowMessage({required this.message}); 32 | 33 | @override 34 | List get props => [message]; 35 | 36 | @override 37 | bool? get stringify => false; 38 | 39 | } 40 | 41 | 42 | class PrimaryTabStateProducts implements PrimaryTabState{ 43 | final List products; 44 | 45 | PrimaryTabStateProducts ({required this.products}); 46 | 47 | @override 48 | List get props => [products]; 49 | 50 | @override 51 | bool? get stringify => false; 52 | 53 | } -------------------------------------------------------------------------------- /lib/presentation/common/infra/router.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_clean_architecture/main.dart'; 3 | import 'package:flutter_clean_architecture/presentation/home/home_page.dart'; 4 | import 'package:flutter_clean_architecture/presentation/login/login_page.dart'; 5 | import 'package:flutter_clean_architecture/presentation/register/register.page.dart'; 6 | import 'package:flutter_clean_architecture/presentation/splash/splash.page.dart'; 7 | 8 | class AppRouter { 9 | static const ROUTE_SPLASH = "/splash"; 10 | static const ROUTE_LOGIN = "/login"; 11 | static const ROUTE_HOME = "/home"; 12 | static const ROUTE_REGISTER = "/register"; 13 | 14 | 15 | static Route generateRoute(RouteSettings settings) { 16 | switch (settings.name) { 17 | case ROUTE_SPLASH: 18 | return MaterialPageRoute(builder: (_) => SplashPage()); 19 | case ROUTE_LOGIN: 20 | return MaterialPageRoute(builder: (_) => LoginPage(loginBloc: sl.get())); 21 | case ROUTE_HOME: 22 | return MaterialPageRoute(builder: (_) => HomePage()); 23 | case ROUTE_REGISTER: 24 | return MaterialPageRoute(builder: (_) => RegisterPage(registerBloc: sl())); 25 | default: 26 | return MaterialPageRoute(builder: (_) => Scaffold(body: Center(child: Text("No route")))); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /lib/data/common/response/response_wrapper.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_clean_architecture/data/common/util/serializable.dart'; 2 | 3 | class WrappedResponse { 4 | bool status; 5 | String message; 6 | T? data; 7 | 8 | WrappedResponse({ required this.status, required this.message, required this.data }); 9 | 10 | factory WrappedResponse.fromJson(Map json, Function(Map) create){ 11 | return WrappedResponse(status: json["status"], message: json["message"], data: create(json["data"])); 12 | } 13 | 14 | Map toJson() { 15 | return { 16 | "status": this.status, 17 | "message": this.message, 18 | "data": this.data?.toJson() 19 | }; 20 | } 21 | } 22 | 23 | class WrappedListResponse { 24 | bool status; 25 | String message; 26 | List? data; 27 | 28 | WrappedListResponse({ required this.status, required this.message, required this.data }); 29 | 30 | factory WrappedListResponse.fromjson(Map json, Function(List) create){ 31 | return WrappedListResponse(status: json["status"], message: json["message"], data: create(json["data"])); 32 | } 33 | 34 | Map toJson(){ 35 | return { 36 | "status": this.status, 37 | "message": this.message, 38 | "data": this.data 39 | }; 40 | } 41 | } -------------------------------------------------------------------------------- /lib/presentation/register/bloc/register_state.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | import 'package:flutter_clean_architecture/domain/register/entity/register_entity.dart'; 3 | import 'package:flutter_clean_architecture/presentation/register/register.page.dart'; 4 | 5 | abstract class RegisterPageState extends Equatable{} 6 | 7 | 8 | class RegisterPageStateInit implements RegisterPageState { 9 | @override 10 | List get props => []; 11 | 12 | @override 13 | bool? get stringify => false; 14 | 15 | } 16 | 17 | class RegisterPageStateLoading implements RegisterPageState { 18 | final bool isLoading; 19 | 20 | RegisterPageStateLoading({ required this.isLoading }); 21 | 22 | @override 23 | List get props => [isLoading]; 24 | 25 | @override 26 | bool? get stringify => false; 27 | 28 | } 29 | 30 | class RegisterPageStateSuccess implements RegisterPageState { 31 | final RegisterEntity registerEntity; 32 | 33 | RegisterPageStateSuccess({ required this.registerEntity }); 34 | 35 | @override 36 | List get props => [registerEntity]; 37 | 38 | @override 39 | bool? get stringify => false; 40 | 41 | } 42 | 43 | class RegisterPageStateError implements RegisterPageState{ 44 | final String message; 45 | 46 | RegisterPageStateError({required this.message}); 47 | 48 | @override 49 | List get props => [message]; 50 | 51 | @override 52 | bool? get stringify => false; 53 | 54 | } -------------------------------------------------------------------------------- /lib/data/register/remote/api/register_api_impl.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:dio/dio.dart'; 4 | import 'package:flutter_clean_architecture/data/common/response/response_wrapper.dart'; 5 | import 'package:flutter_clean_architecture/data/register/remote/api/register_api.dart'; 6 | import 'package:flutter_clean_architecture/data/register/remote/dto/register_response.dart'; 7 | import 'package:flutter_clean_architecture/domain/common/base/base_exception.dart'; 8 | import 'package:flutter_clean_architecture/domain/register/entity/register_entity.dart'; 9 | import 'package:flutter_clean_architecture/data/register/remote/dto/register_request.dart'; 10 | 11 | class RegisterApiImpl implements RegisterApi { 12 | final Dio dio; 13 | 14 | RegisterApiImpl({required this.dio}); 15 | 16 | @override 17 | Future register(RegisterRequest registerRequest) async { 18 | try{ 19 | final response = await dio.post("auth/register", data: registerRequest.toJson()); 20 | var converted = WrappedResponse.fromJson(response.data, (data) => RegisterResponse.fromJson(data)); 21 | if(response.statusCode == 201){ 22 | var registerEntity = RegisterEntity.toEntity(converted.data!); 23 | return registerEntity; 24 | } 25 | throw BaseException(message: converted.message, code: response.statusCode); 26 | }on DioError catch(e){ 27 | throw BaseException(message: e.message, code: e.response?.statusCode); 28 | }on Exception catch(e){ 29 | throw BaseException(message: e.toString()); 30 | } 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /lib/data/login/remote/api/login_api_impl.dart: -------------------------------------------------------------------------------- 1 | import 'package:dio/dio.dart'; 2 | import 'package:flutter_clean_architecture/data/common/response/response_wrapper.dart'; 3 | import 'package:flutter_clean_architecture/data/login/remote/api/login_api.dart'; 4 | import 'package:flutter_clean_architecture/data/login/remote/dto/login_request.dart'; 5 | import 'package:flutter_clean_architecture/data/login/remote/dto/login_response.dart'; 6 | import 'package:flutter_clean_architecture/domain/common/base/base_exception.dart'; 7 | import 'package:flutter_clean_architecture/domain/login/entity/login_entity.dart'; 8 | 9 | class LoginApiImpl implements LoginApi { 10 | final Dio dio; 11 | 12 | LoginApiImpl({required this.dio}); 13 | 14 | @override 15 | Future login(LoginRequest loginRequest) async { 16 | try{ 17 | final response = await dio.post("auth/login", data: loginRequest.toJson()); 18 | var converted = WrappedResponse.fromJson(response.data, (data) => LoginResponse.fromJson(data)); 19 | if(response.statusCode == 200){ 20 | return LoginEntity( 21 | id: converted.data!.id!, 22 | token: converted.data!.token!, 23 | email: converted.data!.email!, 24 | name: converted.data!.name! 25 | ); 26 | } 27 | throw BaseException(message: converted.message, code: response.statusCode); 28 | }on DioError catch(e){ 29 | throw BaseException(message: e.message, code: e.response?.statusCode); 30 | }on Exception catch(e){ 31 | throw BaseException(message: e.toString()); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lib/presentation/detail/bloc/detail_product_state.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | import 'package:flutter_clean_architecture/domain/product/entity/product_entity.dart'; 3 | 4 | abstract class DetailProductPageState extends Equatable{} 5 | 6 | class DetailProductPageStateInit implements DetailProductPageState{ 7 | @override 8 | List get props => []; 9 | 10 | @override 11 | bool? get stringify => false; 12 | 13 | } 14 | 15 | class DetailProductPageStateIsLoading implements DetailProductPageState{ 16 | final bool isLoading; 17 | 18 | DetailProductPageStateIsLoading({required this.isLoading}); 19 | 20 | @override 21 | List get props => [isLoading]; 22 | 23 | @override 24 | bool? get stringify => false; 25 | } 26 | 27 | class DetailProductPageStateReceiveProduct implements DetailProductPageState { 28 | final ProductEntity productEntity; 29 | DetailProductPageStateReceiveProduct({required this.productEntity}); 30 | 31 | @override 32 | List get props => [productEntity]; 33 | 34 | @override 35 | bool? get stringify => false; 36 | } 37 | 38 | class DetailProductPageStateSuccessUpdate implements DetailProductPageState { 39 | @override 40 | List get props => []; 41 | 42 | @override 43 | bool? get stringify => false; 44 | 45 | } 46 | 47 | class DetailProductPageStateShowMessage implements DetailProductPageState { 48 | final String message; 49 | 50 | DetailProductPageStateShowMessage({required this.message}); 51 | 52 | @override 53 | List get props => [message]; 54 | 55 | @override 56 | bool? get stringify => false; 57 | 58 | } -------------------------------------------------------------------------------- /lib/presentation/create_product/bloc/create_product_bloc.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_bloc/flutter_bloc.dart'; 2 | import 'package:flutter_clean_architecture/data/product/remote/dto/create_product_request.dart'; 3 | import 'package:flutter_clean_architecture/domain/product/usecase/create_product_usecase.dart'; 4 | import 'package:flutter_clean_architecture/presentation/create_product/bloc/create_product_event.dart'; 5 | import 'package:flutter_clean_architecture/presentation/create_product/bloc/create_product_state.dart'; 6 | 7 | class CreateProductPageBloc extends Bloc{ 8 | final CreateProductUseCase createProductUseCase; 9 | 10 | CreateProductPageBloc({required this.createProductUseCase}) : super(CreateProductPageStateInit()); 11 | 12 | @override 13 | Stream mapEventToState(CreateProductPageEvent event) async*{ 14 | if(event is CreateProductPageEventCreateProduct){ 15 | yield* _create(event.createProductRequest); 16 | } 17 | } 18 | 19 | Stream _setIsLoading(bool isLoading) async* { 20 | yield CreateProductPageStateIsLoading(isLoading: isLoading); 21 | } 22 | 23 | Stream _create(CreateProductRequest req) async* { 24 | yield* _setIsLoading(true); 25 | final result = await createProductUseCase.invoke(req); 26 | yield* _setIsLoading(false); 27 | yield* result.fold( 28 | (l) async* { 29 | yield CreateProductPageStateSuccessCreate(); 30 | }, 31 | (r) async* { 32 | String msg = "${r.message} [${r.code}]"; 33 | yield CreateProductPageStateShowMessage(message: msg); 34 | } 35 | ); 36 | } 37 | } -------------------------------------------------------------------------------- /ios/Runner/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /ios/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | flutter_clean_architecture 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | $(FLUTTER_BUILD_NAME) 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | UISupportedInterfaceOrientations~ipad 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationPortraitUpsideDown 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UIViewControllerBasedStatusBarAppearance 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /lib/presentation/login/bloc/login_bloc.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:flutter_bloc/flutter_bloc.dart'; 4 | import 'package:flutter_clean_architecture/data/common/module/shared_pref_module.dart'; 5 | import 'package:flutter_clean_architecture/data/login/remote/dto/login_request.dart'; 6 | import 'package:flutter_clean_architecture/domain/login/repository/login_repository.dart'; 7 | import 'package:flutter_clean_architecture/domain/login/usecase/login_usecase.dart'; 8 | import 'package:flutter_clean_architecture/presentation/login/bloc/login_event.dart'; 9 | import 'package:flutter_clean_architecture/presentation/login/bloc/login_state.dart'; 10 | 11 | class LoginBloc extends Bloc { 12 | final LoginUseCase loginUseCase; 13 | final SharedPreferenceModule sharedPreferenceModule; 14 | 15 | LoginBloc({required this.loginUseCase, required this.sharedPreferenceModule}) : super(LoginStateInit()); 16 | 17 | Stream _setIsLoading(bool isLoading) async* { 18 | yield LoginStateLoading(isLoading: isLoading); 19 | } 20 | 21 | @override 22 | Stream mapEventToState(LoginEvent event) async* { 23 | if(event is LoginEventDoLogin){ 24 | yield* login(event.loginRequest); 25 | } 26 | } 27 | 28 | Stream login(LoginRequest loginRequest) async* { 29 | yield* _setIsLoading(true); 30 | var result = await loginUseCase.login(loginRequest); 31 | yield* _setIsLoading(false); 32 | yield* result.fold( 33 | (l) async* { 34 | sharedPreferenceModule.saveUserData(jsonEncode(l)); 35 | yield LoginStateSuccessLogin(loginEntity: l); 36 | }, 37 | (r) async* { 38 | yield LoginStateErrorLogin(message: r.message); 39 | } 40 | ); 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /lib/presentation/register/bloc/register_bloc.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:flutter_bloc/flutter_bloc.dart'; 4 | import 'package:flutter_clean_architecture/data/common/module/shared_pref_module.dart'; 5 | import 'package:flutter_clean_architecture/data/register/remote/dto/register_request.dart'; 6 | import 'package:flutter_clean_architecture/domain/register/usecase/register_usecase.dart'; 7 | import 'package:flutter_clean_architecture/presentation/register/bloc/register_event.dart'; 8 | import 'package:flutter_clean_architecture/presentation/register/bloc/register_state.dart'; 9 | 10 | class RegisterBloc extends Bloc { 11 | final RegisterUseCase registerUseCase; 12 | final SharedPreferenceModule sharedPreferenceModule; 13 | 14 | RegisterBloc({ required this.registerUseCase, required this.sharedPreferenceModule }) : super(RegisterPageStateInit()); 15 | 16 | @override 17 | Stream mapEventToState(RegisterPageEvent event) async* { 18 | if(event is RegisterPageEventDoRegister){ 19 | yield* _register(event.registerRequest); 20 | } 21 | } 22 | 23 | Stream _setIsLoading(bool isLoading) async* { 24 | yield RegisterPageStateLoading(isLoading: isLoading); 25 | } 26 | 27 | Stream _register(RegisterRequest registerRequest) async* { 28 | yield* _setIsLoading(true); 29 | var result = await registerUseCase.invoke(registerRequest); 30 | yield* _setIsLoading(false); 31 | yield* result.fold( 32 | (l) async* { 33 | sharedPreferenceModule.saveUserData(jsonEncode(l)); 34 | yield RegisterPageStateSuccess(registerEntity: l); 35 | }, 36 | (r) async* { 37 | yield RegisterPageStateError(message: r.message); 38 | } 39 | ); 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /lib/presentation/home/primary/bloc/primary_tab_bloc.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_bloc/flutter_bloc.dart'; 2 | import 'package:flutter_clean_architecture/domain/product/entity/product_entity.dart'; 3 | import 'package:flutter_clean_architecture/domain/product/repository/get_product_repository.dart'; 4 | import 'package:flutter_clean_architecture/domain/product/usecase/find_all_product_usecase.dart'; 5 | import 'package:flutter_clean_architecture/presentation/home/primary/bloc/primary_tab_event.dart'; 6 | import 'package:flutter_clean_architecture/presentation/home/primary/bloc/primary_tab_state.dart'; 7 | 8 | class PrimaryTabBloc extends Bloc { 9 | final FindAllProductUseCase findAllProductUseCase; 10 | 11 | PrimaryTabBloc({required this.findAllProductUseCase}) : super(PrimaryTabStateInit()); 12 | 13 | @override 14 | Stream mapEventToState(PrimaryTabEvent event) async* { 15 | if(event is PrimaryTabEventGetProducts){ 16 | yield* _getAllProduct(); 17 | } 18 | } 19 | 20 | Stream _setLoading(bool b) async* { 21 | yield PrimaryTabStateLoading(isLoading: b); 22 | } 23 | 24 | 25 | Stream _getAllProduct() async* { 26 | try{ 27 | yield* _setLoading(true); 28 | var result = await findAllProductUseCase.invoke(); 29 | yield* _setLoading(false); 30 | yield* result.fold( 31 | (l) async* { 32 | final temps = []; 33 | temps.addAll(l); 34 | yield PrimaryTabStateProducts(products: temps); 35 | }, 36 | (r) async* { 37 | String message = "${r.message} [${r.code}]"; 38 | yield PrimaryTabStateShowMessage(message: message); 39 | } 40 | ); 41 | }on Exception catch(e){ 42 | yield PrimaryTabStateShowMessage(message: e.toString()); 43 | } 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /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 30 30 | 31 | sourceSets { 32 | main.java.srcDirs += 'src/main/kotlin' 33 | } 34 | 35 | defaultConfig { 36 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 37 | applicationId "com.example.flutter_clean_architecture" 38 | minSdkVersion 16 39 | targetSdkVersion 30 40 | versionCode flutterVersionCode.toInteger() 41 | versionName flutterVersionName 42 | } 43 | 44 | buildTypes { 45 | release { 46 | // TODO: Add your own signing config for the release build. 47 | // Signing with the debug keys for now, so `flutter run --release` works. 48 | signingConfig signingConfigs.debug 49 | } 50 | } 51 | } 52 | 53 | flutter { 54 | source '../..' 55 | } 56 | 57 | dependencies { 58 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 59 | } 60 | -------------------------------------------------------------------------------- /lib/presentation/home/profile/profile_tab.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_clean_architecture/data/common/module/shared_pref_module.dart'; 5 | import 'package:flutter_clean_architecture/presentation/common/infra/router.dart'; 6 | import 'package:flutter_clean_architecture/presentation/common/shared_component/text_header.shared_component.dart'; 7 | 8 | class ProfileTab extends StatefulWidget { 9 | final SharedPreferenceModule pref; 10 | const ProfileTab({ Key? key, required this.pref }) : super(key: key); 11 | 12 | @override 13 | _ProfileTabState createState() => _ProfileTabState(); 14 | } 15 | 16 | class _ProfileTabState extends State { 17 | String _name = ""; 18 | String _email = ""; 19 | 20 | _showProfileInfo(){ 21 | String userData = widget.pref.getUserData(); 22 | if(userData.isNotEmpty){ 23 | setState(() { 24 | _name = jsonDecode(userData)["name"]; 25 | _email = jsonDecode(userData)["email"]; 26 | }); 27 | 28 | } 29 | } 30 | 31 | _logout(){ 32 | widget.pref.clear(); 33 | Navigator.of(context, rootNavigator: true).pushReplacementNamed(AppRouter.ROUTE_LOGIN); 34 | } 35 | 36 | 37 | @override 38 | void initState() { 39 | super.initState(); 40 | _showProfileInfo(); 41 | } 42 | 43 | @override 44 | Widget build(BuildContext context) { 45 | return Scaffold( 46 | appBar: AppBar( 47 | title: Text("Profile"), 48 | ), 49 | body: Center( 50 | child: Container( 51 | child: Column( 52 | mainAxisAlignment: MainAxisAlignment.center, 53 | children: [ 54 | TextHeader(text: _name), 55 | Text(_email), 56 | ElevatedButton( 57 | onPressed: () { 58 | _logout(); 59 | }, 60 | child: Text("Sign out")) 61 | ], 62 | ), 63 | ), 64 | ), 65 | ); 66 | } 67 | } -------------------------------------------------------------------------------- /android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 13 | 17 | 21 | 26 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/data/product/repository/product_repository_impl.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartz/dartz.dart'; 2 | import 'package:flutter_clean_architecture/data/product/remote/api/product_api.dart'; 3 | import 'package:flutter_clean_architecture/data/product/remote/dto/update_product_request.dart'; 4 | import 'package:flutter_clean_architecture/data/product/remote/dto/create_product_request.dart'; 5 | import 'package:flutter_clean_architecture/domain/common/base/base_exception.dart'; 6 | import 'package:flutter_clean_architecture/domain/common/base/base_failure.dart'; 7 | import 'package:flutter_clean_architecture/domain/product/entity/product_entity.dart'; 8 | import 'package:flutter_clean_architecture/domain/product/repository/create_product_repository.dart'; 9 | import 'package:flutter_clean_architecture/domain/product/repository/delete_product_repository.dart'; 10 | import 'package:flutter_clean_architecture/domain/product/repository/get_product_repository.dart'; 11 | import 'package:flutter_clean_architecture/domain/product/repository/update_product_repository.dart'; 12 | 13 | class ProductRepositoryImpl implements GetProductRepository, CreateProductRepository, UpdateProductRepository, DeleteProductRepository { 14 | final ProductApi productApi; 15 | 16 | ProductRepositoryImpl({required this.productApi}); 17 | 18 | @override 19 | Future, Failure>> getAllProduct() async { 20 | try{ 21 | var products = await productApi.findAllProduct(); 22 | return Left(products); 23 | }on BaseException catch(e){ 24 | return Right(BaseFailure(code: e.code!, message: e.message)); 25 | } 26 | } 27 | 28 | @override 29 | Future> getSingleProduct(String id) async{ 30 | try{ 31 | var product = await productApi.findProductById(id); 32 | return Left(product); 33 | }on BaseException catch(e){ 34 | return Right(BaseFailure(code: e.code!, message: e.message)); 35 | } 36 | } 37 | 38 | @override 39 | Future> createProduct(CreateProductRequest createProductRequest) async { 40 | try{ 41 | var product = await productApi.create(createProductRequest); 42 | return Left(product); 43 | }on BaseException catch(e){ 44 | return Right(BaseFailure(message: e.message, code: e.code!)); 45 | } 46 | } 47 | 48 | @override 49 | Future> delete(String id) async { 50 | try{ 51 | var _ = await productApi.delete(id); 52 | return Left(true); 53 | }on BaseException catch(e){ 54 | return Right(BaseFailure(code: e.code!, message: e.message)); 55 | } 56 | } 57 | 58 | @override 59 | Future> updateProduct(UpdateProductRequest updateProductRequest, String id) async{ 60 | try{ 61 | var product = await productApi.update(updateProductRequest, id); 62 | return Left(product); 63 | }on BaseException catch(e){ 64 | return Right(BaseFailure(code: e.code!, message: e.message)); 65 | } 66 | } 67 | 68 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/presentation/home/home_page.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_clean_architecture/data/common/module/shared_pref_module.dart'; 3 | import 'package:flutter_clean_architecture/main.dart'; 4 | import 'package:flutter_clean_architecture/presentation/common/infra/router.dart'; 5 | import 'package:flutter_clean_architecture/presentation/home/primary/primary_tab_router.dart'; 6 | import 'package:flutter_clean_architecture/presentation/home/profile/profile_tab.dart'; 7 | 8 | class HomePage extends StatefulWidget { 9 | 10 | const HomePage({Key? key}) : super(key: key); 11 | 12 | @override 13 | _HomePageState createState() => _HomePageState(); 14 | 15 | } 16 | 17 | class _HomePageState extends State { 18 | 19 | //first is primary tab that contains a nested navigatiob 20 | //second is profile tab without any navigation 21 | var _tabProperties = [ 22 | GlobalKey(), 23 | null 24 | ]; 25 | final SharedPreferenceModule pref = sl.get(); 26 | int _selectedIndex = 0; 27 | 28 | 29 | @override 30 | void initState() { 31 | _checkIsLoggedIn(); 32 | super.initState(); 33 | } 34 | 35 | Widget _buildPrimaryTab(){ 36 | return Offstage( 37 | offstage: _selectedIndex != 0, 38 | child: Navigator( 39 | key: _tabProperties[0], 40 | initialRoute: PrimaryTabRouter.PRIMARY_TAB_ROOT, 41 | onGenerateRoute: PrimaryTabRouter.generateRoute, 42 | ), 43 | ); 44 | } 45 | 46 | Widget _buildProfileTab(){ 47 | return Offstage( 48 | offstage: _selectedIndex != 1, 49 | child: ProfileTab(pref: sl()), 50 | ); 51 | } 52 | 53 | 54 | void _checkIsLoggedIn(){ 55 | if(pref.getUserData().isEmpty){ 56 | _goToLoginPage(); 57 | } 58 | } 59 | 60 | void _goToLoginPage(){ 61 | Navigator.popAndPushNamed(context, AppRouter.ROUTE_LOGIN); 62 | } 63 | 64 | void _onBottomNavSelected(index){ 65 | setState(() { 66 | _selectedIndex = index; 67 | }); 68 | } 69 | 70 | Future _shouldExitApp() async { 71 | var key = _tabProperties[_selectedIndex]; 72 | if(key != null){ 73 | bool shouldNotExitApp = await key.currentState!.maybePop(); 74 | return !shouldNotExitApp; 75 | } 76 | return true; 77 | } 78 | 79 | 80 | @override 81 | Widget build(BuildContext context) { 82 | return WillPopScope( 83 | onWillPop: () async { 84 | return _shouldExitApp(); 85 | }, 86 | child: Scaffold( 87 | body: Stack( 88 | children: [ 89 | _buildPrimaryTab(), 90 | _buildProfileTab() 91 | ], 92 | ), 93 | bottomNavigationBar: BottomNavigationBar( 94 | currentIndex: _selectedIndex, 95 | selectedItemColor: Colors.green[600], 96 | onTap: _onBottomNavSelected, 97 | items: [ 98 | BottomNavigationBarItem( 99 | icon: Icon(Icons.dashboard), 100 | label: "Home" 101 | ), 102 | BottomNavigationBarItem( 103 | icon: Icon(Icons.person), 104 | label: "Profile" 105 | ) 106 | ], 107 | ), 108 | ), 109 | ); 110 | } 111 | } -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_clean_architecture 2 | description: A new Flutter project. 3 | 4 | # The following line prevents the package from being accidentally published to 5 | # pub.dev using `pub publish`. This is preferred for private packages. 6 | publish_to: 'none' # Remove this line if you wish to publish to pub.dev 7 | 8 | # The following defines the version and build number for your application. 9 | # A version number is three numbers separated by dots, like 1.2.43 10 | # followed by an optional build number separated by a +. 11 | # Both the version and the builder number may be overridden in flutter 12 | # build by specifying --build-name and --build-number, respectively. 13 | # In Android, build-name is used as versionName while build-number used as versionCode. 14 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning 15 | # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. 16 | # Read more about iOS versioning at 17 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html 18 | version: 1.0.0+1 19 | 20 | environment: 21 | sdk: ">=2.12.0 <3.0.0" 22 | 23 | dependencies: 24 | flutter: 25 | sdk: flutter 26 | 27 | 28 | # The following adds the Cupertino Icons font to your application. 29 | # Use with the CupertinoIcons class for iOS style icons. 30 | cupertino_icons: ^1.0.2 31 | get_it: ^7.1.3 32 | dio: ^4.0.0 33 | equatable: ^2.0.2 34 | dartz: ^0.10.0-nullsafety.2 35 | shared_preferences: ^2.0.6 36 | flutter_bloc: ^7.0.1 37 | fluttertoast: ^8.0.7 38 | 39 | dev_dependencies: 40 | flutter_test: 41 | sdk: flutter 42 | 43 | # For information on the generic Dart part of this file, see the 44 | # following page: https://dart.dev/tools/pub/pubspec 45 | 46 | # The following section is specific to Flutter. 47 | flutter: 48 | 49 | # The following line ensures that the Material Icons font is 50 | # included with your application, so that you can use the icons in 51 | # the material Icons class. 52 | uses-material-design: true 53 | 54 | # To add assets to your application, add an assets section, like this: 55 | # assets: 56 | # - images/a_dot_burr.jpeg 57 | # - images/a_dot_ham.jpeg 58 | 59 | # An image asset can refer to one or more resolution-specific "variants", see 60 | # https://flutter.dev/assets-and-images/#resolution-aware. 61 | 62 | # For details regarding adding assets from package dependencies, see 63 | # https://flutter.dev/assets-and-images/#from-packages 64 | 65 | # To add custom fonts to your application, add a fonts section here, 66 | # in this "flutter" section. Each entry in this list should have a 67 | # "family" key with the font family name, and a "fonts" key with a 68 | # list giving the asset and other descriptors for the font. For 69 | # example: 70 | # fonts: 71 | # - family: Schyler 72 | # fonts: 73 | # - asset: fonts/Schyler-Regular.ttf 74 | # - asset: fonts/Schyler-Italic.ttf 75 | # style: italic 76 | # - family: Trajan Pro 77 | # fonts: 78 | # - asset: fonts/TrajanPro.ttf 79 | # - asset: fonts/TrajanPro_Bold.ttf 80 | # weight: 700 81 | # 82 | # For details regarding fonts from package dependencies, 83 | # see https://flutter.dev/custom-fonts/#from-packages 84 | -------------------------------------------------------------------------------- /lib/presentation/home/primary/primary_tab.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_bloc/flutter_bloc.dart'; 3 | import 'package:flutter_clean_architecture/domain/product/entity/product_entity.dart'; 4 | import 'package:flutter_clean_architecture/presentation/home/primary/bloc/primary_tab_bloc.dart'; 5 | import 'package:flutter_clean_architecture/presentation/home/primary/bloc/primary_tab_event.dart'; 6 | import 'package:flutter_clean_architecture/presentation/home/primary/bloc/primary_tab_state.dart'; 7 | import 'package:flutter_clean_architecture/presentation/home/primary/component/product_item_component.dart'; 8 | import 'package:flutter_clean_architecture/presentation/home/primary/primary_tab_router.dart'; 9 | import 'package:fluttertoast/fluttertoast.dart'; 10 | 11 | class PrimaryTab extends StatefulWidget { 12 | final PrimaryTabBloc primaryTabBloc; 13 | 14 | 15 | const PrimaryTab({ Key? key, required this.primaryTabBloc }) : super(key: key); 16 | 17 | @override 18 | _PrimaryTabState createState() => _PrimaryTabState(); 19 | } 20 | 21 | class _PrimaryTabState extends State { 22 | final _products = []; 23 | bool _isLoading = false; 24 | 25 | _fetchProducts(){ 26 | widget.primaryTabBloc.add(PrimaryTabEventGetProducts()); 27 | } 28 | 29 | _handleState(state){ 30 | if(state is PrimaryTabStateLoading){ 31 | _isLoading = state.isLoading; 32 | }else if(state is PrimaryTabStateShowMessage){ 33 | Fluttertoast.showToast( 34 | msg: state.message, 35 | toastLength: Toast.LENGTH_LONG, 36 | ); 37 | }else if (state is PrimaryTabStateProducts){ 38 | _products.clear(); 39 | _products.addAll(state.products); 40 | } 41 | } 42 | 43 | _loadingWidget(){ 44 | return Center( 45 | child: Container( 46 | child: CircularProgressIndicator(), 47 | ), 48 | ); 49 | } 50 | 51 | _listWidget(){ 52 | return ListView.builder( 53 | itemCount: _products.length, 54 | itemBuilder: (context, index) { 55 | return ProductItem( 56 | click: () async { 57 | var isShouldRefresh = await Navigator.pushNamed(context, PrimaryTabRouter.PRIMARY_TAB_DETAIL, arguments: _products[index].id.toString()); 58 | if(isShouldRefresh == true){ 59 | _fetchProducts(); 60 | } 61 | }, 62 | productEntity: _products[index] 63 | ); 64 | } 65 | ); 66 | } 67 | 68 | 69 | @override 70 | void initState() { 71 | super.initState(); 72 | _fetchProducts(); 73 | } 74 | 75 | 76 | 77 | 78 | @override 79 | Widget build(BuildContext context) { 80 | return Scaffold( 81 | appBar: AppBar( 82 | title: Text("Products"), 83 | ), 84 | body: BlocConsumer( 85 | bloc: widget.primaryTabBloc, 86 | listener: (context, state) { 87 | _handleState(state); 88 | }, 89 | builder: (context, state) { 90 | return _isLoading ? _loadingWidget() : _listWidget(); 91 | }, 92 | ), 93 | floatingActionButton: FloatingActionButton( 94 | onPressed: () async { 95 | var isShouldRefresh = await Navigator.pushNamed(context, PrimaryTabRouter.PRIMARY_TAB_CREATE); 96 | if(isShouldRefresh == true){ 97 | _fetchProducts(); 98 | } 99 | }, 100 | child: Icon(Icons.add), 101 | ), 102 | 103 | ); 104 | } 105 | } -------------------------------------------------------------------------------- /lib/presentation/detail/bloc/detail_product_bloc.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_bloc/flutter_bloc.dart'; 2 | import 'package:flutter_clean_architecture/data/product/remote/dto/update_product_request.dart'; 3 | import 'package:flutter_clean_architecture/domain/product/repository/get_product_repository.dart'; 4 | import 'package:flutter_clean_architecture/domain/product/repository/update_product_repository.dart'; 5 | import 'package:flutter_clean_architecture/domain/product/usecase/delete_product_usecase.dart'; 6 | import 'package:flutter_clean_architecture/domain/product/usecase/find_product_by_id_usecase.dart'; 7 | import 'package:flutter_clean_architecture/domain/product/usecase/update_product_usecase.dart'; 8 | import 'package:flutter_clean_architecture/presentation/detail/bloc/detail_product_event.dart'; 9 | import 'package:flutter_clean_architecture/presentation/detail/bloc/detail_product_state.dart'; 10 | 11 | class DetailProductPageBloc extends Bloc{ 12 | final FindProductByIdUseCase findProductByIdUseCase; 13 | final UpdateProductUseCase updateProductUseCase; 14 | final DeleteProductUseCase deleteProductUseCase; 15 | DetailProductPageBloc({ 16 | required this.findProductByIdUseCase, 17 | required this.updateProductUseCase, 18 | required this.deleteProductUseCase 19 | }) : super(DetailProductPageStateInit()); 20 | 21 | 22 | @override 23 | Stream mapEventToState(DetailProductPageEvent event) async*{ 24 | if(event is DetailProductPageEventFindProductById){ 25 | yield* _findById(event.id); 26 | }else if(event is DetailProductPageEventUpdateProduct){ 27 | yield* _updateProduct(event.updateProductRequest, event.id); 28 | }else if(event is DetailProductPageEvenetDeleteById){ 29 | yield* _deleteProduct(event.id); 30 | } 31 | } 32 | 33 | Stream _setIsLoading(bool isLoading) async* { 34 | yield DetailProductPageStateIsLoading(isLoading: isLoading); 35 | } 36 | 37 | Stream _updateProduct(UpdateProductRequest req, String id) async* { 38 | yield* _setIsLoading(true); 39 | final result = await updateProductUseCase.invoke(req, id); 40 | yield* _setIsLoading(false); 41 | yield* result.fold( 42 | (l) async* { 43 | yield DetailProductPageStateSuccessUpdate(); 44 | }, 45 | (r) async* { 46 | String msg = "${r.message} [${r.code}]"; 47 | yield DetailProductPageStateShowMessage(message: msg); 48 | } 49 | ); 50 | } 51 | 52 | Stream _deleteProduct(String id) async* { 53 | yield* _setIsLoading(true); 54 | final result = await deleteProductUseCase.invoke(id); 55 | yield* _setIsLoading(false); 56 | yield* result.fold( 57 | (l) async* { 58 | // using the same state for now, since it is just popping 59 | yield DetailProductPageStateSuccessUpdate(); 60 | }, 61 | (r) async* { 62 | String msg = "${r.message} [${r.code}]"; 63 | yield DetailProductPageStateShowMessage(message: msg); 64 | } 65 | ); 66 | } 67 | 68 | Stream _findById(String id) async* { 69 | yield* _setIsLoading(true); 70 | final result = await findProductByIdUseCase.invoke(id); 71 | yield* _setIsLoading(false); 72 | yield* result.fold( 73 | (l) async* { 74 | yield DetailProductPageStateReceiveProduct(productEntity: l); 75 | }, 76 | (r) async* { 77 | String msg = "${r.message} [${r.code}]"; 78 | yield DetailProductPageStateShowMessage(message: msg); 79 | } 80 | ); 81 | } 82 | 83 | } -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | flutter_clean_architecture 27 | 28 | 29 | 30 | 33 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /lib/presentation/create_product/create_product_page.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_bloc/flutter_bloc.dart'; 3 | import 'package:flutter_clean_architecture/data/product/remote/dto/create_product_request.dart'; 4 | import 'package:flutter_clean_architecture/presentation/common/shared_component/primary_button.shared_component.dart'; 5 | import 'package:flutter_clean_architecture/presentation/create_product/bloc/create_product_bloc.dart'; 6 | import 'package:flutter_clean_architecture/presentation/create_product/bloc/create_product_event.dart'; 7 | import 'package:flutter_clean_architecture/presentation/create_product/bloc/create_product_state.dart'; 8 | import 'package:fluttertoast/fluttertoast.dart'; 9 | 10 | class CreateProductPage extends StatefulWidget { 11 | final CreateProductPageBloc bloc; 12 | const CreateProductPage({ Key? key, required this.bloc }) : super(key: key); 13 | 14 | @override 15 | _CreateProductPageState createState() => _CreateProductPageState(); 16 | } 17 | 18 | class _CreateProductPageState extends State { 19 | final _formKey = GlobalKey(); 20 | final _inputProductName = TextEditingController(); 21 | final _inputPrice = TextEditingController(); 22 | bool _isLoading = false; 23 | 24 | _handleState(state){ 25 | if(state is CreateProductPageStateIsLoading){ 26 | _isLoading = state.isLoading; 27 | }else if(state is CreateProductPageStateShowMessage){ 28 | Fluttertoast.showToast(msg: state.message); 29 | }else if(state is CreateProductPageStateSuccessCreate){ 30 | Navigator.of(context).pop(true); 31 | } 32 | } 33 | 34 | _doCreateProduct(){ 35 | if(_formKey.currentState!.validate()){ 36 | String name = _inputProductName.text.toString().trim(); 37 | int price = int.parse(_inputPrice.text.toString().trim()); 38 | CreateProductRequest req = CreateProductRequest(name: name, price: price); 39 | widget.bloc.add(CreateProductPageEventCreateProduct(createProductRequest: req)); 40 | } 41 | } 42 | 43 | 44 | Widget _buildProductForm(){ 45 | return Container( 46 | child: Form( 47 | key: _formKey, 48 | child: Column( 49 | children: [ 50 | TextFormField( 51 | controller: _inputProductName, 52 | decoration: InputDecoration( 53 | hintText: "Product name", 54 | ), 55 | validator: (value) { 56 | if(value == null || value.toString().trim().isEmpty){ 57 | return "Product name must not be empty"; 58 | } 59 | return null; 60 | }, 61 | ), 62 | 63 | SizedBox(height: 16), 64 | 65 | TextFormField( 66 | keyboardType: TextInputType.number, 67 | controller: _inputPrice, 68 | decoration: InputDecoration( 69 | hintText: "Price", 70 | ), 71 | validator: (value) { 72 | if(value == null || value.toString().trim().isEmpty){ 73 | return "Price must not be empty"; 74 | } 75 | return null; 76 | }, 77 | ), 78 | 79 | SizedBox(height: 16), 80 | 81 | PrimaryButton( 82 | text: "Save", 83 | onClick: _isLoading ? null : _doCreateProduct, 84 | ), 85 | ], 86 | ), 87 | ), 88 | ); 89 | } 90 | 91 | 92 | @override 93 | Widget build(BuildContext context) { 94 | return Scaffold( 95 | appBar: AppBar( 96 | title: Text("Create new product"), 97 | ), 98 | body: SingleChildScrollView( 99 | child: Container( 100 | child: Padding( 101 | padding: const EdgeInsets.all(16), 102 | child: BlocConsumer( 103 | bloc: widget.bloc, 104 | listener: (context, state) => _handleState(state), 105 | builder: (context, state){ 106 | return _buildProductForm(); 107 | }, 108 | ), 109 | ) 110 | ), 111 | ) 112 | ); 113 | } 114 | } -------------------------------------------------------------------------------- /lib/presentation/detail/detail_page.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_bloc/flutter_bloc.dart'; 3 | import 'package:flutter_clean_architecture/data/product/remote/dto/update_product_request.dart'; 4 | import 'package:flutter_clean_architecture/domain/product/entity/product_entity.dart'; 5 | import 'package:flutter_clean_architecture/presentation/common/shared_component/danger_button.shared_component.dart'; 6 | import 'package:flutter_clean_architecture/presentation/common/shared_component/primary_button.shared_component.dart'; 7 | import 'package:flutter_clean_architecture/presentation/detail/bloc/detail_product_bloc.dart'; 8 | import 'package:flutter_clean_architecture/presentation/detail/bloc/detail_product_event.dart'; 9 | import 'package:flutter_clean_architecture/presentation/detail/bloc/detail_product_state.dart'; 10 | import 'package:fluttertoast/fluttertoast.dart'; 11 | 12 | class DetailPage extends StatefulWidget { 13 | final DetailProductPageBloc bloc; 14 | final String productId; 15 | const DetailPage({ Key? key, required this.bloc, required this.productId }) : super(key: key); 16 | 17 | @override 18 | _DetailPageState createState() => _DetailPageState(); 19 | } 20 | 21 | class _DetailPageState extends State { 22 | final _formKey = GlobalKey(); 23 | final _inputProductName = TextEditingController(); 24 | final _inputPrice = TextEditingController(); 25 | bool _isLoading = true; 26 | ProductEntity? _productEntity; 27 | 28 | 29 | _fetchProductById(){ 30 | widget.bloc.add(DetailProductPageEventFindProductById(id: widget.productId)); 31 | } 32 | 33 | _updateInputController(){ 34 | if(_productEntity != null){ 35 | _inputProductName.text = _productEntity!.name; 36 | _inputPrice.text = _productEntity!.price.toString(); 37 | } 38 | } 39 | 40 | _updateProduct(){ 41 | if (_formKey.currentState!.validate()) { 42 | String name = _inputProductName.text.toString().trim(); 43 | int price = int.parse(_inputPrice.text.toString().trim()); 44 | UpdateProductRequest req = UpdateProductRequest(name: name, price: price); 45 | widget.bloc.add(DetailProductPageEventUpdateProduct(updateProductRequest:req, id: widget.productId)); 46 | } 47 | } 48 | 49 | _deleteProduct(){ 50 | widget.bloc.add(DetailProductPageEvenetDeleteById(id: widget.productId)); 51 | } 52 | 53 | _handleState(state){ 54 | if(state is DetailProductPageStateIsLoading){ 55 | _isLoading = state.isLoading; 56 | }else if(state is DetailProductPageStateReceiveProduct){ 57 | _productEntity = state.productEntity; 58 | _updateInputController(); 59 | }else if(state is DetailProductPageStateSuccessUpdate){ 60 | Navigator.of(context).pop(true); 61 | }else if(state is DetailProductPageStateShowMessage){ 62 | Fluttertoast.showToast( 63 | msg: state.message, 64 | toastLength: Toast.LENGTH_LONG, 65 | ); 66 | } 67 | } 68 | 69 | Widget _buildProductForm(){ 70 | return Container( 71 | child: Form( 72 | key: _formKey, 73 | child: Column( 74 | children: [ 75 | TextFormField( 76 | controller: _inputProductName, 77 | decoration: InputDecoration( 78 | hintText: "Product name", 79 | ), 80 | validator: (value) { 81 | if(value == null || value.toString().trim().isEmpty){ 82 | return "Product name must not be empty"; 83 | } 84 | return null; 85 | }, 86 | ), 87 | 88 | SizedBox(height: 16), 89 | 90 | TextFormField( 91 | controller: _inputPrice, 92 | keyboardType: TextInputType.number, 93 | decoration: InputDecoration( 94 | hintText: "Price", 95 | ), 96 | validator: (value) { 97 | if(value == null || value.toString().trim().isEmpty){ 98 | return "Price must not be empty"; 99 | } 100 | return null; 101 | }, 102 | ), 103 | 104 | SizedBox(height: 16), 105 | 106 | PrimaryButton( 107 | text: "Save changes", 108 | onClick: _isLoading ? null : _updateProduct, 109 | ), 110 | 111 | SizedBox(height: 16,), 112 | 113 | DangerButton( 114 | onClick: _isLoading ? null : _deleteProduct, 115 | text: "Delete", 116 | ) 117 | ], 118 | ), 119 | ), 120 | ); 121 | } 122 | 123 | @override 124 | void initState() { 125 | super.initState(); 126 | _fetchProductById(); 127 | } 128 | 129 | 130 | 131 | @override 132 | Widget build(BuildContext context) { 133 | return Scaffold( 134 | appBar: AppBar( 135 | title: Text("Detail"), 136 | ), 137 | body: SingleChildScrollView( 138 | child: Container( 139 | child: Padding( 140 | padding: const EdgeInsets.all(16), 141 | child: BlocConsumer( 142 | bloc: widget.bloc, 143 | listener: (context, state) => _handleState(state), 144 | builder: (context, state) { 145 | return _buildProductForm(); 146 | }, 147 | ), 148 | ), 149 | ), 150 | ) 151 | ); 152 | } 153 | } -------------------------------------------------------------------------------- /lib/data/product/remote/api/product_api_impl.dart: -------------------------------------------------------------------------------- 1 | import 'package:dio/dio.dart'; 2 | import 'package:flutter_clean_architecture/data/common/response/response_wrapper.dart'; 3 | import 'package:flutter_clean_architecture/data/product/remote/api/product_api.dart'; 4 | import 'package:flutter_clean_architecture/data/product/remote/dto/create_product_request.dart'; 5 | import 'package:flutter_clean_architecture/data/product/remote/dto/product_response.dart'; 6 | import 'package:flutter_clean_architecture/data/product/remote/dto/update_product_request.dart'; 7 | import 'package:flutter_clean_architecture/domain/common/base/base_exception.dart'; 8 | import 'package:flutter_clean_architecture/domain/product/entity/product_entity.dart'; 9 | import 'package:flutter_clean_architecture/domain/product/entity/user_product_entity.dart'; 10 | 11 | class ProductApiImpl implements ProductApi { 12 | final Dio dio; 13 | 14 | ProductApiImpl({required this.dio}); 15 | 16 | @override 17 | Future> findAllProduct() async { 18 | try{ 19 | final response = await dio.get("product/"); 20 | var converted = WrappedListResponse.fromjson(response.data, (data) { 21 | List products = data.map((e) => ProductResponse.fromJson(e)).toList(); 22 | return products; 23 | }); 24 | 25 | if(response.statusCode == 200){ 26 | var products = _mapToEntities(converted.data!); 27 | return products; 28 | } 29 | throw BaseException(message: converted.message, code: response.statusCode); 30 | }on DioError catch(e){ 31 | throw BaseException(message: e.message, code: e.response?.statusCode); 32 | }on Exception catch(e){ 33 | throw BaseException(message: e.toString()); 34 | } 35 | } 36 | 37 | @override 38 | Future findProductById(String id) async { 39 | try{ 40 | final response = await dio.get("product/$id"); 41 | var converted = WrappedResponse.fromJson(response.data, (data) => ProductResponse.fromJson(data)); 42 | if(response.statusCode == 200){ 43 | UserProductEntity user = UserProductEntity.toEntity(converted.data!.user!); 44 | return ProductEntity( 45 | id: converted.data!.id!, 46 | name: converted.data!.name!, 47 | price: converted.data!.price!, 48 | user: user 49 | ); 50 | }else{ 51 | throw BaseException(message: converted.message, code: response.statusCode); 52 | } 53 | }on DioError catch(e){ 54 | throw BaseException(message: e.message, code: e.response?.statusCode); 55 | }on Exception catch(e){ 56 | throw BaseException(message: e.toString()); 57 | } 58 | } 59 | 60 | @override 61 | Future create(CreateProductRequest createProductRequest) async { 62 | try{ 63 | final response = await dio.post("product/", data: createProductRequest.toJson()); 64 | var converted = WrappedResponse.fromJson(response.data, (data) => ProductResponse.fromJson(data)); 65 | if(response.statusCode == 201){ 66 | UserProductEntity user = UserProductEntity.toEntity(converted.data!.user!); 67 | return ProductEntity( 68 | id: converted.data!.id!, 69 | name: converted.data!.name!, 70 | price: converted.data!.price!, 71 | user: user 72 | ); 73 | }else{ 74 | throw BaseException(message: converted.message, code: response.statusCode); 75 | } 76 | }on DioError catch(e){ 77 | throw BaseException(message: e.message, code: e.response?.statusCode); 78 | }on Exception catch(e){ 79 | throw BaseException(message: e.toString()); 80 | } 81 | } 82 | 83 | @override 84 | Future delete(String id) async { 85 | try{ 86 | final response = await dio.delete("product/$id"); 87 | if(response.statusCode != 200){ 88 | throw BaseException(message: response.statusMessage.toString(), code: response.statusCode); 89 | } 90 | }on DioError catch(e){ 91 | throw BaseException(message: e.message, code: e.response?.statusCode); 92 | }on Exception catch(e){ 93 | throw BaseException(message: e.toString()); 94 | } 95 | } 96 | 97 | @override 98 | Future update(UpdateProductRequest updateProductRequest, String id) async { 99 | try{ 100 | final response = await dio.put("product/$id", data: updateProductRequest.toJson()); 101 | if(response.statusCode == 200){ 102 | var converted = WrappedResponse.fromJson(response.data, (data) => ProductResponse.fromJson(data)); 103 | UserProductEntity user = UserProductEntity.toEntity(converted.data!.user!); 104 | return ProductEntity( 105 | id: converted.data!.id!, 106 | name: converted.data!.name!, 107 | price: converted.data!.price!, 108 | user: user 109 | ); 110 | }else{ 111 | throw BaseException(message: response.statusMessage.toString(), code: response.statusCode); 112 | } 113 | }on DioError catch(e){ 114 | throw BaseException(message: e.message, code: e.response?.statusCode); 115 | }on Exception catch(e){ 116 | throw BaseException(message: e.toString()); 117 | } 118 | } 119 | 120 | List _mapToEntities(List products){ 121 | var temps = []; 122 | products.forEach((element) { 123 | temps.add(ProductEntity.toEntity(element)); 124 | }); 125 | return temps; 126 | } 127 | } -------------------------------------------------------------------------------- /lib/presentation/register/register.page.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/cupertino.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_bloc/flutter_bloc.dart'; 4 | import 'package:flutter_clean_architecture/data/register/remote/dto/register_request.dart'; 5 | import 'package:flutter_clean_architecture/presentation/common/infra/router.dart'; 6 | import 'package:flutter_clean_architecture/presentation/common/shared_component/primary_button.shared_component.dart'; 7 | import 'package:flutter_clean_architecture/presentation/common/shared_component/text_header.shared_component.dart'; 8 | import 'package:flutter_clean_architecture/presentation/register/bloc/register_bloc.dart'; 9 | import 'package:flutter_clean_architecture/presentation/register/bloc/register_event.dart'; 10 | import 'package:flutter_clean_architecture/presentation/register/bloc/register_state.dart'; 11 | 12 | class RegisterPage extends StatefulWidget { 13 | final RegisterBloc registerBloc; 14 | 15 | const RegisterPage({ Key? key, required this.registerBloc }) : super(key: key); 16 | 17 | @override 18 | _RegisterPageState createState() => _RegisterPageState(); 19 | } 20 | 21 | class _RegisterPageState extends State { 22 | bool _isLoading = false; 23 | bool _isObscurePassword = true; 24 | final _formKey = GlobalKey(); 25 | final _nameInputController = TextEditingController(); 26 | final _emailInputController = TextEditingController(); 27 | final _passwordInputController = TextEditingController(); 28 | 29 | 30 | void _handleState(state){ 31 | if(state is RegisterPageStateLoading){ 32 | _isLoading = state.isLoading; 33 | }else if(state is RegisterPageStateSuccess){ 34 | Navigator.pushNamedAndRemoveUntil(context, AppRouter.ROUTE_HOME, (r) => false); 35 | }else if(state is RegisterPageStateError){ 36 | _showAlert(state.message); 37 | } 38 | } 39 | 40 | 41 | void _showAlert(String message){ 42 | showCupertinoDialog( 43 | context: context, 44 | builder: (context) { 45 | return AlertDialog( 46 | content: Text(message), 47 | actions: [ 48 | TextButton( 49 | onPressed: () => Navigator.pop(context), 50 | child: Text("OK") 51 | ) 52 | ], 53 | ); 54 | } 55 | ); 56 | } 57 | 58 | void _doRegister(){ 59 | if(_formKey.currentState!.validate()){ 60 | String name = _nameInputController.text.toString().trim(); 61 | String email = _emailInputController.text.toString().trim(); 62 | String password = _passwordInputController.text.toString().trim(); 63 | RegisterRequest req = RegisterRequest(name: name, email: email, password: password); 64 | widget.registerBloc.add(RegisterPageEventDoRegister(registerRequest: req)); 65 | } 66 | } 67 | 68 | 69 | Widget _headerWidget(){ 70 | return Container( 71 | margin: const EdgeInsets.only(top: 38), 72 | child: Column( 73 | crossAxisAlignment: CrossAxisAlignment.stretch, 74 | children: [ 75 | TextHeader(text: "Create Account"), 76 | Text("Please fill up this form below to get all access from the app") 77 | ], 78 | ), 79 | ); 80 | } 81 | 82 | Widget _loadingBar(){ 83 | return Container( 84 | margin: const EdgeInsets.symmetric(vertical: 16), 85 | child: LinearProgressIndicator( 86 | value: _isLoading ? null : 0, 87 | ), 88 | ); 89 | } 90 | 91 | Widget _signUpForm(){ 92 | return Container( 93 | child: Form( 94 | key: _formKey, 95 | child: Column( 96 | children: [ 97 | TextFormField( 98 | controller: _nameInputController, 99 | decoration: InputDecoration( 100 | hintText: "Name" 101 | ), 102 | validator: (v) { 103 | if(v == null || v.toString().trim().isEmpty){ 104 | return "Name cannot be empty"; 105 | } 106 | return null; 107 | }, 108 | ), 109 | 110 | SizedBox(height: 16), 111 | 112 | TextFormField( 113 | controller: _emailInputController, 114 | decoration: InputDecoration( 115 | hintText: "Email" 116 | ), 117 | validator: (v){ 118 | if(v == null || v.trim().isEmpty){ 119 | return "Email cannot be empty"; 120 | } 121 | return null; 122 | }, 123 | ), 124 | 125 | SizedBox(height: 16,), 126 | 127 | TextFormField( 128 | controller: _passwordInputController, 129 | decoration: InputDecoration( 130 | hintText: "Password", 131 | suffix: InkWell( 132 | onTap: () { 133 | setState(() { 134 | _isObscurePassword = !_isObscurePassword; 135 | }); 136 | }, 137 | child: _isObscurePassword ? Icon(Icons.visibility_off) : Icon(Icons.visibility), 138 | ) 139 | ), 140 | obscureText: _isObscurePassword, 141 | validator: (v){ 142 | if(v == null || v.trim().length < 8){ 143 | return "Password must at least 8 characters"; 144 | } 145 | return null; 146 | }, 147 | 148 | ), 149 | 150 | SizedBox(height: 16), 151 | 152 | PrimaryButton(text: "Create account", onClick: _isLoading ? null : _doRegister) 153 | ], 154 | ) 155 | ), 156 | ); 157 | 158 | } 159 | 160 | @override 161 | Widget build(BuildContext context) { 162 | return Scaffold( 163 | body: SafeArea( 164 | child: SingleChildScrollView( 165 | child: Container( 166 | margin: const EdgeInsets.symmetric(horizontal: 16), 167 | child: BlocConsumer( 168 | bloc: widget.registerBloc, 169 | listener: (context, state) => { 170 | _handleState(state) 171 | }, 172 | builder: (context, state){ 173 | return Column( 174 | children: [ 175 | _headerWidget(), 176 | _loadingBar(), 177 | _signUpForm() 178 | ], 179 | ); 180 | }, 181 | ), 182 | ), 183 | ), 184 | 185 | ), 186 | ); 187 | } 188 | } -------------------------------------------------------------------------------- /lib/presentation/login/login_page.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/cupertino.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter/painting.dart'; 4 | import 'package:flutter_bloc/flutter_bloc.dart'; 5 | import 'package:flutter_clean_architecture/data/login/remote/dto/login_request.dart'; 6 | import 'package:flutter_clean_architecture/presentation/common/infra/router.dart'; 7 | import 'package:flutter_clean_architecture/presentation/common/shared_component/primary_button.shared_component.dart'; 8 | import 'package:flutter_clean_architecture/presentation/common/shared_component/text_header.shared_component.dart'; 9 | import 'package:flutter_clean_architecture/presentation/login/bloc/login_bloc.dart'; 10 | import 'package:flutter_clean_architecture/presentation/login/bloc/login_event.dart'; 11 | import 'package:flutter_clean_architecture/presentation/login/bloc/login_state.dart'; 12 | 13 | class LoginPage extends StatefulWidget { 14 | final LoginBloc loginBloc; 15 | const LoginPage({Key? key, required this.loginBloc}) : super(key: key); 16 | 17 | @override 18 | _LoginPageState createState() => _LoginPageState(); 19 | } 20 | 21 | class _LoginPageState extends State { 22 | bool _isLoading = false; 23 | bool _isShowPassword = false; 24 | final _formKey = GlobalKey(); 25 | final _emailTextFieldController = TextEditingController(); 26 | final _passwordTextFieldController = TextEditingController(); 27 | 28 | 29 | void _handleState(state){ 30 | if(state is LoginStateSuccessLogin){ 31 | Navigator.pushReplacementNamed(context, AppRouter.ROUTE_HOME); 32 | }else if(state is LoginStateErrorLogin){ 33 | _showAlert(state.message); 34 | }else if(state is LoginStateLoading){ 35 | _isLoading = state.isLoading; 36 | } 37 | } 38 | 39 | void _showAlert(String message){ 40 | showCupertinoDialog( 41 | context: context, 42 | builder: (context) { 43 | return AlertDialog( 44 | content: Text(message), 45 | actions: [ 46 | TextButton( 47 | onPressed: () => Navigator.pop(context), 48 | child: Text("OK") 49 | ) 50 | ], 51 | ); 52 | } 53 | ); 54 | } 55 | 56 | 57 | void _doLogin(){ 58 | if (_formKey.currentState!.validate()) { 59 | String email = _emailTextFieldController.text.toString().trim(); 60 | String password = _passwordTextFieldController.text.toString().trim(); 61 | widget.loginBloc.add(LoginEventDoLogin(loginRequest: LoginRequest(email: email, password: password))); 62 | } 63 | } 64 | 65 | void _goToRegisterPage(){ 66 | Navigator.pushNamed(context, AppRouter.ROUTE_REGISTER); 67 | } 68 | 69 | Widget _headerWidget(){ 70 | return Container( 71 | margin: EdgeInsets.only(top: 36, left: 16, right: 16), 72 | child: Column( 73 | crossAxisAlignment: CrossAxisAlignment.stretch, 74 | children: [ 75 | TextHeader(text: "Sign In"), 76 | Text("Please sign in first to get all feature of this app. If you don't have any account, create a new one"), 77 | ], 78 | ), 79 | ); 80 | } 81 | 82 | Widget _loadingBar(){ 83 | return Container( 84 | margin: EdgeInsets.only(top: 8, bottom: 28, left: 16, right: 16), 85 | child: LinearProgressIndicator( 86 | value: _isLoading ? null : 0, 87 | ), 88 | ); 89 | } 90 | 91 | 92 | Widget _createAccountSection(){ 93 | return Container( 94 | margin: EdgeInsets.symmetric(horizontal: 16, vertical: 28), 95 | child: InkWell( 96 | onTap: () => { 97 | _goToRegisterPage() 98 | }, 99 | child: Padding( 100 | padding: EdgeInsets.all(8), 101 | child: Text("Create a new account", style: TextStyle(decoration: TextDecoration.underline)) 102 | ) 103 | ), 104 | ); 105 | } 106 | 107 | 108 | 109 | 110 | Widget _signInForm(){ 111 | return Container( 112 | margin: EdgeInsets.symmetric(horizontal: 16), 113 | child: Form( 114 | key: _formKey, 115 | child: Column( 116 | children: [ 117 | TextFormField( 118 | controller: _emailTextFieldController, 119 | decoration: InputDecoration( 120 | hintText: "Email", 121 | ), 122 | validator: (value) { 123 | if(value == null || value.toString().trim().isEmpty){ 124 | return "Email must not be empty"; 125 | } 126 | return null; 127 | }, 128 | ), 129 | 130 | SizedBox(height: 16), 131 | 132 | TextFormField( 133 | obscureText: !_isShowPassword, 134 | controller: _passwordTextFieldController, 135 | decoration: InputDecoration( 136 | hintText: "Password", 137 | suffixIcon: InkWell( 138 | onTap: () => { 139 | setState(() { 140 | _isShowPassword = !_isShowPassword; 141 | }) 142 | }, 143 | child: _isShowPassword ? Icon(Icons.visibility_off) : Icon(Icons.visibility), 144 | ) 145 | ), 146 | validator: (value) { 147 | if(value == null || value.toString().trim().isEmpty){ 148 | return "Password must not be empty"; 149 | } 150 | return null; 151 | }, 152 | ), 153 | 154 | SizedBox(height: 16,), 155 | 156 | PrimaryButton( 157 | text: "Login", 158 | onClick: _isLoading ? null : _doLogin, 159 | ) 160 | ], 161 | ), 162 | ), 163 | ); 164 | } 165 | 166 | @override 167 | Widget build(BuildContext context) { 168 | return Scaffold( 169 | body: SafeArea( 170 | child: SingleChildScrollView( 171 | child: Container( 172 | child: BlocConsumer( 173 | bloc: widget.loginBloc, 174 | listener: (context, state){ 175 | _handleState(state); 176 | }, 177 | builder: (context, state) { 178 | return Column( 179 | children: [ 180 | _headerWidget(), 181 | _loadingBar(), 182 | _signInForm(), 183 | _createAccountSection() 184 | ], 185 | ); 186 | }, 187 | ) 188 | ) 189 | ) 190 | ) 191 | ); 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:dio/dio.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_clean_architecture/data/common/interceptor/request_interceptor.dart'; 4 | import 'package:flutter_clean_architecture/data/common/module/network_module.dart'; 5 | import 'package:flutter_clean_architecture/data/common/module/shared_pref_module.dart'; 6 | import 'package:flutter_clean_architecture/data/login/remote/api/login_api.dart'; 7 | import 'package:flutter_clean_architecture/data/login/remote/api/login_api_impl.dart'; 8 | import 'package:flutter_clean_architecture/data/login/repository/login_repository_impl.dart'; 9 | import 'package:flutter_clean_architecture/data/product/remote/api/product_api.dart'; 10 | import 'package:flutter_clean_architecture/data/product/remote/api/product_api_impl.dart'; 11 | import 'package:flutter_clean_architecture/data/product/repository/product_repository_impl.dart'; 12 | import 'package:flutter_clean_architecture/data/register/remote/api/register_api.dart'; 13 | import 'package:flutter_clean_architecture/data/register/remote/api/register_api_impl.dart'; 14 | import 'package:flutter_clean_architecture/data/register/repository/register_repository_impl.dart'; 15 | import 'package:flutter_clean_architecture/domain/login/repository/login_repository.dart'; 16 | import 'package:flutter_clean_architecture/domain/login/usecase/login_usecase.dart'; 17 | import 'package:flutter_clean_architecture/domain/product/repository/create_product_repository.dart'; 18 | import 'package:flutter_clean_architecture/domain/product/repository/delete_product_repository.dart'; 19 | import 'package:flutter_clean_architecture/domain/product/repository/get_product_repository.dart'; 20 | import 'package:flutter_clean_architecture/domain/product/repository/update_product_repository.dart'; 21 | import 'package:flutter_clean_architecture/domain/product/usecase/create_product_usecase.dart'; 22 | import 'package:flutter_clean_architecture/domain/product/usecase/delete_product_usecase.dart'; 23 | import 'package:flutter_clean_architecture/domain/product/usecase/find_all_product_usecase.dart'; 24 | import 'package:flutter_clean_architecture/domain/product/usecase/find_product_by_id_usecase.dart'; 25 | import 'package:flutter_clean_architecture/domain/product/usecase/update_product_usecase.dart'; 26 | import 'package:flutter_clean_architecture/domain/register/repository/register_repository.dart'; 27 | import 'package:flutter_clean_architecture/domain/register/usecase/register_usecase.dart'; 28 | import 'package:flutter_clean_architecture/presentation/common/infra/router.dart'; 29 | import 'package:flutter_clean_architecture/presentation/create_product/bloc/create_product_bloc.dart'; 30 | import 'package:flutter_clean_architecture/presentation/detail/bloc/detail_product_bloc.dart'; 31 | import 'package:flutter_clean_architecture/presentation/home/primary/bloc/primary_tab_bloc.dart'; 32 | import 'package:flutter_clean_architecture/presentation/login/bloc/login_bloc.dart'; 33 | import 'package:flutter_clean_architecture/presentation/register/bloc/register_bloc.dart'; 34 | import 'package:flutter_clean_architecture/presentation/splash/splash.page.dart'; 35 | import 'package:get_it/get_it.dart'; 36 | import 'package:shared_preferences/shared_preferences.dart'; 37 | 38 | final sl = GetIt.instance; 39 | 40 | Future init() async { 41 | sl.registerSingletonAsync(() => SharedPreferences.getInstance()); 42 | 43 | sl.registerSingletonWithDependencies( 44 | () => SharedPreferenceModule(pref: sl()), 45 | dependsOn: [SharedPreferences] 46 | ); 47 | 48 | //interceptor 49 | sl.registerSingletonWithDependencies( 50 | () => RequestInterceptor(pref: sl()), 51 | dependsOn: [SharedPreferenceModule] 52 | ); 53 | 54 | //module 55 | sl.registerLazySingleton(() => NetworkModule(requestInterceptor: sl()).provideDio()); 56 | 57 | //datasource 58 | sl.registerLazySingleton(() => LoginApiImpl(dio: sl())); 59 | sl.registerLazySingleton(() => RegisterApiImpl(dio: sl())); 60 | sl.registerLazySingleton(() => ProductApiImpl(dio: sl())); 61 | 62 | //repositories 63 | sl.registerLazySingleton(() => LoginRepositoryImpl(loginApi: sl())); 64 | sl.registerLazySingleton(() => RegisterRepositoryImpl(registerApi: sl())); 65 | sl.registerLazySingleton(() => ProductRepositoryImpl(productApi: sl())); 66 | sl.registerLazySingleton(() => ProductRepositoryImpl(productApi: sl())); 67 | sl.registerLazySingleton(() => ProductRepositoryImpl(productApi: sl())); 68 | sl.registerLazySingleton(() => ProductRepositoryImpl(productApi: sl())); 69 | 70 | //use cases 71 | sl.registerLazySingleton(() => LoginUseCase(loginRepository: sl())); 72 | sl.registerLazySingleton(() => RegisterUseCase(registerRepository: sl())); 73 | sl.registerLazySingleton(() => FindAllProductUseCase(getProductRepository: sl())); 74 | sl.registerLazySingleton(() => FindProductByIdUseCase(getProductRepository: sl())); 75 | sl.registerLazySingleton(() => CreateProductUseCase(createProductRepository: sl())); 76 | sl.registerLazySingleton(() => UpdateProductUseCase(updateProductRepository: sl())); 77 | sl.registerLazySingleton(() => DeleteProductUseCase(deleteProductRepository: sl())); 78 | 79 | //blocs 80 | sl.registerFactory(() => LoginBloc( 81 | loginUseCase: sl(), 82 | sharedPreferenceModule: sl() 83 | )); 84 | 85 | sl.registerFactory(() => RegisterBloc( 86 | registerUseCase: sl(), 87 | sharedPreferenceModule: sl() 88 | )); 89 | 90 | sl.registerFactory(() => PrimaryTabBloc(findAllProductUseCase: sl())); 91 | 92 | sl.registerFactory(() => DetailProductPageBloc( 93 | findProductByIdUseCase: sl(), 94 | updateProductUseCase: sl(), 95 | deleteProductUseCase: sl() 96 | )); 97 | 98 | sl.registerFactory(() => CreateProductPageBloc(createProductUseCase: sl())); 99 | 100 | 101 | } 102 | 103 | void main() async { 104 | WidgetsFlutterBinding.ensureInitialized(); 105 | await init(); 106 | 107 | runApp(MyApp()); 108 | } 109 | 110 | class MyApp extends StatelessWidget { 111 | 112 | @override 113 | Widget build(BuildContext context) { 114 | return FutureBuilder( 115 | future: sl.allReady(), 116 | builder: (context, snapshot){ 117 | if(snapshot.hasData){ 118 | return MaterialApp( 119 | onGenerateRoute: AppRouter.generateRoute, 120 | // initialRoute: AppRouter.ROUTE_SPLASH, 121 | title: "Flutter clean architecture", 122 | theme: ThemeData( 123 | primarySwatch: Colors.green, 124 | ), 125 | home: SplashPage(), 126 | ); 127 | }else{ 128 | return Center( 129 | child: CircularProgressIndicator(), 130 | ); 131 | } 132 | }, 133 | ); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | async: 5 | dependency: transitive 6 | description: 7 | name: async 8 | url: "https://pub.dartlang.org" 9 | source: hosted 10 | version: "2.6.1" 11 | bloc: 12 | dependency: transitive 13 | description: 14 | name: bloc 15 | url: "https://pub.dartlang.org" 16 | source: hosted 17 | version: "7.0.0" 18 | boolean_selector: 19 | dependency: transitive 20 | description: 21 | name: boolean_selector 22 | url: "https://pub.dartlang.org" 23 | source: hosted 24 | version: "2.1.0" 25 | characters: 26 | dependency: transitive 27 | description: 28 | name: characters 29 | url: "https://pub.dartlang.org" 30 | source: hosted 31 | version: "1.1.0" 32 | charcode: 33 | dependency: transitive 34 | description: 35 | name: charcode 36 | url: "https://pub.dartlang.org" 37 | source: hosted 38 | version: "1.2.0" 39 | clock: 40 | dependency: transitive 41 | description: 42 | name: clock 43 | url: "https://pub.dartlang.org" 44 | source: hosted 45 | version: "1.1.0" 46 | collection: 47 | dependency: transitive 48 | description: 49 | name: collection 50 | url: "https://pub.dartlang.org" 51 | source: hosted 52 | version: "1.15.0" 53 | cupertino_icons: 54 | dependency: "direct main" 55 | description: 56 | name: cupertino_icons 57 | url: "https://pub.dartlang.org" 58 | source: hosted 59 | version: "1.0.3" 60 | dartz: 61 | dependency: "direct main" 62 | description: 63 | name: dartz 64 | url: "https://pub.dartlang.org" 65 | source: hosted 66 | version: "0.10.0-nullsafety.2" 67 | dio: 68 | dependency: "direct main" 69 | description: 70 | name: dio 71 | url: "https://pub.dartlang.org" 72 | source: hosted 73 | version: "4.0.0" 74 | equatable: 75 | dependency: "direct main" 76 | description: 77 | name: equatable 78 | url: "https://pub.dartlang.org" 79 | source: hosted 80 | version: "2.0.2" 81 | fake_async: 82 | dependency: transitive 83 | description: 84 | name: fake_async 85 | url: "https://pub.dartlang.org" 86 | source: hosted 87 | version: "1.2.0" 88 | ffi: 89 | dependency: transitive 90 | description: 91 | name: ffi 92 | url: "https://pub.dartlang.org" 93 | source: hosted 94 | version: "1.1.1" 95 | file: 96 | dependency: transitive 97 | description: 98 | name: file 99 | url: "https://pub.dartlang.org" 100 | source: hosted 101 | version: "6.1.1" 102 | flutter: 103 | dependency: "direct main" 104 | description: flutter 105 | source: sdk 106 | version: "0.0.0" 107 | flutter_bloc: 108 | dependency: "direct main" 109 | description: 110 | name: flutter_bloc 111 | url: "https://pub.dartlang.org" 112 | source: hosted 113 | version: "7.0.1" 114 | flutter_test: 115 | dependency: "direct dev" 116 | description: flutter 117 | source: sdk 118 | version: "0.0.0" 119 | flutter_web_plugins: 120 | dependency: transitive 121 | description: flutter 122 | source: sdk 123 | version: "0.0.0" 124 | fluttertoast: 125 | dependency: "direct main" 126 | description: 127 | name: fluttertoast 128 | url: "https://pub.dartlang.org" 129 | source: hosted 130 | version: "8.0.7" 131 | get_it: 132 | dependency: "direct main" 133 | description: 134 | name: get_it 135 | url: "https://pub.dartlang.org" 136 | source: hosted 137 | version: "7.1.3" 138 | http_parser: 139 | dependency: transitive 140 | description: 141 | name: http_parser 142 | url: "https://pub.dartlang.org" 143 | source: hosted 144 | version: "4.0.0" 145 | js: 146 | dependency: transitive 147 | description: 148 | name: js 149 | url: "https://pub.dartlang.org" 150 | source: hosted 151 | version: "0.6.3" 152 | matcher: 153 | dependency: transitive 154 | description: 155 | name: matcher 156 | url: "https://pub.dartlang.org" 157 | source: hosted 158 | version: "0.12.10" 159 | meta: 160 | dependency: transitive 161 | description: 162 | name: meta 163 | url: "https://pub.dartlang.org" 164 | source: hosted 165 | version: "1.3.0" 166 | nested: 167 | dependency: transitive 168 | description: 169 | name: nested 170 | url: "https://pub.dartlang.org" 171 | source: hosted 172 | version: "1.0.0" 173 | path: 174 | dependency: transitive 175 | description: 176 | name: path 177 | url: "https://pub.dartlang.org" 178 | source: hosted 179 | version: "1.8.0" 180 | path_provider_linux: 181 | dependency: transitive 182 | description: 183 | name: path_provider_linux 184 | url: "https://pub.dartlang.org" 185 | source: hosted 186 | version: "2.0.0" 187 | path_provider_platform_interface: 188 | dependency: transitive 189 | description: 190 | name: path_provider_platform_interface 191 | url: "https://pub.dartlang.org" 192 | source: hosted 193 | version: "2.0.1" 194 | path_provider_windows: 195 | dependency: transitive 196 | description: 197 | name: path_provider_windows 198 | url: "https://pub.dartlang.org" 199 | source: hosted 200 | version: "2.0.1" 201 | platform: 202 | dependency: transitive 203 | description: 204 | name: platform 205 | url: "https://pub.dartlang.org" 206 | source: hosted 207 | version: "3.0.0" 208 | plugin_platform_interface: 209 | dependency: transitive 210 | description: 211 | name: plugin_platform_interface 212 | url: "https://pub.dartlang.org" 213 | source: hosted 214 | version: "2.0.0" 215 | process: 216 | dependency: transitive 217 | description: 218 | name: process 219 | url: "https://pub.dartlang.org" 220 | source: hosted 221 | version: "4.2.1" 222 | provider: 223 | dependency: transitive 224 | description: 225 | name: provider 226 | url: "https://pub.dartlang.org" 227 | source: hosted 228 | version: "5.0.0" 229 | shared_preferences: 230 | dependency: "direct main" 231 | description: 232 | name: shared_preferences 233 | url: "https://pub.dartlang.org" 234 | source: hosted 235 | version: "2.0.6" 236 | shared_preferences_linux: 237 | dependency: transitive 238 | description: 239 | name: shared_preferences_linux 240 | url: "https://pub.dartlang.org" 241 | source: hosted 242 | version: "2.0.0" 243 | shared_preferences_macos: 244 | dependency: transitive 245 | description: 246 | name: shared_preferences_macos 247 | url: "https://pub.dartlang.org" 248 | source: hosted 249 | version: "2.0.0" 250 | shared_preferences_platform_interface: 251 | dependency: transitive 252 | description: 253 | name: shared_preferences_platform_interface 254 | url: "https://pub.dartlang.org" 255 | source: hosted 256 | version: "2.0.0" 257 | shared_preferences_web: 258 | dependency: transitive 259 | description: 260 | name: shared_preferences_web 261 | url: "https://pub.dartlang.org" 262 | source: hosted 263 | version: "2.0.0" 264 | shared_preferences_windows: 265 | dependency: transitive 266 | description: 267 | name: shared_preferences_windows 268 | url: "https://pub.dartlang.org" 269 | source: hosted 270 | version: "2.0.0" 271 | sky_engine: 272 | dependency: transitive 273 | description: flutter 274 | source: sdk 275 | version: "0.0.99" 276 | source_span: 277 | dependency: transitive 278 | description: 279 | name: source_span 280 | url: "https://pub.dartlang.org" 281 | source: hosted 282 | version: "1.8.1" 283 | stack_trace: 284 | dependency: transitive 285 | description: 286 | name: stack_trace 287 | url: "https://pub.dartlang.org" 288 | source: hosted 289 | version: "1.10.0" 290 | stream_channel: 291 | dependency: transitive 292 | description: 293 | name: stream_channel 294 | url: "https://pub.dartlang.org" 295 | source: hosted 296 | version: "2.1.0" 297 | string_scanner: 298 | dependency: transitive 299 | description: 300 | name: string_scanner 301 | url: "https://pub.dartlang.org" 302 | source: hosted 303 | version: "1.1.0" 304 | term_glyph: 305 | dependency: transitive 306 | description: 307 | name: term_glyph 308 | url: "https://pub.dartlang.org" 309 | source: hosted 310 | version: "1.2.0" 311 | test_api: 312 | dependency: transitive 313 | description: 314 | name: test_api 315 | url: "https://pub.dartlang.org" 316 | source: hosted 317 | version: "0.3.0" 318 | typed_data: 319 | dependency: transitive 320 | description: 321 | name: typed_data 322 | url: "https://pub.dartlang.org" 323 | source: hosted 324 | version: "1.3.0" 325 | vector_math: 326 | dependency: transitive 327 | description: 328 | name: vector_math 329 | url: "https://pub.dartlang.org" 330 | source: hosted 331 | version: "2.1.0" 332 | win32: 333 | dependency: transitive 334 | description: 335 | name: win32 336 | url: "https://pub.dartlang.org" 337 | source: hosted 338 | version: "2.1.3" 339 | xdg_directories: 340 | dependency: transitive 341 | description: 342 | name: xdg_directories 343 | url: "https://pub.dartlang.org" 344 | source: hosted 345 | version: "0.2.0" 346 | sdks: 347 | dart: ">=2.13.0 <3.0.0" 348 | flutter: ">=1.20.0" 349 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 11 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 12 | 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 13 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 14 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 15 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXCopyFilesBuildPhase section */ 19 | 9705A1C41CF9048500538489 /* Embed Frameworks */ = { 20 | isa = PBXCopyFilesBuildPhase; 21 | buildActionMask = 2147483647; 22 | dstPath = ""; 23 | dstSubfolderSpec = 10; 24 | files = ( 25 | ); 26 | name = "Embed Frameworks"; 27 | runOnlyForDeploymentPostprocessing = 0; 28 | }; 29 | /* End PBXCopyFilesBuildPhase section */ 30 | 31 | /* Begin PBXFileReference section */ 32 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 33 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 34 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 35 | 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 36 | 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 37 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 38 | 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 39 | 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 40 | 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 41 | 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 42 | 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 43 | 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 44 | 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 45 | /* End PBXFileReference section */ 46 | 47 | /* Begin PBXFrameworksBuildPhase section */ 48 | 97C146EB1CF9000F007C117D /* Frameworks */ = { 49 | isa = PBXFrameworksBuildPhase; 50 | buildActionMask = 2147483647; 51 | files = ( 52 | ); 53 | runOnlyForDeploymentPostprocessing = 0; 54 | }; 55 | /* End PBXFrameworksBuildPhase section */ 56 | 57 | /* Begin PBXGroup section */ 58 | 9740EEB11CF90186004384FC /* Flutter */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 62 | 9740EEB21CF90195004384FC /* Debug.xcconfig */, 63 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, 64 | 9740EEB31CF90195004384FC /* Generated.xcconfig */, 65 | ); 66 | name = Flutter; 67 | sourceTree = ""; 68 | }; 69 | 97C146E51CF9000F007C117D = { 70 | isa = PBXGroup; 71 | children = ( 72 | 9740EEB11CF90186004384FC /* Flutter */, 73 | 97C146F01CF9000F007C117D /* Runner */, 74 | 97C146EF1CF9000F007C117D /* Products */, 75 | ); 76 | sourceTree = ""; 77 | }; 78 | 97C146EF1CF9000F007C117D /* Products */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | 97C146EE1CF9000F007C117D /* Runner.app */, 82 | ); 83 | name = Products; 84 | sourceTree = ""; 85 | }; 86 | 97C146F01CF9000F007C117D /* Runner */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | 97C146FA1CF9000F007C117D /* Main.storyboard */, 90 | 97C146FD1CF9000F007C117D /* Assets.xcassets */, 91 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, 92 | 97C147021CF9000F007C117D /* Info.plist */, 93 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, 94 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, 95 | 74858FAE1ED2DC5600515810 /* AppDelegate.swift */, 96 | 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */, 97 | ); 98 | path = Runner; 99 | sourceTree = ""; 100 | }; 101 | /* End PBXGroup section */ 102 | 103 | /* Begin PBXNativeTarget section */ 104 | 97C146ED1CF9000F007C117D /* Runner */ = { 105 | isa = PBXNativeTarget; 106 | buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; 107 | buildPhases = ( 108 | 9740EEB61CF901F6004384FC /* Run Script */, 109 | 97C146EA1CF9000F007C117D /* Sources */, 110 | 97C146EB1CF9000F007C117D /* Frameworks */, 111 | 97C146EC1CF9000F007C117D /* Resources */, 112 | 9705A1C41CF9048500538489 /* Embed Frameworks */, 113 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */, 114 | ); 115 | buildRules = ( 116 | ); 117 | dependencies = ( 118 | ); 119 | name = Runner; 120 | productName = Runner; 121 | productReference = 97C146EE1CF9000F007C117D /* Runner.app */; 122 | productType = "com.apple.product-type.application"; 123 | }; 124 | /* End PBXNativeTarget section */ 125 | 126 | /* Begin PBXProject section */ 127 | 97C146E61CF9000F007C117D /* Project object */ = { 128 | isa = PBXProject; 129 | attributes = { 130 | LastUpgradeCheck = 1020; 131 | ORGANIZATIONNAME = ""; 132 | TargetAttributes = { 133 | 97C146ED1CF9000F007C117D = { 134 | CreatedOnToolsVersion = 7.3.1; 135 | LastSwiftMigration = 1100; 136 | }; 137 | }; 138 | }; 139 | buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; 140 | compatibilityVersion = "Xcode 9.3"; 141 | developmentRegion = en; 142 | hasScannedForEncodings = 0; 143 | knownRegions = ( 144 | en, 145 | Base, 146 | ); 147 | mainGroup = 97C146E51CF9000F007C117D; 148 | productRefGroup = 97C146EF1CF9000F007C117D /* Products */; 149 | projectDirPath = ""; 150 | projectRoot = ""; 151 | targets = ( 152 | 97C146ED1CF9000F007C117D /* Runner */, 153 | ); 154 | }; 155 | /* End PBXProject section */ 156 | 157 | /* Begin PBXResourcesBuildPhase section */ 158 | 97C146EC1CF9000F007C117D /* Resources */ = { 159 | isa = PBXResourcesBuildPhase; 160 | buildActionMask = 2147483647; 161 | files = ( 162 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, 163 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 164 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, 165 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, 166 | ); 167 | runOnlyForDeploymentPostprocessing = 0; 168 | }; 169 | /* End PBXResourcesBuildPhase section */ 170 | 171 | /* Begin PBXShellScriptBuildPhase section */ 172 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { 173 | isa = PBXShellScriptBuildPhase; 174 | buildActionMask = 2147483647; 175 | files = ( 176 | ); 177 | inputPaths = ( 178 | ); 179 | name = "Thin Binary"; 180 | outputPaths = ( 181 | ); 182 | runOnlyForDeploymentPostprocessing = 0; 183 | shellPath = /bin/sh; 184 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; 185 | }; 186 | 9740EEB61CF901F6004384FC /* Run Script */ = { 187 | isa = PBXShellScriptBuildPhase; 188 | buildActionMask = 2147483647; 189 | files = ( 190 | ); 191 | inputPaths = ( 192 | ); 193 | name = "Run Script"; 194 | outputPaths = ( 195 | ); 196 | runOnlyForDeploymentPostprocessing = 0; 197 | shellPath = /bin/sh; 198 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; 199 | }; 200 | /* End PBXShellScriptBuildPhase section */ 201 | 202 | /* Begin PBXSourcesBuildPhase section */ 203 | 97C146EA1CF9000F007C117D /* Sources */ = { 204 | isa = PBXSourcesBuildPhase; 205 | buildActionMask = 2147483647; 206 | files = ( 207 | 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */, 208 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, 209 | ); 210 | runOnlyForDeploymentPostprocessing = 0; 211 | }; 212 | /* End PBXSourcesBuildPhase section */ 213 | 214 | /* Begin PBXVariantGroup section */ 215 | 97C146FA1CF9000F007C117D /* Main.storyboard */ = { 216 | isa = PBXVariantGroup; 217 | children = ( 218 | 97C146FB1CF9000F007C117D /* Base */, 219 | ); 220 | name = Main.storyboard; 221 | sourceTree = ""; 222 | }; 223 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { 224 | isa = PBXVariantGroup; 225 | children = ( 226 | 97C147001CF9000F007C117D /* Base */, 227 | ); 228 | name = LaunchScreen.storyboard; 229 | sourceTree = ""; 230 | }; 231 | /* End PBXVariantGroup section */ 232 | 233 | /* Begin XCBuildConfiguration section */ 234 | 249021D3217E4FDB00AE95B9 /* Profile */ = { 235 | isa = XCBuildConfiguration; 236 | buildSettings = { 237 | ALWAYS_SEARCH_USER_PATHS = NO; 238 | CLANG_ANALYZER_NONNULL = YES; 239 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 240 | CLANG_CXX_LIBRARY = "libc++"; 241 | CLANG_ENABLE_MODULES = YES; 242 | CLANG_ENABLE_OBJC_ARC = YES; 243 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 244 | CLANG_WARN_BOOL_CONVERSION = YES; 245 | CLANG_WARN_COMMA = YES; 246 | CLANG_WARN_CONSTANT_CONVERSION = YES; 247 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 248 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 249 | CLANG_WARN_EMPTY_BODY = YES; 250 | CLANG_WARN_ENUM_CONVERSION = YES; 251 | CLANG_WARN_INFINITE_RECURSION = YES; 252 | CLANG_WARN_INT_CONVERSION = YES; 253 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 254 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 255 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 256 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 257 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 258 | CLANG_WARN_STRICT_PROTOTYPES = YES; 259 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 260 | CLANG_WARN_UNREACHABLE_CODE = YES; 261 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 262 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 263 | COPY_PHASE_STRIP = NO; 264 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 265 | ENABLE_NS_ASSERTIONS = NO; 266 | ENABLE_STRICT_OBJC_MSGSEND = YES; 267 | GCC_C_LANGUAGE_STANDARD = gnu99; 268 | GCC_NO_COMMON_BLOCKS = YES; 269 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 270 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 271 | GCC_WARN_UNDECLARED_SELECTOR = YES; 272 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 273 | GCC_WARN_UNUSED_FUNCTION = YES; 274 | GCC_WARN_UNUSED_VARIABLE = YES; 275 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 276 | MTL_ENABLE_DEBUG_INFO = NO; 277 | SDKROOT = iphoneos; 278 | SUPPORTED_PLATFORMS = iphoneos; 279 | TARGETED_DEVICE_FAMILY = "1,2"; 280 | VALIDATE_PRODUCT = YES; 281 | }; 282 | name = Profile; 283 | }; 284 | 249021D4217E4FDB00AE95B9 /* Profile */ = { 285 | isa = XCBuildConfiguration; 286 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 287 | buildSettings = { 288 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 289 | CLANG_ENABLE_MODULES = YES; 290 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 291 | ENABLE_BITCODE = NO; 292 | INFOPLIST_FILE = Runner/Info.plist; 293 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 294 | PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterCleanArchitecture; 295 | PRODUCT_NAME = "$(TARGET_NAME)"; 296 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 297 | SWIFT_VERSION = 5.0; 298 | VERSIONING_SYSTEM = "apple-generic"; 299 | }; 300 | name = Profile; 301 | }; 302 | 97C147031CF9000F007C117D /* Debug */ = { 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; 333 | ENABLE_STRICT_OBJC_MSGSEND = YES; 334 | ENABLE_TESTABILITY = YES; 335 | GCC_C_LANGUAGE_STANDARD = gnu99; 336 | GCC_DYNAMIC_NO_PIC = NO; 337 | GCC_NO_COMMON_BLOCKS = YES; 338 | GCC_OPTIMIZATION_LEVEL = 0; 339 | GCC_PREPROCESSOR_DEFINITIONS = ( 340 | "DEBUG=1", 341 | "$(inherited)", 342 | ); 343 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 344 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 345 | GCC_WARN_UNDECLARED_SELECTOR = YES; 346 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 347 | GCC_WARN_UNUSED_FUNCTION = YES; 348 | GCC_WARN_UNUSED_VARIABLE = YES; 349 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 350 | MTL_ENABLE_DEBUG_INFO = YES; 351 | ONLY_ACTIVE_ARCH = YES; 352 | SDKROOT = iphoneos; 353 | TARGETED_DEVICE_FAMILY = "1,2"; 354 | }; 355 | name = Debug; 356 | }; 357 | 97C147041CF9000F007C117D /* Release */ = { 358 | isa = XCBuildConfiguration; 359 | buildSettings = { 360 | ALWAYS_SEARCH_USER_PATHS = NO; 361 | CLANG_ANALYZER_NONNULL = YES; 362 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 363 | CLANG_CXX_LIBRARY = "libc++"; 364 | CLANG_ENABLE_MODULES = YES; 365 | CLANG_ENABLE_OBJC_ARC = YES; 366 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 367 | CLANG_WARN_BOOL_CONVERSION = YES; 368 | CLANG_WARN_COMMA = YES; 369 | CLANG_WARN_CONSTANT_CONVERSION = YES; 370 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 371 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 372 | CLANG_WARN_EMPTY_BODY = YES; 373 | CLANG_WARN_ENUM_CONVERSION = YES; 374 | CLANG_WARN_INFINITE_RECURSION = YES; 375 | CLANG_WARN_INT_CONVERSION = YES; 376 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 377 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 378 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 379 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 380 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 381 | CLANG_WARN_STRICT_PROTOTYPES = YES; 382 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 383 | CLANG_WARN_UNREACHABLE_CODE = YES; 384 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 385 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 386 | COPY_PHASE_STRIP = NO; 387 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 388 | ENABLE_NS_ASSERTIONS = NO; 389 | ENABLE_STRICT_OBJC_MSGSEND = YES; 390 | GCC_C_LANGUAGE_STANDARD = gnu99; 391 | GCC_NO_COMMON_BLOCKS = YES; 392 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 393 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 394 | GCC_WARN_UNDECLARED_SELECTOR = YES; 395 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 396 | GCC_WARN_UNUSED_FUNCTION = YES; 397 | GCC_WARN_UNUSED_VARIABLE = YES; 398 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 399 | MTL_ENABLE_DEBUG_INFO = NO; 400 | SDKROOT = iphoneos; 401 | SUPPORTED_PLATFORMS = iphoneos; 402 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 403 | TARGETED_DEVICE_FAMILY = "1,2"; 404 | VALIDATE_PRODUCT = YES; 405 | }; 406 | name = Release; 407 | }; 408 | 97C147061CF9000F007C117D /* Debug */ = { 409 | isa = XCBuildConfiguration; 410 | baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; 411 | buildSettings = { 412 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 413 | CLANG_ENABLE_MODULES = YES; 414 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 415 | ENABLE_BITCODE = NO; 416 | INFOPLIST_FILE = Runner/Info.plist; 417 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 418 | PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterCleanArchitecture; 419 | PRODUCT_NAME = "$(TARGET_NAME)"; 420 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 421 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 422 | SWIFT_VERSION = 5.0; 423 | VERSIONING_SYSTEM = "apple-generic"; 424 | }; 425 | name = Debug; 426 | }; 427 | 97C147071CF9000F007C117D /* Release */ = { 428 | isa = XCBuildConfiguration; 429 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 430 | buildSettings = { 431 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 432 | CLANG_ENABLE_MODULES = YES; 433 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 434 | ENABLE_BITCODE = NO; 435 | INFOPLIST_FILE = Runner/Info.plist; 436 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 437 | PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterCleanArchitecture; 438 | PRODUCT_NAME = "$(TARGET_NAME)"; 439 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 440 | SWIFT_VERSION = 5.0; 441 | VERSIONING_SYSTEM = "apple-generic"; 442 | }; 443 | name = Release; 444 | }; 445 | /* End XCBuildConfiguration section */ 446 | 447 | /* Begin XCConfigurationList section */ 448 | 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { 449 | isa = XCConfigurationList; 450 | buildConfigurations = ( 451 | 97C147031CF9000F007C117D /* Debug */, 452 | 97C147041CF9000F007C117D /* Release */, 453 | 249021D3217E4FDB00AE95B9 /* Profile */, 454 | ); 455 | defaultConfigurationIsVisible = 0; 456 | defaultConfigurationName = Release; 457 | }; 458 | 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { 459 | isa = XCConfigurationList; 460 | buildConfigurations = ( 461 | 97C147061CF9000F007C117D /* Debug */, 462 | 97C147071CF9000F007C117D /* Release */, 463 | 249021D4217E4FDB00AE95B9 /* Profile */, 464 | ); 465 | defaultConfigurationIsVisible = 0; 466 | defaultConfigurationName = Release; 467 | }; 468 | /* End XCConfigurationList section */ 469 | }; 470 | rootObject = 97C146E61CF9000F007C117D /* Project object */; 471 | } 472 | --------------------------------------------------------------------------------