-2

I have a class which has an instance of Dio as dependency. how can i solve it using injectable?

reza
  • 1,354
  • 1
  • 7
  • 25

1 Answers1

0

I use get_it as my dependency injection.

https://pub.dev/packages/get_it

Example main.dart:

// declare a global variable
GetIt getIt = GetIt.instance;

Your dependency injection file:

import 'package:YOUR_PACKAGE/main.dart' as main;
main.getIt.registerSingleton<Dio>(Dio());

Then, when you want to use it:

import 'package:YOUR_PACKAGE/main.dart' as main;
Dio dio => main.getIt<Dio>();
Jared Anderton
  • 826
  • 9
  • 12