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?