flutter_getit 2.0.0 copy "flutter_getit: ^2.0.0" to clipboard
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

example/example.md

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,
        );
      },
    );
  }
}
82
likes
150
pub points
89%
popularity

Publisher

verified publisheracademiadoflutter.com.br

Integrating with 'get_it,' it efficiently manages Flutter project dependencies, providing robust page control, route management, and module flexibility

Repository (GitHub)
View/report issues

Topics

#dependency-injection #di #injection #router #routing

Documentation

API reference

License

MIT (license)

Dependencies

flutter, get_it

More

Packages that depend on flutter_getit