modular_di 0.0.1 modular_di: ^0.0.1 copied to clipboard
A lightweight and flexible module system for Flutter applications, providing dependency injection and module management capabilities.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:modular_di/modular_di.dart';
import 'features/core/core_module.dart';
import 'features/home/home_module.dart';
import 'features/message/message_module.dart';
import 'features/message/ui/screens/message_screen.dart';
import 'features/profile/profile_module.dart';
/// ### All the modules that the app has. <br/>
/// It's used to initialize the dependencies. <br/><br/>
final modules = <Module>[
CoreModule(),
MessageModule(),
HomeModule(),
ProfileModule(),
];
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
ModulesManager.instance.addModules(modules);
await ModulesManager.instance.initAllModules();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
initialRoute: '/',
routes: {
'/': (context) => const ModuleWidget<HomeModule>(child: HomeScreen()),
'/message': (context) => const ModuleWidget<MessageModule>(child: MessageScreen()),
'/profile': (context) => const ModuleWidget<ProfileModule>(child: ProfileScreen()),
},
);
}
}