stacked icon indicating copy to clipboard operation
stacked copied to clipboard

setupLocator always returns void

Open sanalkv opened this issue 5 years ago • 6 comments

I'm not able to use await for setupLocator. I would like the setupLocator to return a future if there is any class type that requires resolving the future.

instead of locator.registerLazySingleton(() => SharedPreferenceService.getInstance());, it should be locator.registerLazySingleton(() async=> await SharedPreferenceService.getInstance());

sanalkv avatar Apr 15 '21 05:04 sanalkv

Use Presolve for registering async instance and make sure getInstance has Future return type

 Presolve(
      classType: LocalStorageService,
      presolveUsing: LocalStorageService.getInstance,
    )

hurbes avatar Apr 16 '21 11:04 hurbes

I'm using presolve. getInstance returns static Future<SharedPreferenceService> getInstance()

sanalkv avatar Apr 16 '21 12:04 sanalkv

@FilledStacks

sanalkv avatar Apr 19 '21 06:04 sanalkv

@kodjosama

sanalkv avatar Apr 22 '21 07:04 sanalkv

share a snippet code of the app.dart file

kodjosama avatar Apr 23 '21 00:04 kodjosama

Using this

  Presolve(
    classType: CloudLoggingService,
    presolveUsing: CloudLoggingService.getInstance,
  ),

Will generate this

Future setupLocator() async {
  final sharedPreferencesService = await SharedPreferencesService.getInstance();
  locator.registerSingleton(sharedPreferencesService);
}

so it's a Future you can await. We use this exact functionality

FilledStacks avatar Apr 28 '21 16:04 FilledStacks