Description
Using get_it: ^7.6.0
I am getting several variants of the same bug in my production code and I'm wondering why get it would have a null instance in several different cases. I have 8 variants in 2 days. I cannot reproduce in developement mode of the app.
The line that keeps throwing is
instance = instanceFactory.instance!;
inside your get_it_impl.dart
I am using this function to register singletons with get_it. I have not seen this problem surface but customers are complaining about seeing the error Null check operator used on a null value. Error thrown Instance of 'ErrorDescription'.
Please advise as to why this is happening and if there's a way to ensure the instance factory has the instance when accessed?
void registerService<T extends LoadableService>(
T Function() factoryFunction,
{bool lazy = false,
List<Type>? dependsOn}) {
var registerFcn = () async {
final service = factoryFunction();
await service.load();
return service;
};
if (lazy) {
locator.registerLazySingletonAsync<T>(registerFcn);
} else {
locator.registerSingletonAsync<T>(registerFcn, dependsOn: dependsOn);
}
}
Here are 3 of the 8 different stack traces.
VARIENT 1
0 ??? 0x0 _GetItImplementation.get + 437 (get_it_impl.dart:437)
1 ??? 0x0 _GetItImplementation.call + 461 (get_it_impl.dart:461)
2 ??? 0x0 _EffectsOfAddingState.build + 346 (EffectsOfAdding.dart:346)
3 ??? 0x0 StatefulElement.build + 5080 (framework.dart:5080)
VARIENT 2
0 ??? 0x0 _GetItImplementation.get + 437 (get_it_impl.dart:437)
1 ??? 0x0 _GetItImplementation.call + 461 (get_it_impl.dart:461)
2 ??? 0x0 Problem.titleString + 128 (Problem.dart:128)
3 ??? 0x0 _WaterTestServiceCellState._buildTestProblemRow + 178 (WaterTestServiceCell.dart:178)
4 ??? 0x0 _WaterTestServiceCellState._buildProblemList. + 325 (WaterTestServiceCell.dart:325)
VARIENT 3
0 ??? 0x0 _GetItImplementation.get + 437 (get_it_impl.dart:437)
1 ??? 0x0 _GetItImplementation.call + 461 (get_it_impl.dart:461)
2 ??? 0x0 _EffectsOfAddingState.build + 346 (EffectsOfAdding.dart:346)
3 ??? 0x0 StatefulElement.build + 5080 (framework.dart:5080)