mardi 19 janvier 2021

Flutter: Mapping Type to Widget

I have multiple widgets corresponding to each type of object, to modify attributes of these objects. these widgets are based on different state of the page (the state of the page changes with user interaction). currently i manage this mapping using many switch statements; each switch statement for each[type of widget] i need to render.

Case: there are 3 types: class A, B & C each of these types can be displayed in 3 different forms[using widgets to render] like for class A; widgetA1, widgetA2 and widgetA3. currently i do this using switch cases for each widget type in the form widget1, widget2 etc.

Question: Is there any easy, more maintainable way to do this, so every time i create a new type if don't have to add another switch case in all of the different cases

Aucun commentaire:

Enregistrer un commentaire