Ad

How To Pass Data Dynamically To A Widget Class Inside Model

I have a model like this:

class MyModel{
  Widget widget;
  MyModel(this.widget);
}

var myPage = MyModel(HomeWidget());

is there a way to pass data to HomeWidget() using model when i use it? like this?

myPage.widget("some data")

or any way to pass data to widget dynamically?

Ad

Answer

u can try callback like way

class MyModel{
  Function(String data) widget;
  MyModel(this.widget);
}

var myPage = MyModel((String data) => HomeWidget(data));
myPage.widget("some data");
Ad
source: stackoverflow.com
Ad