padi 1.0.2 copy "padi: ^1.0.2" to clipboard
padi: ^1.0.2 copied to clipboard

Async DI for flutter

Features #

This PADI - Async Dependency Injection - simple async DI

Usage #

Create new Padi scope

class UserScope extends Padi {
  @override
  Future<void> initAsync(BuildContext context) async {}
}

Add some deps

class UserScope extends Padi {
  late final String yourDep;
  @override
  Future<void> initAsync(BuildContext context) async {
    yourDep = "hello di";
  }

  @override
  Future<void> onError(BuildContext context, Object? error, StackTrace? stackTrace) async {
    //your hanlde here
    super.onError(context, error, stackTrace);
  }
}

Create Padi Widget that will wrap your dependency

runApp(
 PadiWidget<UserScope>(
        create: UserScope.new,
        loaderBuilder: (context) => Container(),
        errorBuilder: (context) => Container(),
        child: const App(),
      ),
)

get dependency from your di

PadiScope.of<UserScope>(context);

PadiWidget arguments explanation

  PadiWidget<UserScope>(
    // Function that returns a PadiScope
    create: UserScope.new,
    // Widget shown while `initAsync` method is running
    loaderBuilder: (context) => Container(),
    // Widget shown when an error occurs in initAsync
    errorBuilder: (context) => Container(),
    // Called after instance of Padi is created. Contains instance of created scope in function arguments
    onCreated: (padi) {},
    // Child widget that will be displayed
    child: const App(),
  ),
3
likes
130
points
32
downloads

Publisher

verified publishergdtuka.ru

Weekly Downloads

Async DI for flutter

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on padi