2

In my case: I have listTemplates the same:

List<TemplateModel> listTemplate = [
TemplateModel(
    id: 1,
    name: 'Temp_1',
    previewBack: AppImages.TEMP_1,
    previewFront: AppImages.TEMP_1,),
TemplateModel(
    id: 2,
    name: 'Temp_2',
    previewBack: AppImages.TEMP_2,
    previewFront: AppImages.TEMP_2),
TemplateModel(
    id: 3,
    name: 'Temp_3',
    previewBack: AppImages.TEMP_3,
    previewFront: AppImages.TEMP_3),
TemplateModel(
    id: 4,
    name: 'Temp_4',
    previewBack: AppImages.TEMP_4,
    previewFront: AppImages.TEMP_4),
  ];

And I also have Temp_1(), Temp_2(), Temp_3(), Temp_4() Widgets.

I want to show each by name of template ex:

Container(
    child: `Temp_1`(), // It's my explain to try to show my problem, of course, it's not work.
);

I don't want to use if-else or switch-case for this case becuase I have the too large list templates.

Thank you for your answer!

2 Answers 2

1

I think It's not support now. Do you use right solution for this case?

Sign up to request clarification or add additional context in comments.

Comments

0

No, you can't. Another option you can use - Map<int, Widget>.

final temperatureUI = {
    1: Temp_1(),
    ...
}

and then

Container(
    child: temperatureUI[templateModel.id],
);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.