The operator '[]' isn't defined for the class 'Object'. Dart
ModalRoute.settings.arguments
is a property with the type Object
. You cannot call an indexer []
on an Object
. Everything in Dart inherits from Object
, which is why you can pass your arguments to the ModalRoute
no matter what it is. In order to use it, though, you need to first cast it to the type you are expecting to work with.
tag: (ModalRoute.of(context).settings.arguments as Map)["tag"].toString(),
ModalRoute.settings.arguments is a property with the type Object.so you can make it Map
final routeArgs = ModalRoute.of(context)!.settings.arguments as Map;final tag = routeArgs['tag'];