get_it_di_global_variable

A simple Dart package that provides a globally accessible instance of GetIt, a popular service locator for dependency injection in Flutter and Dart apps.

πŸ”§ Installation

Add this package to your pubspec.yaml:

dependencies:
  get_it_di_global_variable: latest_version 

Then run:

flutter pub get

πŸš€ Usage

This package exposes a globally accessible instance of GetIt named sl, which is short for "service locator".

Import the package:

import 'package:get_it_di_global_variable/get_it_di_global_variable.dart';

Register your dependencies:

sl.registerSingleton<ApiService>(ApiService());

Retrieve your dependencies:

final apiService = sl<ApiService>();

πŸ“¦ Provided Code

import 'package:get_it/get_it.dart';

final GetIt sl = GetIt.I;

🎯 Why use this?

  • Avoid boilerplate in each file to define a GetIt instance.
  • Cleaner and more readable dependency registration and access.
  • Common convention (sl) used in many Flutter projects.

πŸ“ License

This package is released under the MIT License.