A robust, modular template for building scalable Flutter applications using the GetX package. This template promotes clean architecture, code reusability, and efficient state management.
Update the package name to match your project:
dart run change_app_package_name:main "com.getx.template"Update the app name:
dart run rename_app:main all="GetX Template"Update the app icon (replace assets/images/app_logo.png):
dart run flutter_launcher_icons:main- Offline Storage: Utilizes
sqflitewith a pre-configureddb_helper.dartin thecorefolder. - Default DB File:
assets/db/getx_template.db. - Steps to Update:
- Rename the file (e.g.,
my_app.db). - Update the path in
lib/app/core/db_helper/db_helper.dart.
- Rename the file (e.g.,
assets/ - Static assets (images, fonts, database files).
ios/ - iOS-specific files.
android/ - Android-specific files.
lib/ - Main directory for Dart code.
lib/
app/ - Main app logic.
flavor/ - Flavor configurations (dev, prod, etc.).
l10n/ - Localization files.
main_dev.dart - Entry point for development flavor.
main_prod.dart- Entry point for production flavor.
app/
bindings/ - Dependency injection (bindings).
core/ - Core logic, utilities, and reusable components.
entity/ - Data models/entities.
global_modal/ - App-wide modals.
global_widgets/ - Reusable widgets.
modules/ - Feature modules (e.g., Home, Login).
routes/ - Navigation routes.
services/ - API and backend services.
my_app.dart - App initialization.
core/
base/ - Abstract classes (`BaseController`, `BaseView`).
core_model/ - Core models (e.g., LoggedUser, PageState).
db_helper/ - Database helper (`sqflite`).
session_manager/- Lightweight session management.
utils/ - Utility functions (e.g., validators).
values/ - App-wide constants (e.g., colors, themes).
widgets/ - Core widgets (e.g., buttons, inputs).
exporter.dart - Centralized export file for core resources.
The BaseController is a shared foundation for all controllers. It manages:
- State Management:
- Page states (
loading,success,error) viaPageState. - Reactive updates with
Rxvariables for seamless UI synchronization.
- Utilities:
- Internet checks with
hasInternet(). - Dynamic locale switching (
changeLocale()).
- Error and Loader Management:
showLoader()andcloseLoader()for loading overlays.- Centralized error handling with
_handleException().
- Session Management:
- Persistent preferences with
SessionManager.
- Database Support:
- Pre-configured
DbHelperfor SQLite.
The BaseView class provides a consistent UI scaffold and integrates with BaseController.
- Dynamic UI Handling:
- Observes
PageStateto render appropriate content (loading spinners, error views, etc.).
- Reusable Structure:
- Predefined layout with customizable
appBar(),body(),drawer(), andfloatingActionButton().
- Error Handling and Debugging:
showErrorSnackBar()andshowToast()for user feedback.- Debug tools for tracking current routes and states.
- Create Module Files:
- Add a new folder under
modules(e.g.,home). - Create three files:
home_controller.darthome_view.darthome_binding.dart
- Set Up Routing:
- Add the route to
routes/app_pages.dart.
- Connect the Module:
- Use
HomeBindingto register dependencies.
- Implement Logic:
- Extend
BaseControllerfor shared functionality. - Update UI in
BaseView.
class HomeBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut<HomeController>(() => HomeController());
}
} class HomeController extends BaseController {
@override
Future<void> onInit() async {
super.onInit();
// Initialize logic here.
}
} class HomeView extends BaseView<HomeController> {
@override
PreferredSizeWidget? appBar(BuildContext context) {
return AppBar(title: Text('Home'));
}
@override
Widget body(BuildContext context) {
return Center(child: Text('Welcome to Home'));
}
} - Scalable Architecture:
- Modularized structure ensures maintainability and scalability.
- Reusable Components:
- Shared utilities, widgets, and base classes minimize code duplication.
- State Management Simplified:
- GetX integration for reactive programming and navigation.
- Customizable:
- Easy to update package name, app name, icon, and database.
- Consistency:
- Predefined patterns ensure uniformity across modules.
- Core files in
core/are rarely modified—they handle reusable and common app logic. - Developers should focus on
modules/,routes/, andservices/for feature development. - This template is ideal for medium to large Flutter projects.
- create a CLI to generate modules and other files
- add more examples
Happy coding! 🚀