layer_kit 0.0.6-dev.2 copy "layer_kit: ^0.0.6-dev.2" to clipboard
layer_kit: ^0.0.6-dev.2 copied to clipboard

A Flutter architecture package that combines Clean Architecture and MVVM patterns using Provider for state management.

LayerKit #

Where MVVM meets Clean Architecture

LayerKit is a powerful Flutter framework that combines the best aspects of MVVM (Model-View-ViewModel) pattern with Clean Architecture principles to create a robust, maintainable, and scalable application structure.

pub package License: MIT

[Layer Kit]

🌟 Features #

  • Clean Project Structure - Organized folder structure that follows both MVVM and Clean Architecture principles
  • Feature Generation - CLI tools to quickly scaffold new features with all necessary components
  • Project Generation - Quickly bootstrap an entire project with best practices built-in
  • View State Management - Built-in ViewModel base classes with state handling
  • Error Handling - Standardized exceptions and failures for consistent error handling
  • Configuration System - Flexible configuration for different environments
  • Extension Methods - Utility extensions for common types to reduce boilerplate
  • UI Utilities - Helper methods for common UI tasks like decorations
  • Logging - Development-friendly logging system

πŸ“‹ Table of Contents #

πŸš€ Installation #

Add LayerKit to your pubspec.yaml:

dependencies:
  layer_kit:

Run:

flutter pub get

πŸ“ Project Structure #

LayerKit organizes your project into a well-defined structure:

lib/
β”œβ”€β”€ config/                         # Configuration files
β”‚   β”œβ”€β”€ data/                       # Data-related config
β”‚   β”œβ”€β”€ lang/                       # Localization
β”‚   β”œβ”€β”€ routes/                     # Routing
β”‚   └── theme/                      # Theme configuration
β”œβ”€β”€ core/                           # Core components
β”‚   β”œβ”€β”€ callbacks/                  # Callback interfaces
β”‚   β”œβ”€β”€ common/                     # Common utilities
β”‚   β”‚   └── widgets/                # Reusable widgets
β”‚   β”œβ”€β”€ constants/                  # Constants
β”‚   β”œβ”€β”€ extensions/                 # Extension methods
β”‚   β”œβ”€β”€ helper/                     # Helper methods 
β”‚   β”œβ”€β”€ network/                    # Network service 
β”‚   └── utils/                      # Utilities
β”œβ”€β”€ src/                            # Features
β”‚   β”œβ”€β”€ feature1/                   # Feature module
β”‚   β”‚   β”œβ”€β”€ datasource/             # Data sources
β”‚   β”‚   β”‚   β”œβ”€β”€ models/             # Data models
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ body_models/    # UI display Model (used in screens)
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ requests/       # API request models
β”‚   β”‚   β”‚   β”‚   └── response/       # API response models
β”‚   β”‚   β”‚   └── repo/               # Repository implementation
β”‚   β”‚   β”œβ”€β”€ providers/              # Feature providers
β”‚   β”‚   └── screens/                # UI screens
β”‚   └── feature2/                   # Another feature module
β”œβ”€β”€ di_container.dart               # Dependency Injection imports (part of di main)
β”œβ”€β”€ di_container.main.dart          # di main file - injection of all dependencies
└── main.dart                       # Entry point

🏁 Getting Started #

Generating a New Project #

Create a new Flutter project, then run:

dart run layer_kit --project

This will generate a properly structured project with all the necessary files and configurations.

Generating a New Feature #

To add a new feature to your project:

dart run layer_kit --feature feature_name

This command will:

  1. Create a feature directory in the src folder
  2. Generate all necessary files following MVVM and Clean Architecture principles
  3. Update routes to include the new feature

βš™οΈ Configuration #

LayerKit provides a flexible configuration system through KitConfig:

/// ...code....  
@override
Widget build(BuildContext context) {
  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
    // DeviceOrientation.landscapeRight,
    // DeviceOrientation.landscapeLeft,
  ]);

  return Consumer<ThemeProvider>(builder: (context, state, _) {
    return LayerKitConfigProvider(
      envType: EnvType.development,
      defaultRadius: 10,
      showApiReqLog: false,
      showApiResLog: true,
      /// other config options
      child: AppResponsiveTheme( /// for Theme Configuaration [see responsive_theme package on pub.flutter-io.cn]
        themeMode: state.theme,
        config: ColorConfig(
          lightColors: AppColors.light().toThemeColor(),
          darkColors: AppColors.dark().toThemeColor(),
        ),
        child: ToastificationWrapper(
          child: MaterialApp(
            title: AppConsts.appName,
            debugShowCheckedModeBanner: false,
            /// route config [see flutter_easy_routing package on pub.flutter-io.cn]
            navigatorKey: AppRouter.navigatorKey,
            onGenerateRoute: (s) => AppRouter.generateRoute(s, SplashScreen()),
            scrollBehavior: const StretchScrollBehavior(),
            initialRoute: Routes.splash.path,
            localizationsDelegates: context.localizationDelegates,
            supportedLocales: context.supportedLocales,
            locale: context.locale,
            theme: state.darkTheme ? ThemeData.dark() : ThemeData.light(),
            builder: (context, child) {
              return MediaQuery(
                data: MediaQuery.of(context).copyWith(textScaler: const TextScaler.linear(1.0)),
                child: child ?? SizedBox(),
              );
            },
          ),
        ),
      ),
    );
  });
}
/// ...code....

🧠 Core Concepts #

MVVM + Clean Architecture #

LayerKit combines MVVM pattern with Clean Architecture principles:

  • View - Flutter UI components (screens, widgets)
  • ViewModel - Business logic and state management
  • Model - Data models and repository interfaces

With additional Clean Architecture layers:

  • Repositories - Abstract data source interactions and Implementation that access data models
  • Data Sources - Concrete implementations of data access - Models, Requests, Responses

ViewModels #

ViewModels in LayerKit extend the BaseViewModel class:

class MovieProvider extends BaseViewModel {
  final MovieRepo _movieRepo;
  final NetworkService _networkService;

  MovieProvider({required MovieRepo movieRepo, required NetworkService networkService})
          : _movieRepo = movieRepo,
            _networkService = networkService;

  Future<bool> getData({
    required String data1,
    required String data2,
    bool listen = true,
  }) async {
    setLoading();
    final isNetwork = await _networkService.isConnected;
    final isSuccess = await apiCallback(
      name: "getData",
      isNetwork: isNetwork,
      doWhenOnline: () async {
        final req = MovieReq(data1: data1, data2: data2);
        final res = await _movieRepo.getData(req);
        showSnackbar(res.message);
        setLoaded();
        return res.status;
      },
      errorListener: (e) {
        setError(e.toString());
      },
    );
    if (listen) notifyListeners();
    return isSuccess;
  }
}

Repositories #

Repositories abstract data sources:

abstract interface class MovieRepo {
  Future<MovieResponse> getData(MovieReq req);
}

class MovieRepoImpl implements MovieRepo {
  final DioClient _dioClient;

  MovieRepoImpl({required DioClient dioClient}) : _dioClient = dioClient;

  @override
  Future<MovieResponse> getData(MovieReq req) async {
    return await repoCallback<MovieResponse>(
      name: "getData",
      callback: () async {
        final res = await _dioClient.post(Apis.getData, data: req.toJson());
        return MovieResponse.fromJson(res.data ?? {});
      },
    );
  }
}

πŸ› οΈ Extensions #

LayerKit includes several useful extensions:

// String casing
"hello world".toTitleCase      // "Hello World"
"example".firstUpperCased      // "Example"

// Time formatting
120.toMMSS                     // "02 : 00"
3725.toHHMMSS                  // "01 : 02 : 05"

🀝 Contributing #

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License #

LayerKit is available under the MIT license. See the LICENSE file for more info.


Created by Nayan Parmar Β© 2025

3
likes
0
points
54
downloads

Publisher

verified publishertcircle.kesug.com

Weekly Downloads

A Flutter architecture package that combines Clean Architecture and MVVM patterns using Provider for state management.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

args, flutter, flutter_easy_routing, path, recase, responsive_theme

More

Packages that depend on layer_kit