FilledStacks / flutter-tutorials

The repo contains the source code for all the tutorials on the FilledStacks Youtube channel.
MIT License
4.75k stars 1.76k forks source link

No type RemoteConfigService is registered inside GetIt. #62

Closed Flutter-Stack closed 1 year ago

Flutter-Stack commented 4 years ago

Thank you for wonderful tutorial.

I have configured completed all the tutorials. I have updated my code and configured firebase Remote Config Service also.

I am getting below error when I run $ flutter run --debug

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ I/flutter (24896): The following assertion was thrown building StartUpView: I/flutter (24896): No type RemoteConfigService is registered inside GetIt. I/flutter (24896): Did you forget to pass an instance name?
I/flutter (24896): (Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance;did you I/flutter (24896): forget to register it?)
I/flutter (24896): 'package:get_it/get_it_impl.dart':
I/flutter (24896): Failed assertion: line 248 pos 14: 'instanceFactory != null' I/flutter (24896):
I/flutter (24896): Either the assertion indicates an error in the framework itself, or we should provide substantially I/flutter (24896): more information in this error message to help you determine and fix the underlying cause. I/flutter (24896): In either case, please report this assertion by filing a bug on GitHub: I/flutter (24896): https://github.com/flutter/flutter/issues/new?template=BUG.md I/flutter (24896):
I/flutter (24896): The relevant error-causing widget was:
I/flutter (24896): StartUpView
I/flutter (24896): file:///home/suresh-kumara/projects/mobile-applications/firebase/compound_social_media/lib/main.dart:42:13 I/flutter (24896):
I/flutter (24896): When the exception was thrown, this was the stack:
I/flutter (24896): #2 _GetItImplementation._findFactoryByNameOrType (package:get_it/get_it_impl.dart:248:14) I/flutter (24896): #3 _GetItImplementation.get (package:get_it/get_it_impl.dart:260:27) I/flutter (24896): #4 _GetItImplementation.call (package:get_it/get_it_impl.dart:285:12) I/flutter (24896): #5 new StartUpViewModel (package:compound/viewmodels/startup_view_model.dart:18:59) I/flutter (24896): #6 StartUpView.build. (package:compound/ui/views/startup_view.dart:32:34) I/flutter (24896): #7 _ViewModelProviderState._createOrSetViewModel (package:provider_architecture/_viewmodel_provider.dart:99:23) I/flutter (24896): #8 _ViewModelProviderState.initState (package:provider_architecture/_viewmodel_provider.dart:87:7)

FilledStacks commented 4 years ago

Did you register the RemoteConfigService with the locator?

Flutter-Stack commented 4 years ago

thank you for the reply.

Yes I have registered it in locator.

I guess we have async function in locator because of that or else I haven't registered my application in google playstore or else I am trying it in debug mode is causing the issue.

Code I have same to same code as yours.

GetIt locator = GetIt.instance;

Future setupLocator() async { locator.registerLazySingleton(() => NavigationService()); locator.registerLazySingleton(() => DialogService()); locator.registerLazySingleton(() => AuthenticationService()); locator.registerLazySingleton(() => FirestoreService()); locator.registerLazySingleton(() => CloudStorageService()); locator.registerLazySingleton(() => ImageSelector()); locator.registerLazySingleton(() => PushNotificationService()); locator.registerLazySingleton(() => AnalyticsService()); locator.registerLazySingleton(() => DynamicLinkService());

var remoteConfigService = await RemoteConfigService.getInstance(); locator.registerSingleton(remoteConfigService); }

FilledStacks commented 4 years ago

Are you awaiting the setup call in the main function?

ManmohanTalwar commented 3 years ago

I'm facing the same error: 'package:get_it/get_it_impl.dart': Failed assertion: line 298 pos 9: 'instanceFactory != null': Object/factory with type AppPrefs is not registered inside GetIt. I/flutter (24182): (Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance; I/flutter (24182): Did you forget to register it?) I/flutter (24182): #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39) I/flutter (24182): #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5) I/flutter (24182): #2 _GetItImplementation._findFactoryByNameAndType (package:get_it/get_it_impl.dart:298:9) I/flutter (24182): #3 _GetItImplementation.get (package:get_it/get_it_impl.dart:313:29) I/flutter (24182): #4 _GetItImplementation.call (package:get_it/get_it_impl.dart:339:12) I/flutter (24182): #5 Services.setAppServices (package:fasalsetu/services/index.dart:29:20) I/flutter (24182): #6 _AppInitState.loadInitData (package:fasalsetu/app_init.dart:31:18) I/flutter (24182): #7 _AppInitState.initState (package:fasalsetu/app_init.dart:62:5) I/flutter (24182): #8 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4812:57) I/flutter (24182): #9 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4649:5) I/flutter (24182): #10 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3615:14) I/flutter (24182): #11 Element.updateChild (package:flutter/src/widgets/framework.dart:3380:18) I/flutter (24182): #12 ComponentElement.performRebuild (package:flutter/src/widge

code: `final GetIt locator = GetIt.instance;

Future main() async { WidgetsFlutterBinding.ensureInitialized(); Provider.debugCheckInvalidValueType = null; printLog('[main] ============== main.dart START ==============');

await setupLocator();

/// enable network traffic logging HttpClient.enableTimelineLogging = true;

await SystemChrome.setPreferredOrientations( [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);

SystemChrome.setSystemUIOverlayStyle( SystemUiOverlayStyle.light .copyWith(statusBarColor: AppConstants.primaryColor), ); runApp( MyConstants( child: App(), ), ); }

Future setupLocator() async { final preferences = await StreamingSharedPreferences.instance; locator.registerLazySingleton(() => AppPrefs(preferences)); locator.registerLazySingleton(() => NetworkUtil()); // locator.registerLazySingleton(() => Services());

locator.registerFactory(() => AppModel()); locator.registerFactory(() => AppStore()); } `

kmno commented 3 years ago

same problem here.

felipecastrosales commented 1 year ago

any updates here?

FilledStacks commented 1 year ago

Are you guys awaiting the setup call in the main function?

Are you awaiting the setup call in the main function?

FilledStacks commented 1 year ago

If you are, then put a break point on every line that does locator<AnalyticsService> and also put on on your setupLocator call.

Then check which one is hit first and see which viewmodel or service is making that request before it's registered.

felipecastrosales commented 1 year ago

Hello, I forgot to give feedback.

I had this problem in testing widgets.

I managed to solve it by following this to the letter, but it was not nso simple because I had to do it in several files.

FilledStacks commented 1 year ago

Strange, I have thousands of test files and this works perfectly fine. Most likely just a request for the service type either in a Singleton constructed before the other service is registered.

Happy you got it solved.