Creating widgets dynamically

I’m building a program for my collage project. In that program, the program reads a json file from local and creates widgets dynamically according to the specifications described on it. If I wanted to create widgets vertically, then I would have to use “keyed_column” . If I combined it with a scrollable, then the program would not even start. “keyed_column” creates widgets vertically, but I haven’t found any way to create widgets horizontally. I tried to find any guide or document, but I haven’t found any. Does anyone know how to do that and make it scrollable?

Thank you.

Something along these lines should work:

    fn view(&self) -> iced::Element<Message> {
        if self.json_said_vertical {
            return iced::widget::scrollable::Scrollable::new(
                iced::widget::Column::new()
                .push(iced::widget::Text::new("hello"))
                .push(iced::widget::Text::new("hi"))
            ).into();
        } else {
            return iced::widget::scrollable::Scrollable::new(
                iced::widget::Row::new()
                .push(iced::widget::Text::new("hello"))
                .push(iced::widget::Text::new("hi"))
            ).into();
        };
    }

Thanks for your suggestion. But the code only works if you have a number of fixed elements. What I’m trying to do is add a number of widgets based on the number of elements the array has.

Then it’s only a matter of calling that push method inside a loop.

I have already tried that, But it does not work.

It should. Can you share your code and the error you’re getting?

sorry for my late reply, I was busy due to my college exams.

My Project in this program it shows a set of packages defined in the config file at the left side of the program. I want to loads all of these entries from the config and shows in a scrollable list, but if I put it in a scrollable program doesn’t even start.

Either create a new branch with the patch you are trying to apply or share it here. I cloned the repo and it builds fine, I can’t see what you’re trying or why it’s failing.