by @kodeazy

Flutter How to create list of widgets inside coulmn widget?

Home » flutter » Flutter How to create list of widgets inside coulmn widget?

In this blog we will discuss on how to create list of widgets inside coulmn widget.

What is List?

  • List is similar to Arrays in different programming languages like Java,C,C++.
  • In flutter list stores widgets orelements of similar type.
  • Below is an example of creating a List of Container type of Widgets.

    List<Container> containerList =[
    Container(
      color: Colors.green,
      width: 100.0,
      height: 100.0,
      margin: const EdgeInsets.only(top: 20.0,bottom: 20.0),
    ),
    Container(
      color: Colors.red,
      width: 100.0,
      height: 100.0,
      margin: const EdgeInsets.only(top: 20.0,bottom: 20.0),
    ),
    
    ];

    Below is an example of creating and adding List of widgets inside coulmn widget.

    import 'dart:core';
    import 'package:flutter/material.dart';
    void main() {
    runApp(MaterialApp(
    home: WidgExample(),
    ));
    }
    class WidgExample extends StatelessWidget {
    WidgExample({Key? key}) : super(key: key);
    List<Container> containerList =[
    Container(
      color: Colors.green,
      width: 100.0,
      height: 100.0,
      margin: const EdgeInsets.only(top: 20.0,bottom: 20.0),
    ),
    Container(
      color: Colors.red,
      width: 100.0,
      height: 100.0,
      margin: const EdgeInsets.only(top: 20.0,bottom: 20.0),
    ),
    ];
    @override
    Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: containerList,
      ),
    );
    }
    }

    Output: Image