How to pass data dynamically to a Widget class inside Model


I have a model like this:

class MyModel{
  Widget 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?


u can try callback like way

class MyModel{
  Function(String data) widget;

var myPage = MyModel((String data) => HomeWidget(data));
myPage.widget("some data");

Answered By – Husen

Answer Checked By – Clifford M. (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *