Basically, I'm able to send user locations to an API, and I want that upon sending, I can capture this location and make it global throughout my project, so that I can create a widget to display the location. I'm using get_it and it always returns:
Bad state: GetIt ObjectFactory with type UserLocation is not registered inside GetIt
mycode
final GetIt locator = GetIt.instance;
void setupLocator(double latitude, double longitude, String registeredAt){
locator.registerSingleton<UserLocation>(UserLocation
latitude: latitude,
longitude: longitude,
registeredAt: registeredAt
));
}
class SendLocationController {
Future<Void> sendLocationToApi(LocationDto apiData) async {
//api data is ok, it is sending
setupLocator(apiData.latitude,apiData.longitude, apiData.registeredAt)
UserLocation locationOnSend = locator<UserLocation>();
}
}
Widget buildUserLocation(){
UserLocation locationOnSend = locator<UserLocation>();
//rest of widget
}
Am I using get_it incorrectly?
How do I create an object within an asynchronous function, make it global, and use it throughout my project, specifically to build a widget with this data? Thank you, folks