Skip to content

get_it seems to be closing http Client connection! #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ajaygautam opened this issue May 22, 2020 · 1 comment
Closed

get_it seems to be closing http Client connection! #80

ajaygautam opened this issue May 22, 2020 · 1 comment

Comments

@ajaygautam
Copy link

ajaygautam commented May 22, 2020

After switching to get_it (get_it: ^4.0.2), my flutter app starts failing with this error:

flutter: SchedulerBloc LoadUserReservations err ===>>> NoSuchMethodError: The method 'openUrl' was called on null.
Receiver: null
Tried calling: openUrl("GET", Instance of '_Uri')
SchedulerBloc LoadUserReservations stack ===>>> #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1      IOClient.send (package:http/src/io_client.dart:31:37)
#2      BaseClient._sendUnstreamed (package:http/src/base_client.dart:176:38)
#3      BaseClient.get (package:http/src/base_client.dart:35:7)
<... trimmed ...>

NOTE that one call goes through the HTTP client, after that calls through the client error out with the above.

Here is what my setup looks like (trimmed for brevity):

...
import 'package:http/http.dart' as http;

// "service locator" shortcut.
final sl = GetIt.instance;

Future<void> initServiceLocators() async {
  // Facility chain
  sl.registerFactory(() => FacilityBloc(sl()));
  sl.registerLazySingleton(() => FacilityRepository(sl()));
  sl.registerLazySingleton(() => FacilityAPIClient(sl())); // need http.Client()

  // Scheduler chain
  sl.registerFactory(() => SchedulerBloc(sl()));
  sl.registerLazySingleton(() => SchedulerRepository(sl()));
  sl.registerLazySingleton(() => SchedulerApiClient(sl())); // need http.Client()

  // Auth chain <... trimmed ...>

  // Register system services
  final SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
  sl.registerLazySingleton(() => sharedPreferences);
  sl.registerLazySingleton(() => http.Client());
}

Let me know if I am doing anything wrong.

$ flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 1.19.0-2.0.pre.133, on Mac OS X 10.15.3 19D76, locale en-US)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
[✓] Android Studio (version 3.6)
[✓] VS Code (version 1.44.2)
[✓] Connected device (1 available)
@ajaygautam
Copy link
Author

Sorry! My bad!
I started setting breakpoints and noticed a close() call in my SchedulerApiClient - this was being called by the hot reload process.
Removed it.
get_it works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant