opticore 2.1.6
opticore: ^2.1.6 copied to clipboard
OptiCore is a lightweight micro-framework for Flutter that simplifies and optimizes your app development
OptiCore Module Structure π #
This document outlines the OptiCore module structure, designed for scalability, maintainability, and efficiency. The architecture ensures a clean separation of concerns, making development seamless.
π Folder Structure #
Each module follows this structured hierarchy:
lib/
module/
<ModuleName>/
π¦ bloc/ # Business logic layer (BLoC)
βββ <module_name>_bloc.dart
β‘ event/ # Events triggering BLoC updates
βββ <module_name>_event.dart
π state/ # UI state definitions
βββ <module_name>_state.dart
π₯οΈ screen/ # UI components (Widgets)
βββ <module_name>_screen.dart
π import/ # Centralized module imports
βββ <module_name>_import.dart
π factory/ # State factory management
βββ <module_name>_state_factory.dart
β¨ Example: ExampleModule
#
lib/
module/
ExampleModule/
π¦ bloc/
βββ example_module_bloc.dart
β‘ event/
βββ example_module_event.dart
π state/
βββ example_module_state.dart
π₯οΈ screen/
βββ example_module_screen.dart
π import/
βββ example_module_import.dart
π factory/
βββ example_module_state_factory.dart
π File Overview #
ποΈ BLoC (example_module_bloc.dart
) #
Handles the business logic and state transitions.
part of '../import/example_module_import.dart';
class ExampleModuleBloc extends BaseBloc {
ExampleModuleBloc()
: super(
ExampleModuleStateFactory(),
initialState: ExampleModuleInitialState(),
);
@override
void onDispose() {}
}
β‘ Event (example_module_event.dart
) #
Defines events that trigger state changes.
part of '../import/example_module_import.dart';
class ExampleModuleInitialEvent extends BaseEvent {}
π State (example_module_state.dart
) #
Defines the UI state.
part of '../import/example_module_import.dart';
class ExampleModuleInitialState extends RenderDataState {
ExampleModuleInitialState() : super(null);
}
π₯οΈ Screen (example_module_screen.dart
) #
Handles the UI and interacts with the BLoC.
part of '../import/example_module_import.dart';
class ExampleModuleScreen extends StatefulWidget {
final ExampleModuleBloc bloc;
const ExampleModuleScreen({super.key, required this.bloc});
@override
ExampleModuleScreenState createState() => ExampleModuleScreenState(bloc);
}
class ExampleModuleScreenState
extends BaseScreen<ExampleModuleBloc, ExampleModuleScreen, dynamic> {
ExampleModuleScreenState(super.bloc);
@override
Widget buildWidget(BuildContext context, RenderDataState state) {
return Container();
}
@override
void listenToState(BuildContext context, BaseState state) {}
}
π Import (example_module_import.dart
) #
Manages centralized imports.
import 'package:flutter/material.dart';
import 'package:opticore/opticore.dart';
part '../bloc/example_module_bloc.dart';
part '../event/example_module_event.dart';
part '../screen/example_module_screen.dart';
part '../state/example_module_state.dart';
part '../factory/example_module_state_factory.dart';
π State Factory (example_module_state_factory.dart
) #
Creates and manages different states dynamically.
part of '../import/example_module_import.dart';
class ExampleModuleStateFactory extends BaseFactory {
@override
BaseState getState<M>(M data) {
return DefaultState();
}
}
π― Key Benefits #
β
Modular & Scalable β Ensures long-term maintainability
β
Separation of Concerns β Organized into logical units
β
Optimized for BLoC β Structured for predictable state management
Start building robust OptiCore modules with this scalable structure today! π