Home > Net >  is this possible to use Map<String, Function> in flutter?
is this possible to use Map<String, Function> in flutter?

Time:02-04

I'm new to Flutter. I'm trying to use this sentence

  Map<String, Function> map = Map();

  Function fun1 = (() => print("TAG : 1111"));
  map.putIfAbsent("test", fun1);
  map["test"]!.call();

But in runtime, I've got the error like this.

Dart Unhandled Exception: type '_TypeError'

I want to use the map including some function because of not supported reflection Is there any solution in my case?

CodePudding user response:

Update your map.putIfAbsent() to:

map.putIfAbsent("test", () => fun1);
  •  Tags:  
  • Related