webfactorymk / flutter-template

Flutter template project - Simple ToDo app with scalable project structure.
https://webfactory.mk/
MIT License
166 stars 36 forks source link
dart flutter template

Flutter Template

Flutter template project - A simple TODO list app. This template provides simple UI and scalable project structure that goes beyond the simple counter example.

The app has basic login and signup screens, task list, task details, and settings screen. It supports multiple languages and in-app language change, and light and dark theme.

It's configured with BLoC for state management, Chopper for networking, Navigation 2.0, GetIt as service locator, UserManager, Repository Pattern, Logger, and util and convenience methods.


    Light theme      Dark theme


First Run

The project is configured with mock data if you run the MOCK flavor. See the next section for configuring run configurations.

After installing the package dependencies with

flutter pub get

run the code generation tool

flutter pub run build_runner build

Run Configurations

In addition to the Flutter's build modes (debug, profile, release), the project has 4 flavours/schemas for defining environments:

To run the app use the following command:

flutter run --flavor dev -t lib/main_dev.dart

or edit run configurations in Android Studio:

See flavor_config.dart for environment specific config.

For adding an additional Flutter flavours see the official documentation and this blog post.

Use as template

You can copy this repository with the Use this template button and go on from there, or download the code and use it in you project. Afterwards, you'll need to rename the project and change the app id and configuration. There are ToDos scattered through the project that will help you transition this project to your needs.

Use as template

Head to the Wiki page for project documentation.

Resolve TODOs

Go over the TODOs scattered around the project and resolve as much as possible. They will help you configure the project to your needs.

In AndroidStudio you can view all TODOs in the bottom tab as shown in this picture:

TODOs bottom tab in AS

App Configuration

To configure the app for your environment head to the /config directory:

See the wiki configuration page for more info.

Under the hood

Data Management

Alt text

TasksDataSource

This is the main entry point for accessing and manipulating tasks data. The rest of the app should not invoke tasks' endpoints directly or query cached data. All tasks operations should go through this service.

Implementations:

ApiService

Abstraction over the API communication that defines (all) endpoints. This templates uses Chopper, an http client generator, to make network requests.

JSON and Serialization

JSON models are serialized using a code generation library.

For one time code generation run this command in terminal: flutter pub run build_runner build

For subsequent code generations with conflicting outputs: flutter pub run build_runner build --delete-conflicting-outputs

For more information and generating code continuously see the documentation.

Declarative UI and state management

Flutter is declarative framework. This means that Flutter builds its user interface to reflect the current state of the app.

High level diagram

This template attempts to be unopinionated and does not yet use a state management tool. ...we use BLoC now. But, each app service has an updates Stream that clients can subscribe to and receive state updates. See the UpdatesStream mixin. It's up to you to use a tool of your choice, or don't use one at all. See TasksRepository#taskEventUpdatesStream and TasksRepository#taskGroupUpdatesStream in TasksRepository

Dependency Management

Dependencies are managed in the service_locator.dart file. This sample uses GetIt, a lightweight service locator. There are 2 scopes defined in this template global and user scope. For more information visit the wiki service locator page.

Logger

This project uses a custom Logger configured to:

  1. print to console, except in production
  2. write to a file, except in production - useful for QA reporting
  3. log to firebase or report a non-fatal error to firebase

Prefer to use this logger over print statements.

Tests

The test package contains unit tests for almost all components. Be sure to give it a look.