flutter_getit 1.2.1 flutter_getit: ^1.2.1 copied to clipboard
Project that allows you to use get_it as a dependency injection but controlled by Flutter's lifecycle, registering and unregistering in page navigation.
Exemplos #
Exemplo de page #
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)),
);
}
}
Exemplo de rota #
class HomeRoute extends FlutterGetItPageRoute {
const HomeRoute({super.key});
@override
List<Bind> get bindings => [
Bind.singleton((i) => HomeController())
];
@override
WidgetBuilder get page => (context) => HomePage();
}
Exemplo de configuração #
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const HomeRouter(),
);
}
}