You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I have future function to load color from json file like this
Future<ColorKey> load() async {
final path = "assets/colors/light.json";
final strJson = await rootBundle.loadString(path);
Map<String, dynamic> data = jsonDecode(strJson);
return ColorKey(Map<String, String>.from(data));
}
I tried to register that function using get_it like this serviceLocator.registerFactoryAsync<ColorKey>(() => ColorBase().load());
and this serviceLocator.registerLazySingletonAsync<ColorKey>(() => ColorBase().load());
but both shows error.
Then I tried this
final color = await ColorBase().load();
serviceLocator.registerFactory<ColorKey>(() => color);
and this
final color = await ColorBase().load();
serviceLocator.registerLazySingleton<ColorKey>(() => color);
both are working, but then when I pass ContextUtils as parameter to load() function like this
serviceLocator.registerFactoryParam<ContextUtils, BuildContext, void>((context, _) => ContextUtilsImpl(context));
final color = await ColorBase().load(serviceLocator());
serviceLocator.registerLazySingleton<ColorKey>(() => color);
it's not working, and I got this error 'context != null': is not true.
Any suggestion?
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
Hello, I have future function to load color from json file like this
I tried to register that function using get_it like this
serviceLocator.registerFactoryAsync<ColorKey>(() => ColorBase().load());
and this
serviceLocator.registerLazySingletonAsync<ColorKey>(() => ColorBase().load());
but both shows error.
Then I tried this
and this
both are working, but then when I pass ContextUtils as parameter to load() function like this
it's not working, and I got this error
'context != null': is not true.
Any suggestion?
The text was updated successfully, but these errors were encountered: