title: How to loop list variable in flutter
body: <p>I'm trying to apply random colors to the list view generated widgets in flutter.
  here is the example.</p>
  <p>this is a list view generated list , and different colors on each widget.</p>
  <p><a href="https://i.stack.imgur.com/8NzlBm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8NzlBm.png" alt="enter image description here" /></a></p>
  <p>here is how I did that</p>
  <pre><code>ListView.separated(
                physics: const BouncingScrollPhysics(),
                shrinkWrap: true,
                itemCount: docList.length,
                scrollDirection: Axis.horizontal,
                itemBuilder: (BuildContext context, int index) {
                  final data = docList[index];
                  return Row(
                    children: [
                      DocLIstCard(
  // here is the color list to apply different colors to each of the generated widget.
                        backgroundColor: AppColors.gradientIndex[index], 
                        category: data.sectionName,
                        docImage: data.image,
                        docName: data.name,
                      ),
                    ],
                  );
                },
                separatorBuilder: (BuildContext context, int index) {
                  return const SizedBox(width: 20);
                },
              ),
  </code></pre>
  <p>and here is the <code>AppColors.gradientIndex[index]</code>'s variable</p>
  <pre><code> static const gradientIndex = [
      LinearGradient(
        begin: Alignment.topLeft,
        end: Alignment.bottomRight,
        colors: [Color(0xFF111A8A), Color(0xFFB1008A)],
      ),
      LinearGradient(
        begin: Alignment.topLeft,
        end: Alignment.bottomRight,
        colors: [Color(0xFFE97000), Color(0xFFB1008A)],
      ),
      LinearGradient(
        begin: Alignment.topLeft,
        end: Alignment.bottomRight,
        colors: [Color(0xFF111A8A), Color(0xFFB1008A)],
      ),
      LinearGradient(
        begin: Alignment.topLeft,
        end: Alignment.bottomRight,
        colors: [Color(0xFFE97000), Color(0xFFB1008A)],
      ),
    ];
  </code></pre>
  <p>if there are 1000 of widgets, I've to write the colors list 1000 times, so how can I loop this???</p>