Flutter Row and Column | Complete guide Row and Column in Flutter

Flutter

Row vs Column in Flutter

Flutter Tutorial

Introduction

Flutter

Cross Platform

MVVM vs MVC vs MVP

Flutter Framework

Flutter Benefits

Flutter Comparison

Install Flutter in Win/Linux/Mac

Android Studio vs VsCode

Android Setup

VS Code Setup

VS Code Plugins

Android Studio Plugins

Flutter Widgets:

Flutter Basic Template

Flutter Commands

Top 10 Popular widgets

Flutter Stateless vs Stateful

Type of Widgets

Flutter Text widget

Flutter Text style

Textfield vs TextFormField

Flutter Scaffold

Flutter Container & SizedBox

Flutter Row & Column

Flutter Buttons

Flutter Stack

Flutter Forms

Flutter AlertDialog

Flutter Icons

Flutter Images

Flutter Drawer

Flutter ListView

Flutter GridView

Flutter Toast

Flutter Checkbox

Flutter Radio Button

Flutter Progress Bar

Flutter Tooltip

Flutter Slider

Flutter Table

Flutter SnackBar

Shimmer in Flutter

Bottom Navigation Bar in Flutter

Gesture Detector in Flutter

Error Handling in Flutter

DropDown in Flutter

Flutter Toggle

Auto Close Keyboard in Flutter

Screen size handling in Flutter

Flutter REST API

Flutter http

Flutter dio

dio vs http

Flutter Advance

Custom widget in Flutter

Flutter Navigator

Read Json in Flutter

Generate Excel in Flutter

Multiple Widgets in Flutter

Bottom sheet in Flutter

Copy to Clipboard in Flutter

Tab bar in Flutter

Code Editor in Flutter

Youtube Player in Flutter

Flutter App Development Tips

Flutter App version Update

Flutter Copy Text in App

Flutter Handle Null Value

Flutter Splash Screen

Flutter Disposable

Notification Listener

Flutter Switch Cases

Flutter Slivers

Flutter Custom App bar

Databinding in Flutter

Flutter Cards

Wrap vs Builder vs OverBarFlow

Flutter App Upgrade

GoogleMap vs FlutterMap

Circular progress contain Icon

DropDown Timer in Flutter

Flutter State management Comparison

Flutter vs Other Framework

Flutter Mixin

Passing values in Dart Files

WorkManager in Flutter

Flutter Database

Flutter Store Data

Suitable DB for Flutter

Backend for Flutter

SharedPreferences in Flutter

Flutter Token Expired Handling

Flutter Provider

Flutter Provider Tutorial

Flutter GetX

Flutter GetX tutorial

Flutter with Native

Flutter FFI

Flutter Testing

Flutter Tips

Best Practices

Reduce Flutter Screens

Tips to make app smart

Optimize App

Handle Multiple Pages

Interview Questions

Flutter 100 Interview Questions

Provider Interview Questions

GetX Interview Questions

BLoC Interview Questions

Row widget in Flutter

In Flutter, Row and Column are two important layout widgets that allow you to arrange child widgets(Other widgets like Text, Elevated Button, Row/Column), horizontally (Row) or vertically (Column) and both are play a major role in UI of Flutter applications

Row

  • Row is a widget that arranges its children(widgets) horizontally in a horizontal line.
  • In Row mainAxisAlignment and crossAxisAlignment to control how the children are aligned and positioned within the Row.
  • Here’s an example of using Row:
Row(

  mainAxisAlignment: MainAxisAlignment.spaceBetween, //you can use [spaceEvenly //center //start ] based on UI requirements

  children: [

    Text('Widget 1'),

    Text('Widget 2'),

    Text('Widget 3'),

  ],

)

Column

  • Column is a widget that arranges its children vertically in a vertical line.
  • In Cloumn height of the children exceeds the available height, you can use properties like mainAxisAlignment and crossAxisAlignment to control how the children are aligned and positioned within the Column.
Column(

  mainAxisAlignment: MainAxisAlignment.center,//you can use [spaceEvenly //center //start ] based on UI requirements

  children: [

    Text('Widget 1'),

    Text('Widget 2'),

    Text('Widget 3'),

  ],

)

This example creates a Column with three Text widgets, and the mainAxisAlignment is set to MainAxisAlignment.center, which vertically centers the children within the Column.

Both Row and Column can contain any widget as their children, allowing you to create complex layouts by combining multiple rows and columns.

mainAxisAlignment | crossAxisAlignment

In Flutter mainAxisAlignment | crossAxisAlignment in Row and Column play a major roles , below example clearly explain there functionality

//ROW CODE 

import 'package:flutter/material.dart';

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.appBartitle});


  final String appBartitle;
  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  // int _counter = 0;
bool enable=false;
  // void _incrementCounter() {
  //   setState(() {
  //     _counter++;
  //   });
  // }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          appBartitle: Text('Row Example by ResearchThinker'),
        ),
        body: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              // MainAxisAlignment.start & CrossAxisAlignment.start
              Row(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text('Start 1'),
                  Text('Start 2'),
                  Text('Start 3'),
                ],
              ),
              SizedBox(height: 20),
              // MainAxisAlignment.center & CrossAxisAlignment.center
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Text('Center 1'),
                  Text('Center 2'),
                  Text('Center 3'),
                ],
              ),
              SizedBox(height: 20),
              // MainAxisAlignment.end & CrossAxisAlignment.end
              Row(
                mainAxisAlignment: MainAxisAlignment.end,
                crossAxisAlignment: CrossAxisAlignment.end,
                children: [
                  Text('End 1'),
                  Text('End 2'),
                  Text('End 3'),
                ],
              ),
              SizedBox(height: 20),
              // MainAxisAlignment.spaceBetween & CrossAxisAlignment.stretch
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: [
                  Text('SpaceBetween 1'),
                  Text('SpaceBetween 2'),
                  Text('SpaceBetween 3'),
                ],
              ),
              SizedBox(height: 20),
              // MainAxisAlignment.spaceAround & CrossAxisAlignment.center
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Text('SpaceAround 1'),
                  Text('SpaceAround 2'),
                  Text('SpaceAround 3'),
                ],
              ),
              SizedBox(height: 20),
              // MainAxisAlignment.spaceEvenly & CrossAxisAlignment.end
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                crossAxisAlignment: CrossAxisAlignment.end,
                children: [
                  Text('SpaceEvenly 1'),
                  Text('SpaceEvenly 2'),
                  Text('SpaceEvenly 3'),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Column widget in Flutter
//COLUMN CODE

import 'package:flutter/material.dart';
// In this example we use all possible cases if you run you will see that how  CrossAxisAlignment.[please check below bold content] looks different
class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.appBartitle});


  final String appBartitle;
  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  // int _counter = 0;
bool enable=false;
  // void _incrementCounter() {
  //   setState(() {
  //     _counter++;
  //   });
  // }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          appBartitle: Text('Column Example by ResearchThinker'),
        ),
        body: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              // MainAxisAlignment.start & CrossAxisAlignment.start
              Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
// Here in this you can add your widgets
// In this we use Text to explain how CrossAxisAlignment.start work
                  Text('Start 1'),
                  Text('Start 2'),
                  Text('Start 3'),
                ],
              ),
              SizedBox(width: 20),
              // MainAxisAlignment.center & CrossAxisAlignment.center
              Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
// Here in this you can add your widgets
// In this we use Text to explain how CrossAxisAlignment.center work
                  Text('Center 1'),
                  Text('Center 2'),
                  Text('Center 3'),
                ],
              ),
              SizedBox(width: 20),
              // MainAxisAlignment.end & CrossAxisAlignment.end
              Column(
                mainAxisAlignment: MainAxisAlignment.end,
                crossAxisAlignment: CrossAxisAlignment.end,
                children: [
// Here in this you can add your widgets
// In this we use Text to explain how CrossAxisAlignment.start end
                  Text('End 1'),
                  Text('End 2'),
                  Text('End 3'),
                ],
              ),
              SizedBox(width: 20),
              // MainAxisAlignment.spaceBetween & CrossAxisAlignment.stretch
              Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: [
// Here in this you can add your widgets
// In this we use Text to explain how CrossAxisAlignment.strech work
                  Text('SpaceBetween 1'),
                  Text('SpaceBetween 2'),
                  Text('SpaceBetween 3'),
                ],
              ),
              SizedBox(width: 20),
              // MainAxisAlignment.spaceAround & CrossAxisAlignment.center
              Column(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
// Here in this you can add your widgets
// In this we use Text to explain how CrossAxisAlignment.center work
                  Text('SpaceAround 1'),
                  Text('SpaceAround 2'),
                  Text('SpaceAround 3'),
                ],
              ),
              SizedBox(width: 20),
              // MainAxisAlignment.spaceEvenly & CrossAxisAlignment.end
              Column(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                crossAxisAlignment: CrossAxisAlignment.end,
                children: [
// Here in this you can add your widgets
// In this we use Text to explain how CrossAxisAlignment.end work
                  Text('SpaceEvenly 1'),
                  Text('SpaceEvenly 2'),
                  Text('SpaceEvenly 3'),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

In this way, you can use Row and Column in Flutter. You should also remember how Column and Row work in Flutter to ensure they function correctly according to the intended direction.


Leave a Reply

Your email address will not be published. Required fields are marked *

web_horizontal
About Us Disclaimer Privacy Policy Terms & Conditions Contact Us

Copyright © 2023 ResearchThinker.com. All rights reserved.