a sample flutter app using Injection, routing and simple authentication follows clean code and best practices

Overview

Flutter Clean Project

A sample flutter app using Injection, routing and simple authentication follows clean code and best practices

Features

  • Cleaned flutter project
  • Used linter with rules as errors
  • Configured route generator
  • Pass parameters / variables through routes
  • Simple AuthService & configured Guard for routes
  • Well structured flutter project contains Screens, Components, Services and so on..

Used Packages

Getting Started

Project root folder

The project root folder is src. In order to take advantage of VS Code settings open src as your work folder.

Building

Auto generated files are committed into this repository. if you changed any part of codes which used auto generators you will have a compilation error. This can be resolved by running the auto generation command to create the sources necessary again to compile the app.

After checking out the branch simply run:

flutter pub run build_runner build --delete-conflicting-outputs

You can also use the watch command to constantly generate files on change:

flutter pub run build_runner watch --delete-conflicting-outputs

Dependency Injection

Dependency injection is done by using Injectable package.

After you run the build_runner command a file named setup.config.dart will get generated which holds all the injections.

Routing

Routing is done by using AutoRoute package.

There is a service called router in /Services which using AutoRoute package to generate routes and paths in app.

After you run the build_runner command a file named router.gr.dart will get generated which holds all the routes and classes used for routing.

also for showcasing how to pass parameters from paths to screens, see /home/message/message_screen_v.dart

State Management

Selected state management for this project is Cubit.

The Cubit is a subset of the famous implementation of BLoC Pattern: bloclibrary.dev, it abandons the concept of Events and simplifies the way of emitting states.

There are 3 parts for each component / screen to managing the states.

  • name_m.dart

    • Model: this file contains definition of models for state management. to reduce duplicate codes like copyWith, isA[Class] and so on, I used Freezed package to auto generate needed classes and constructors for each state model.
  • name_v.dart

    • View: this file contains the view for our component / screen which extends from BaseView class. the BaseView class itself extends from StatelessWidget and has a getter to get the viewModel inside the view. it's using locateService<T>() and Injectable DI.
  • name_vm.dart

    • ViewModel: this file contains the viewModel for our component / screen which extends from BaseViewModel class (T is the state Model class). the BaseViewModel<T> class itself extends from cubit<T>.

Screens

I defined 3 screens in this project.

  • Home
    • the root path of application.
      • have a link to message screen with passing a parameter to it.
      • using AuthService to logout user.
      • showing counter component in it.
  • message
    • a screen to demo how to get a parameter in our routing system.
      • the input parameter is defined in view's constructor [String message].
      • also in the routing service, I have to define the input parameter for this screen.
  • login
    • login screen with a simple button and use AuthService to do the fake login in application.
      • there is optional parameter called redirectPath which used by router to navigate user back to where he/she been after successful login.
      • to guard selected routes and navigate user to this screen, I defined class AuthenticatedUser in the routing service class.

there is a file in each folder with folder_name.dart pattern name, which includes exports of files inside that folder. I use this pattern to minimize imports for other parts of application and classes. in usage we only need to import components.dart or screens.dart to use each folders implementations.

Components

Right now there is only one component in this project to demonstrate how to use components in screens.

  • counter
    • a simple counter component with cubit state management.
    • I used this component inside the Home screen.

Images

login

home

message

Contact me

if you have any question or suggestion, please contact me :

You might also like...

Flutter classified app - A sample app to showcase classified app using flutter

Flutter classified app - A sample app to showcase classified app using flutter

Flutter Classified App Demo A sample app to showcase classified app using flutter. Demo Android Screen iOS Screen Getting Started This project is a st

Dec 27, 2022

Sample app to demonstrate the integration and working of Dyte SDK for mobile, using Flutter.

Sample app to demonstrate the integration and working of Dyte SDK for mobile, using Flutter.

Flutter Sample App by dyte Sample App to demonstrate Dyte SDK in flutter Explore the docs » View Demo · Report Bug · Request Feature Table of Contents

Jan 1, 2023

Flutter sample app using MLKit Vision API for text recognition

Flutter sample app using MLKit Vision API for text recognition

Flutter ML Kit Vision This a sample Flutter app integrated with the ML Kit Vision API for recognition of email addresses from an image. NOTE: The ML K

Oct 12, 2022

A sample app to showcase signin-signup UI demo using clippers in flutter

A sample app to showcase signin-signup UI demo using clippers in flutter

flutter_signin_signup A sample app to showcase signin-signup UI demo using clippers in flutter. Screenshots Login Register Pull Requests I welcome and

Nov 3, 2022

Flutter App to save notes secure, using cryptography, clean architecture and some design patterns.

notes A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this is

Mar 28, 2022

Resturant FlutterApp withApi - A flutter app of a such restaurant with API and Firebase Authentication

Resturant FlutterApp withApi - A flutter app of a such restaurant with API and Firebase Authentication

Resturant_FlutterApp_withApi This is flutter app of a such restaurant with API a

Oct 5, 2022

Pokedex app built with Flutter (with lots of animations) using Clean Architecture

Pokedex app built with Flutter (with lots of animations) using Clean Architecture

Flutter Pokedex Pokedex app built with Flutter App preview Video demo Installation Add Flutter to your machine Open this project folder with Terminal/

Jan 8, 2023

A nice clean recipe app UI using flutter.

A nice clean recipe app UI using flutter.

Recipe App - Flutter UI Watch it on YouTube Also work on both landscape and portrait mood Packages we are using: flutter_svg: link provider: link Try

Dec 17, 2022

Pokedex app built with Flutter (with lots of animations) using Clean Architecture

Pokedex app built with Flutter (with lots of animations) using Clean Architecture

Flutter Pokedex Pokedex app built with Flutter App preview Video demo Installation Add Flutter to your machine Open this project folder with Terminal/

Dec 28, 2022
Owner
Moez Shakeri
Moez Shakeri
DoneIt is a sample note app 📝 Flutter application 📱 built to demonstrate use of Clean Architecture tools. Dedicated to all Flutter Developers with ❤️.

DoneIt ?? DoneIt is a sample note app ?? Flutter application ?? built to demonstrate use of Clean Architecture tools. Dedicated to all Flutter Develop

Shubham Chhimpa 175 Dec 24, 2022
A sample app that implement Uncle Bob's Clean Architecture in Flutter

Clean Architecture for Flutter This a sample app that implement Uncle Bob's Clea

Mahmoud Saeed 28 Nov 8, 2022
Dependency Injection oversimplified. Inspired by Koin, with focus on scopes.

Dependency Injection oversimplified. Inspired by Koin, with focus on scopes. Features Define your dependencies in a syntax as close to DSL as possible

Tamás Barta 1 Dec 5, 2022
Flutter ToDo application using Clean Code architecture

DoneIt ?? DoneIt is a sample note app ?? Flutter application ?? built to demonstrate use of Clean Architecture tools. Dedicated to all Flutter Develop

Harshal 7 Dec 27, 2022
Wake Up & Code Sample Flutter Project

todo_app A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this

null 0 Dec 29, 2021
News Adda is a news app that selects the latest and best news from multiple national and international sources

News Adda A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if thi

 Geeky.dev 7 Apr 22, 2022
Best ever drawer in flutter for android and ios

Drawer in Flutter Best ever drawer in flutter to make precious application. This flutter app is made just to demonstrate how you we can make an animat

Asad Malik 22 Oct 16, 2022
Algorithm for choosing the best seats in a cinema. Made in dart.

Buy movie tickets algorithm This dart project contains an algorithm to choose the better seats on the cinema. Also contains a bot to buy movie tickets

Chris Chávez 1 Dec 2, 2021
Summary of "Clean Code"

clean_code A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to get you started i

Jonathan 0 Dec 29, 2021
A simple flutter application that demonstrates authentication with pin or OTP sent via sms and also Fingerprint.

flutter_authentication A simple flutter application that demonstrates authentication with pin or OTP sent via sms and also Fingerprint. Getting Starte

OLUWATOMISIN ESAN 4 Apr 10, 2022