Skip to content

Advanced and highly scalable boilerplate for building Flutter apps with MobX, Dio, GetIt, and AutoRoutes. Null safe and compatible with Flutter 2.0.

License

Notifications You must be signed in to change notification settings

ganeshrvel/flutter_mobx_dio_boilerplate

Repository files navigation

Flutter Mobx Dio Boilerplate [null safe]

Advanced and highly scalable boilerplate for building Flutter App - Mobx, Dio, GetIt and AutoRoutes.

Flutter is an excellent framework for building cross-platform native applications. But there are only a handful of frameworks available online to get going and I found most of them lack advanced features.

Features

Find the tutorial links

Installation

$ git clone https://github.com/ganeshrvel/flutter_mobx_dio_boilerplate.git

$ cd flutter_mobx_dio_boilerplate
$ flutter create .
$ flutter pub get
$ flutter pub upgrade

This boilerplate uses code generation tools to automatically generate code during the hot reload workflow, and while building an Application.

# clean conflicting codes
./scripts/build-runner-clean.sh
# keep your code automatically synced
./scripts/build-runner-watch.sh

Configuration

Activate pre-commit hooks

$ git config core.hooksPath .githooks/

To activate network connection in macOS, add the following lines to your macos/Runner/DebugProfile.entitlements and macos/Runner/Release.entitlements

    <key>com.apple.security.network.server</key>
    <true/>
    <key>com.apple.security.network.client</key>
    <true/>

To activate video player in, macOS: add the following lines to your macos/Runner/Info.plist

    <key>NSAppTransportSecurity</key>
    <dict>
      <key>NSAllowsArbitraryLoads</key>
      <true/>
    </dict>

iOS: add the following lines to your ios/Runner/Info.plist

    <key>NSAppTransportSecurity</key>
    <dict>
      <key>NSAllowsArbitraryLoads</key>
      <true/>
    </dict>

Android: Ensure the following permission is present in your Android Manifest file, located in android/app/src/main/AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET"/>

and add the attribute android:usesCleartextTraffic="true" to <application

# example
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="abc.xyz.pqr">
	<uses-permission android:name="android.permission.INTERNET"/>
	
	<application
        android:usesCleartextTraffic="true"
		....
		...
		/>

APIS

Clone the repo https://github.com/ganeshrvel/auth-apis and follow the instructions in the README.md for the running the API server.

Directory structure

.
├── common
│   ├── api_client
│   │   ├── api_client.dart
│   │   ├── api_errors
│   │   └── interceptors
│   ├── di
│   ├── enums
│   ├── exceptions
│   ├── helpers
│   ├── l10n
│   ├── mixins
│   ├── models
│   ├── network
│   ├── router
│   └── themes
├── constants
├── features
│   ├── app
│   │   ├── data
│   │   │   ├── controllers
│   │   │   ├── data_sources
│   │   │   └── repositories
│   │   └── ui
│   │       ├── l10n
│   │       ├── pages
│   │       └── store
│   ├── home
│   │   └── ui
│   ├── login
│   │   ├── data
│   │   │   ├── controllers
│   │   │   │   └── login_controller.dart
│   │   │   ├── data_sources
│   │   │   │   ├── login_local_data_source.dart
│   │   │   │   └── login_remote_data_source.dart
│   │   │   ├── mappers
│   │   │   ├── models
│   │   │   │   ├── authentication_model.dart
│   │   │   │   ├── post_login_request_model.dart
│   │   │   │   ├── post_login_response_model.dart
│   │   │   │   ├── user_model.dart
│   │   │   └── repositories
│   │   │       └── login_repository.dart
│   │   └── ui
│   │       ├── l10n
│   │       │   ├── en.dart
│   │       │   └── hi.dart
│   │       ├── pages
│   │       │   └── login.dart
│   │       └── store
│   │           ├── login_store.dart
│   ├── page_not_found
│   │   └── ui
│   ├── profile
│   │   └── ui
│   └── splash
│       └── ui
├── main.dart
├── services
├── utils
│   ├── alerts
│   └── log
├── widget_extends
└── widgets

Detailed view

.
├── common # all common files are kept here.
│   ├── api_client
│   │   ├── api_client.dart # api client (dio) logics
│   │   ├── api_errors # api client error
│   │   └── interceptors # dio logics
│   ├── di # dependency injection (DI); 3rd party classes are included here for DI
│   ├── enums # common enums
│   ├── exceptions # common exceptions
│   ├── helpers # common helpers
│   ├── l10n # common l10n (localization) files. add a new locale file for a new language addition
│   ├── mixins # common mixins
│   ├── models # common models
│   ├── network # network helpers
│   ├── router # routing logic
│   └── themes # theme data files
├── constants # constants such as strings, errors message names, dimensions etc.
├── features # contains the logic for all features
│   ├── app
│   │   ├── data # contains the models, controllers, data_sources, repositories
│   │   │   ├── controllers
│   │   │   ├── data_sources
│   │   │   └── repositories
│   │   │   ├── models
│   │   └── ui # any ui related stuffs are added here
│   │       ├── l10n # localization files and data are added here for the particular page. Make sure that every new locale file is added in lib/common/l10n/en.dart
│   │       ├── pages # every screen related stuffs
│   │       └── store # mobx store for state management
│   ├── home
│   │   └── ui
│   ├── login
│   │   ├── data
│   │   │   ├── controllers
│   │   │   │   └── login_controller.dart
│   │   │   ├── data_sources
│   │   │   │   ├── login_local_data_source.dart
│   │   │   │   └── login_remote_data_source.dart
│   │   │   ├── mappers
│   │   │   ├── models
│   │   │   │   ├── authentication_model.dart
│   │   │   │   ├── post_login_request_model.dart
│   │   │   │   ├── post_login_response_model.dart
│   │   │   │   ├── user_model.dart
│   │   │   └── repositories
│   │   │       └── login_repository.dart
│   │   └── ui
│   │       ├── l10n
│   │       │   ├── en.dart
│   │       │   └── hi.dart
│   │       ├── pages
│   │       │   └── login.dart
│   │       └── store
│   │           ├── login_store.dart
│   ├── page_not_found
│   │   └── ui
│   ├── profile
│   │   └── ui
│   └── splash
│       └── ui
├── main.dart # main file
├── services # common services
├── utils # utils
│   ├── alerts
│   └── log
├── widget_extends # widget extend files
└── widgets # common widgets

Architecture

The boilerplate follows a fusion of Clean architecture and MVVM pattern. It is highly customizable and feature-rich.

architecture diagram

DC (Data Channel)

It is not a very ideal solution to handle exceptions using try and catch at every function call, use data_channel instead. data_channel will take care of routing errors and data out of a method.

data_channel (DC) is a simple dart utility for handling exceptions and data routing.

Refer to https://pub.dev/packages/data_channel for more details.

Rules

Rules - Powerful and feature-rich validation library for both Dart and Flutter.

Refer to https://pub.dev/packages/rules for more details.

Non-Null safe version

Find the non-null safe version from here: https://github.com/ganeshrvel/flutter_mobx_dio_boilerplate/tree/9623e9a367cae5380e3a84840b46263262f166af

IDE

Hide Generated Files

In-order to hide generated files, navigate to Android Studio -> Preferences -> Editor -> File Types and paste the below lines under Ignore files and Folders section:

*.inject.summary;*.inject.dart;*.g.dart;

In Visual Studio Code, navigate to Preferences -> Settings and search for Files:Exclude. Add the following patterns:

**/*.inject.summary
**/*.inject.dart
**/*.g.dart

Contribute

  • Fork the repo and create your branch from master.
  • Ensure that the changes pass linting.
  • Update the documentation if needed.
  • Make sure your code lints.
  • Issue a pull request!

When you submit code changes, your submissions are understood to be under the same MIT License that covers the project. Feel free to contact the maintainers if that's a concern.

Tutorials

Buy me a coffee

Help me keep the app FREE and open for all. Paypal me: paypal.me/ganeshrvel

Contacts

Please feel free to contact me at [email protected]

License

flutter_mobx_dio_boilerplate | Flutter Mobx Dio Boilerplate is released under MIT License.

Copyright © 2018-Present Ganesh Rathinavel

About

Advanced and highly scalable boilerplate for building Flutter apps with MobX, Dio, GetIt, and AutoRoutes. Null safe and compatible with Flutter 2.0.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published