I know there are other same questions but I couldn't find the solution. The NotificationRepository depends on NotificationService and it depends on Flutter local Notifications plugin instance.
Initialization
final GetIt getIt = GetIt.instance;
@InjectableInit(
initializerName: 'init', // default
preferRelativeImports: true, // default
asExtension: true,
)
void configureDependencies() => getIt.init();
I have called it in main
@module
abstract class InjectableModule {
// for other use
@lazySingleton
Dio dio() => ...
@lazySingleton
FlutterLocalNotificationsPlugin getLocalNotification() =>
FlutterLocalNotificationsPlugin();
}
this is the module that I have used to put FLNotification to Notification Service
abstract class NotificationService {
// required functions...
}
@LazySingleton(as: NotificationService)
class NotificationServiceImp implements NotificationService {
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
NotificationServiceImp(this.flutterLocalNotificationsPlugin);
.....
}
abstract class NotificationRepository {
....
}
@LazySingleton(as: NotificationRepository)
class NotificationRepositoryImpl implements NotificationRepository {
final NotificationService _notificationService;
NotificationRepositoryImpl(this._notificationService);
....
}
This is the warning I get when I run build runner
[WARNING] injectable_generator:injectable_config_builder on lib/di/get_it.dart:
Missing dependencies in statedemo/di/get_it.dart
[NotificationRepositoryImpl] depends on unregistered type [NotificationService] from package:statedemo/data/services/notification_serivce_imp.dart
This is the error that I get when I run the code
Bad state: GetIt: Object/factory with type NotificationService is not registered inside GetIt.
(Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance;
Did you forget to register it?)
GetIt works fine with the other registration that I have done in this project for Dio. I just wanted to implement notification feature. This feature works fine when I try to implement Singleton pattern for notification service manually. I have also tried named Instance and I get this
Bad state: GetIt: Object/factory with with name NotificationServiceImp and type NotificationService
is not registered inside GetIt.
(Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance;
Did you forget to register it?)
Thanks for giving your time. If you want more information I can provide.