Two internal types created from one type declaration when a test uses relative imports

  • Dart SDK Version (dart --version)
    Dart VM version: 2.9.0-7.0.dev.flutter-617bc54b71 (be) (Thu May 7 23:23:09 2020 +0000) on “windows_x64”

  • Whether you are using Windows, MacOSX, or Linux (if applicable)
    Windows

A user of my package get_it raised an issue that a type that he registered in GetIt was not available when he tried to access it later.

GetIt uses internally a `map<Type,Object> to store registered Objects. When debugging the test I observed that the type in question was indeed stored in the map and that the type that was passed to access it was the same type but still the map returned always null.
When comparing the hashcodes of both type instances they were different.

Following a hunch I changed all relative imports to package imports because there were problems before and suddenly it worked.

I tried to reproduce it in a new project but didn’t succeed. So I stripped down the project that had the problem.

Please watch this screencast:
https://www.screencast.com/t/dqufsChuC

you find the project here: https://github.com/escamoteur/spacex_flights_get_it_assertion

Author: Fantashit

1 thought on “Two internal types created from one type declaration when a test uses relative imports

  1. Yes, we would fix that as part of option 3 (we’re already working on a new minimal set of “must do” lints we’re planning to add per default to all Flutter & Dart templates).

Comments are closed.