i'm new in Dart. I came from Java and there someting I want to mimic. I have a project that has multiple screens and each screen has multiple bodies. For exemple: Screen UMW0001 Body: 0001 Body: 0002 Body: 0003
I want to build those widgets according to the body. I have a widget call BuildBody, today he's like this:
String body = autorization.getBody("UMW0001");
switch (body) {
case '0002':
return const detalhe_0002.Detalhe();
default:
return const detalhe_0001.Detalhe();
}
I would like to improve this by using some kind of factory to build the right body, something like
String body = "0002";
Widget widget = methodToCreateWidget("page/umw0001/$body");
return widget();
Is flutter capable of that?
You can do it with below code. Here i have taken the
buildBodyas an higher level function you can put it any class and make it static if you wish and can do in the constructor too.Let me know if you have any doubt regarding this.