1

I'm making an app that contains ViewList that have some Widget Inside it,

the Widget has functions And three Inputs (text title, text SubTitle, button with action 'OnPressed' it will change every Widget)

I need to duplicate this Widget 42 Times and every Widget has a different (title, subtitle, button) so how I can make a loop that duplicates the Widgets and Array to enter a specific (title, subtitle, button) to each Widget?

(more Explanation) array list Contains(title, subtitle, button), every time the loop creates a new Widget in the ViewList, the Widget Get's (title, subtitle, button) from the Arraylist.

I had done that before but not in flutter not even using dart so I'm a little bit confused

this picture explains what I need press here

2
  • Hi there. post more info as to what you have tried so far and what didn't work ? seems like you just need to traverse an array Commented Jun 9, 2021 at 2:51
  • I did everything about the Widget UI but I have two Options first copy paste 42 times or make a loop with an array that does that and saves me some space and time. Commented Jun 9, 2021 at 13:01

1 Answer 1

1

This uses a for loop to loop through a the lists of lists containing the information for your widgets, and add each element of the list to a text widget, you just have to make sure the elements of each list are the correct type that you have to pass to the widget.

@override
  Widget build(BuildContext context) {
    List lists = [
      ['title', 'subtitle', 'button'],
      ['title', 'subtitle', 'button'],
      ['title', 'subtitle', 'button'],
    ];

    return MaterialApp(
      title: MyApp._title,
      home: Scaffold(
          appBar: AppBar(title: const Text(MyApp._title)),
          body: SingleChildScrollView(
            child: Column(
              children: [
                for (var i in lists)
                  Card(
                    child: Column(
                      children: [
                        Text(i[0]),
                        Text(i[1]),
                        Text(i[2]),
                      ],
                    ),
                  )
              ],
            ),
          )),
    );
  }
}
Sign up to request clarification or add additional context in comments.

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.