Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter, can i pass a Map for the named parameters

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)
}
like image 768
Lpc_dark Avatar asked Oct 11 '19 16:10

Lpc_dark


People also ask

How do you pass parameters to widgets in flutter?

Steps to Pass Data to Stateful Widget in Flutter To pass data to stateful widget, first of all, create two pages. Now from the first page open the second page and pass the data. Inside the second page, access the variable using the widget. For example widget.


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.

like image 195
Alexey Inkin Avatar answered Sep 22 '22 08:09

Alexey Inkin