flutter_getit 2.0.0 flutter_getit: ^2.0.0 copied to clipboard
Integrating with 'get_it,' it efficiently manages Flutter project dependencies, providing robust page control, route management, and module flexibility
User Injection #
class HomePage extends StatelessWidget {
final controller = Injector.get<HomeController>();
HomePage({super.key});
@override
Widget build(BuildContext context) {
var controller = context.get<HomeController>();
return Scaffold(
appBar: AppBar(
title: const Text('Home'),
),
body: Center(child: Text(controller.name)),
);
}
}
Route #
class HomeRoute extends FlutterGetItPageRouter {
const HomeRoute({super.key});
@override
List<Bind> get bindings => [
Bind.singleton((i) => HomeController())
];
@override
WidgetBuilder get view => (context) => HomePage();
}
Configuration #
import 'package:flutter/material.dart';
import 'package:flutter_getit/flutter_getit.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return FlutterGetIt(
// "Add here the pages that will be loaded."
pages: [
FlutterGetItPageBuilder(
page: (context) => const MyHomePage(title: 'home'),
path: '/',
),
],
// In this method, the MaterialApp or Cupertino App should be returned.
builder: (context, routes, flutterGetItNavObserver) {
return MaterialApp(
title: 'Flutter Demo',
// Add the flutterGetItNavObserver attribute here.
navigatorObservers: [flutterGetItNavObserver],
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
// Add the routes attribute here.
routes: routes,
);
},
);
}
}