easy_get_it 0.0.6 copy "easy_get_it: ^0.0.6" to clipboard
easy_get_it: ^0.0.6 copied to clipboard

A simple and lightweight service locator for managing dependencies in Flutter and Dart applications.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:easy_get_it/easy_get_it.dart';

void main() {
  // Register dependencies
  getIt.registerSingleton<CounterService>(CounterService());

  runApp(const MyApp());
}

/// Simple service to demonstrate DI
class CounterService {
  int counter = 0;

  void increment() {
    counter++;
  }
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Easy GetIt Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const MyHomePage(title: 'Easy GetIt Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  // Get service from locator
  final counterService = getIt.get<CounterService>();

  void _incrementCounter() {
    setState(() {
      counterService.increment();
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text('You have pushed the button this many times:'),
            Text(
              '${counterService.counter}',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}
0
likes
160
points
28
downloads
screenshot

Documentation

API reference

Publisher

verified publisherrony.fun

Weekly Downloads

A simple and lightweight service locator for managing dependencies in Flutter and Dart applications.

Repository (GitHub)
View/report issues

Topics

#dependency-injection #service-locator #inversion-of-control #di-container #di

License

MIT (license)

Dependencies

flutter

More

Packages that depend on easy_get_it