Flutter Row – Expanded Children

Flutter Row – Expanded Children

You can make the children of Row widget, expand to the available horizontal space. All you need to do is, wrap each child of Row widget around Expanded widget.

Example: Expanded Children in Row Widget

In the following example, we have taken three children for Row widget and each of them is wrapped with Expanded widget.

main.dart

import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    home: MyApp(),
  ));
}

class MyApp extends StatefulWidget {
  @override
  _State createState() => _State();
}

class _State extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Flutter Tutorial - googleflutter.com'),
      ),
      body: Row(
        children: <Widget>[
          Expanded(
            child: Icon(
              Icons.access_alarm,
              size: 80,
            ),
          ),
          Expanded(
            child: Icon(
              Icons.account_circle,
              size: 80,
            ),
          ),
          Expanded(
            child: Icon(
              Icons.save,
              size: 80,
            ),
          ),
        ],
      ),
    );
  }
}

Screenshot

Flutter Row - Expanded Children

Example 2: Some Expanded Children in Row Widget

Let us take four children and keep only two of them wrapped with Expanded widget.

main.dart

import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    home: MyApp(),
  ));
}

class MyApp extends StatefulWidget {
  @override
  _State createState() => _State();
}

class _State extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Flutter Tutorial - googleflutter.com'),
      ),
      body: Row(
        children: <Widget>[
          Icon(
            Icons.access_alarm,
            size: 60,
          ),
          Icon(
            Icons.account_circle,
            size: 60,
          ),
          Expanded(
            child: Icon(
              Icons.save,
              size: 60,
            ),
          ),
          Expanded(
            child: Icon(
              Icons.volume_up,
              size: 60,
            ),
          ),
        ],
      ),
    );
  }
}

Screenshot

Some Expanded Children in Row Widget

Summary

In this Flutter Tutorial, we learned how to make the children of Row widget occupy equal space in a row, using Expanded widget, with the help of well detailed example Flutter Application.

Desclaimer: We are not affiliated, associated, authorized, endorsed by, or in any way officially connected with the Google, Apple or Flutter, or any of its subsidiaries or its affiliates. The names Google, Apple and Flutter as well as related names, marks, emblems and images are registered trademarks of their respective owners. This site googleflutter.com covers tutorials related to Flutter developed by Google.