Flutter, can i pass a Map for the named parameters

2,412

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.

Share:
2,412
Lpc_dark
Author by

Lpc_dark

I am a student in school and I am hoping to make some little apps for practice and just gather as much experience as possible. Love Programming and hope to be really good one day to start giving back :D

Updated on December 14, 2022

Comments

  • Lpc_dark
    Lpc_dark over 1 year

    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)
    }