Skip to content

odc-student/flutter_bloc_starter

Repository files navigation

Flutter Starter Template with BLoC

This repository serves as a Flutter Starter Template utilizing the BLoC (Business Logic Component) pattern. It is designed to provide a clean and scalable project structure, enabling efficient development and maintainability.


🗂️ Project Structure

The project structure is organized into three main folders under the lib directory:

1. Core

Contains shared resources and configurations used throughout the app.

  • Network Client: Handles API requests and responses.
  • Local Storage: Manages data persistence using shared_preferences.
  • App Configuration: Includes environment global settings such as baseUrl.

2. Features

Each app feature is modularized into its own folder for better separation of concerns.

  • Login Feature (Example): A pre-built login feature is included in this repository to demonstrate the structure and implementation of features.

3. I10n

Holds all the localization files for the app.

  • Example: app_en.arb for English translations.
  • Easily extendable for multi-language support.

Generating Translations

To use the latest translations changes, you will need to generate them:

  1. Generate localizations for the current project:
flutter gen-l10n --arb-dir="lib/l10n/arb"

📖 How to Add a New Feature

  1. Create a new folder under the features directory.
  2. Add the following subfolders to the new feature:
  • data/: Handles API calls and local data sources
  • presentation/: Contains:
    • Widgets: Widgets for the user interface.
    • Pages: the user interface.
    • BLoC Folder: Manages the feature's state using BLoC.
  • repository/: Implements the repository pattern for business logic, acting as the intermediary between data and presentation.
  1. Register the new feature’s routes in the app's main navigation.

Example:

features
└── login
    ├── data
    │   ├── models
    │   │       └── request
    │   │       └── response
    │   └── data_sources
    ├── presentation
    │   ├── widgets
    │   ├── pages
    │   └── bloc
    └── repository

Working with Translations 🌐

This project relies on flutter_localizations and follows the official internationalization guide for Flutter.

Adding Strings

  1. To add a new localizable string, open the app_en.arb file at lib/l10n/arb/app_en.arb.
{
  "@@locale": "en",
  "loginAppBarTitle": "Login App Bar",
  "buttonTextLogin": "Login",
  "labelTextEmail": "Email address"
}
  1. Then add a new key/value and description
{
  "@@locale": "en",
  "loginAppBarTitle": "Login App Bar",
  "buttonTextLogin": "Login",
  "labelTextEmail": "Email address",
  "labelTextPassword": "Password"
}
  1. Use the new string
import 'package:something/l10n/l10n.dart';

@override
Widget build(BuildContext context) {
  final l10n = context.l10n;
  return Text(l10n.labelTextEmail);
}

Adding Supported Locales

Update the CFBundleLocalizations array in the Info.plist at ios/Runner/Info.plist to include the new locale.

    ...

    <key>CFBundleLocalizations</key>
	<array>
		<string>en</string>
		<string>fr</string>
	</array>

    ...

💉 Dependency Injection

Dependency injection is a technique where one object (or static method) supplies the dependencies of another object. For our case, we created a file located in the root application that handles the dependency injection setup for the application using the Get package.

It defines a DI class that extends Bindings, ensuring that necessary dependencies are initialized and made available throughout the app. The dependencies method registers instances of AppConfig, LocalStorage, and NetworkClient, promoting cleaner code and better modularity by decoupling object creation from their usage.

🔨 Naming Convention

  • DO name packages, directories, and source files using lowercase_with_underscores
  • Classes, enum types, typedefs, and type parameters should capitalize the first letter of each word (including the first word), and use no separators.
    class SliderMenu { ... }
    

❌ Linter Rules

Rule Status Description
avoid_print: true ✅ Enabled Avoid using print statements in your code. Use proper logging instead.
prefer_single_quotes: true ✅ Enabled Be consistent and use single quotes (') instead of double quotes (") in code.
lines_longer_than_80_chars ✅ Enabled Ensure no lines exceed 80 characters to maintain readability and code quality.
unawaited_futures ✅ Enabled Ensure all futures are awaited to prevent unintended behavior or missed errors.

👉 Feel free to add yours: https://dart.dev/tools/linter-rules

Expected results when running this repo

Creation of the initial instances

alt text

Logs

alt text

🚀 Getting Started

Follow these steps to get the project up and running on your local machine:

Prerequisites

Installation

  1. Clone the repository:
    git clone <repository-url>
  2. Navigate to the project directory:
    cd flutter-starter-bloc
  3. Get the dependencies:
    flutter pub get

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors