Could some please explain what is wrong?

I try to get an item by key from HashMap:

If I do it that way:

var stringProvider = providersHolder[String] I get an error:

NoSuchMethodError: Class 'Module' has no instance getter 'String'.

If I do it next way:

var stringProvider = providersHolder[providersHolder.keys.last] where providersHolder.keys.last == String

I get success.

Here is a full listing:

class Module {
  HashMap providersHolder = new HashMap<Type, ItemCreator>();

  void addProvider<T, M extends Module>(ItemCreator<T, M> itemCreator) {
     providersHolder[T] = itemCreator;

class Test {
    Test() {
      var module = Module();
      module.addProvider((module) => new Ticker());
      module.addProvider((module) => "hello");
      var ticketProvider = module.providersHolder[Ticker]; //success
      var stringProvider = module.providersHolder[String]; //error

Here is a watcher:


Solution 1: Omatt

Could you provide more details on how ItemCreator was defined? This will help us replicate the behavior you've encountered. If you're still having the same errors, you can also run flutter doctor -v to check for any errors or warnings.