Flutter, can i pass a Map for the named parameters

Viewed 2816

if i have levels of named parameters that needs to be passed down, i don't want to typeout the named parameter for ever method eg,

BaseText(text,options) LargerText(text,options) MenuText(text,options)

eventually i need to pass this to the Text Widget with the different defaults, but to write out all of the parameters, and pass each on down seems like alot of work, how can i get around this.

in JS i would just do

LargerText(text,options){
   options = {...defaultOptions,...options}
   return BaseText(text,options)
}
1 Answers

If Dart supported spreading map into named arguments, this would either reduce type safety, or introduce overhead checks.

Use objects to get around this. This is exactly what objects are for. With each call a compiler checks if the class is what the method expects and so all the fields present. You would not have this with maps.

Related