Skip to content

farhadrezvani7/flutter_clean_core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flutter Clean Core

Core infrastructure for large, modular Flutter projects.

Flutter Clean Core provides a ready-to-use core layer for Flutter applications following Clean Architecture and modular structure, eliminating the need to create or maintain a Core folder manually.

Features

  • Centralized configuration via CoreConfig (API base URL, headers, timeouts)
  • Ready-to-use DioModule for dev/prod/mock environments
  • Dependency Injection support using injectable and GetIt
  • Modular and testable services setup
  • Fully compatible with large-scale, clean architecture projects
  • Easy to extend with your own repositories, services, and state management

Installation

Add the package to your pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter
  flutter_clean_core: ^0.0.1
  dio: ^6.1.0
  injectable: ^2.3.0
  get_it: ^8.1.0

Usage

Initialize CoreConfig

import 'package:flutter/material.dart';
import 'package:flutter_clean_core/flutter_clean_core.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await CoreConfig.initialize(
    apiBaseUrl: "https://myapi.example.com",
  );
  await configureDependencies(environment: Env.dev);
  runApp(const MyApp());
}

Setup Dependency Injection

import 'package:get_it/get_it.dart';
import 'package:injectable/injectable.dart';
import 'injector.config.dart';

final getIt = GetIt.instance;

@InjectableInit()
Future<void> configureDependencies({String? environment}) async =>
    getIt.init(environment: environment ?? Env.dev);

abstract class Env {
  static const dev = 'dev';
  static const prod = 'prod';
  static const mock = 'mock';
}

Generate DI files

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

Using Dio or Services

import 'package:flutter_clean_core/flutter_clean_core.dart';
import 'package:dio/dio.dart';
import 'package:injectable/injectable.dart';
import 'injector.dart';

class UserRepository {
  final Dio _dio;

  UserRepository() : _dio = getIt<Dio>();

  Future<void> fetchUsers() async {
    final response = await _dio.get("/users");
    print(response.data);
  }
}

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages