简体   繁体   中英

A value of type 'Object?' can't be assigned to a variable of type 'Map<String, dynamic>'. flutter related issue

 RouteFactory _routes() {
    return (settings) {
      final args = settings.arguments;
      final Map<String, dynamic> arguments = **args** ; //here is error in args
      Widget screen;
      switch (settings.name) {
        case LocationRoute:
          screen = Locations();
          break;
        case LocationDetailRoute:
          screen = LocationDetail(arguments['id']);
          break;
        default:
          return null;
      }
      return MaterialPageRoute(builder: (BuildContext context) => screen);
    };
  }

here in args there is an error(A value of type 'Object?' can't be assigned to a variable of type 'Map<String, dynamic>'. Try changing the type of the variable, or casting the right-hand type to 'Map<String, dynamic>'.)

Manually Cast args as Map<String, dynamic> .

final Map<String, dynamic> arguments = args as Map<String, dynamic>;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM