Skip to main content

Command Palette

Search for a command to run...

Column Widget and Attributes.

Updated
3 min read
Column Widget and Attributes.
V

"Hello World, I'm Vinit Mepani, a coding virtuoso driven by passion, fueled by curiosity, and always poised to conquer challenges. Picture me as a digital explorer, navigating through the vast realms of code, forever in pursuit of innovation.

In the enchanting kingdom of algorithms and syntax, I wield my keyboard as a magical wand, casting spells of logic and crafting solutions to digital enigmas. With each line of code, I embark on an odyssey of learning, embracing the ever-evolving landscape of technology.

Eager to decode the secrets of the programming universe, I see challenges not as obstacles but as thrilling quests, opportunities to push boundaries and uncover new dimensions in the realm of possibilities.

In this symphony of zeros and ones, I am Vinit Mepani, a coder by passion, an adventurer in the digital wilderness, and a seeker of knowledge in the enchanting world of code. Join me on this quest, and let's create digital wonders together!"

Let's delve into the Column widget and provide more explanation along with a simple example.

The Column widget in Flutter is a layout widget that displays its children in a vertical sequence. It arranges its children from top to bottom. Each child can be any widget, and they will be drawn in the order they appear in the children property.

The Column widget in Flutter has several attributes (also known as properties) that you can use to customize its behavior and appearance. Here are some of the key attributes:

  1. children: A list of widgets to be displayed in the column, arranged in the order they appear in the list.

     Column(
       children: [
         Text('First Child'),
         Text('Second Child'),
         // More children...
       ],
     )
    
  2. mainAxisAlignment: Defines how the children should be placed along the main axis (vertically, in the case of a Column). Possible values include:

    • start: Align children at the top.

    • end: Align children at the bottom.

    • center: Center children in the middle.

    • spaceBetween: Space children evenly along the main axis with space between them.

    • spaceAround: Space children evenly along the main axis with space around them.

    • spaceEvenly: Space children evenly along the main axis with equal space on both ends.

    Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Text('Centered Child'),
        // More children...
      ],
    )
  1. crossAxisAlignment: Defines how the children should be placed along the cross axis (horizontally, in the case of a Column). Possible values include:

    • start: Align children at the start of the cross axis.

    • end: Align children at the end of the cross axis.

    • center: Center children along the cross axis.

    • stretch: Stretch children to fill the cross axis.

    Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        Text('Centered Child'),
        // More children...
      ],
    )
  1. mainAxisSize: Defines the size of the column along its main axis. Possible values are MainAxisSize.min (shrinks to fit its children) and MainAxisSize.max (takes up as much space as possible along the main axis).

     Column(
       mainAxisSize: MainAxisSize.max,
       children: [
         // Children...
       ],
     )
    
  2. verticalDirection: Defines the order in which the children are placed along the main axis. Possible values include VerticalDirection.down (top to bottom) and VerticalDirection.up (bottom to top).

     Column(
       verticalDirection: VerticalDirection.down,
       children: [
         // Children...
       ],
     )
    

These attributes allow you to control the layout and appearance of a Column widget. You can combine and customize them according to your UI design requirements.

Here's an example that demonstrates the use of Column with various widgets:

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Column Widget Example'),
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Text('First Child', style: TextStyle(fontSize: 20)),
            Container(
              color: Colors.blue,
              height: 50,
              width: 150,
              child: Center(child: Text('Second Child', style: TextStyle(color: Colors.white))),
            ),
            FlutterLogo(size: 100),
          ],
        ),
      ),
    );
  }
}

In this example:

  • The first child is a simple text widget.

  • The second child is a container with a blue background, containing centered text.

  • The third child is a Flutter logo.

You can customize the appearance and arrangement of your widgets within the Column according to your layout requirements. Feel free to experiment with different properties to achieve the desired visual result.

Learn Flutter

Part 1 of 50

Explore Flutter's magic in crafting cross-platform apps effortlessly. Join the adventure!

More from this blog

Vinit Mepani (Flutter Developer)

270 posts

"Vinit Mepani, passionate coder! Dive into my Dart and Flutter journey on the blog. Let's master these tech wonders together. Happy coding! 🚀"

Column Widget and Attributes.