Flutter Widgets: Text, Button, Row & Column

Building a Flutter screen means choosing what to show and how to arrange it. Flutter widgets describe parts of an interface and let you place them in a layout.

This article explains what a widget is, then walks through assembling a screen with text and a button arranged in either direction.

TL;DR

Text displays a string, and ElevatedButton provides an action. Row places widgets horizontally while Column places them vertically.

  • Use Text to show a string and TextStyle to change its appearance.
  • Use ElevatedButton for an action with a visible Material surface.
  • Choose Row for a horizontal group and Column for a vertical group.

What Is a Flutter Widget?

A widget is an immutable description of part of a user interface. Flutter combines widgets into a tree, so a page can use a Column for its overall structure, then place a Text widget and a button inside it. Identifying each role first helps because the parent-child tree determines how much space a child can use.

A widget describes what Flutter should build at a position in the tree. The parent determines the constraints that its child receives, which is why a Text child inside a Row can behave differently from the same Text inside a Column.

Scaffold provides the page body in this example, while Padding adds space around the content. SizedBox separates the heading from the row. These surrounding widgets set the screen context.

WidgetRoleUse in this screen
TextDisplays a string with inherited or local styleShows the heading and task count
ElevatedButtonProvides a Material actionIncreases the count when pressed
RowPlaces children along a horizontal main axisKeeps status and action together
ColumnPlaces children along a vertical main axisStacks the heading and status row

A parent widget sets the space its child can use. Padding reduces the space inside its outer bounds, while Expanded shares the remaining width in a Row. That parent-child relationship explains why layout choices affect where text wraps.

How to Use Text, Buttons, Row, and Column

Build one small screen from a heading, a short status line, and a button. The outer Column stacks the heading above a Row, while the Row keeps the status and action on one line.

Step 1: Display text with Text

Text takes the string it should display. Its optional style uses TextStyle, while an omitted style inherits the nearest DefaultTextStyle. In the sample, the heading sets its size and weight and the status line uses the surrounding default.

The title’s TextStyle changes its size and weight without changing the status line. Decide whether a long label should wrap or be shortened before adding a line limit. Use a local style for one heading and the app theme when the treatment should repeat across screens.

Text can wrap across lines as its width changes, which lets the same widget work in a wider desktop window or a narrow phone layout. Avoid setting a fixed width only to make one short sample fit. If a label must stay on one line, choose a visible overflow treatment so readers can tell that content was shortened.

Step 2: Add an action with ElevatedButton

ElevatedButton requires a child for its label and an onPressed callback for activation. The callback below updates the status count, so the button has a visible effect. A null onPressed disables the button.

ButtonAppearance and use
ElevatedButtonFilled surface with elevation when pressed. Use for a primary action that needs a clear shape.
TextButtonNo visible border or fill by default. Use where nearby content makes the action clear.
FilledButtonFilled Material 3 option without the elevation effect of ElevatedButton.

Use styleFrom for a few local color or padding changes. ButtonStyle supports state-dependent properties. Use the app theme when several screens need the same button treatment.

The button’s child can be Text or an icon-and-label combination. Keep its label short enough for the available width. In a Row, give a long status string Expanded or Flexible so it wraps while the button uses its natural width.

The onPressed callback performs the action, and setting it to null disables the button. This screen uses StatefulWidget because the count changes. Its State object holds that value, and calling setState tells Flutter to rebuild the Text with the updated count after each press.

Step 3: Arrange children with Row and Column

Row lays out children along the horizontal main axis. Column uses the vertical main axis.

The sample uses Column for the screen and a Row for the status and button. Replace the inner Row with a Column when those two elements should stack.

PropertyIn a RowIn a Column
Main axisHorizontalVertical
Cross axisVerticalHorizontal
mainAxisAlignmentPositions children across the rowPositions children down the column
crossAxisAlignmentAligns children verticallyAligns children horizontally

Choose the direction first, then set the alignments. Here, start alignment keeps the heading and status at the leading edge. Use SizedBox for fixed space between children, or spaceBetween when they should spread across the main axis.

MainAxisSize.min lets the outer Column use its children’s height when parent constraints allow. Expanded fills its assigned share of remaining space, while Flexible can use less. Choose Row for side-by-side content or Column for a vertical order, and use either flex widget only with finite constraints.

Row first measures its non-flexible children at their natural width. Expanded then divides the width left over among flexible children. That is why wrapping the status text in Expanded changes the layout, while adding another alignment setting alone cannot make an oversized label fit.

Step 4: Assemble the screen

Save this as the main Dart file in a Flutter project. The Expanded child lets the status text use the width left after the button is laid out.

import 'package:flutter/material.dart';

void main() {
  runApp(const MaterialApp(home: WidgetExample()));
}

class WidgetExample extends StatefulWidget {
  const WidgetExample({super.key});

  @override
  State<WidgetExample> createState() => _WidgetExampleState();
}

class _WidgetExampleState extends State<WidgetExample> {
  int completed = 3;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Padding(
        padding: const EdgeInsets.all(24),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisSize: MainAxisSize.min,
          children: [
            const Text(
              'Daily progress',
              style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
            ),
            const SizedBox(height: 12),
            Row(
              children: [
                Expanded(child: Text('$completed tasks complete')),
                ElevatedButton(
                  onPressed: () => setState(() => completed++),
                  child: const Text('Add one'),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

Step 5: Verify the button and layout

Save these checks as test/widget_test.dart. The first sets a 280-pixel viewport, and the second taps the button and checks the updated count.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:widget_demo/main.dart';

void main() {
  testWidgets('keeps the status and action inside a narrow viewport', (tester) async {
    tester.view.physicalSize = const Size(280, 600);
    tester.view.devicePixelRatio = 1;
    addTearDown(tester.view.resetPhysicalSize);
    addTearDown(tester.view.resetDevicePixelRatio);

    await tester.pumpWidget(const MaterialApp(home: WidgetExample()));
    expect(find.text('3 tasks complete'), findsOneWidget);
    expect(find.text('Add one'), findsOneWidget);
    expect(tester.takeException(), isNull);
  });

  testWidgets('shows progress and responds to the action', (tester) async {
    await tester.pumpWidget(const MaterialApp(home: WidgetExample()));
    expect(find.text('Daily progress'), findsOneWidget);
    expect(find.text('3 tasks complete'), findsOneWidget);
    await tester.tap(find.text('Add one'));
    await tester.pump();
    expect(find.text('4 tasks complete'), findsOneWidget);
  });
}

The widget tests verify that tapping Add one changes the count, that the status and action fit at a 280-pixel viewport, and that Flutter reports no exception. Both tests passed with Flutter 3.47.9. The image below shows terminal output, not the rendered app UI.

flutter test test/widget_test.dart --reporter expanded
00:00 +0: keeps the status and action inside a narrow viewport
00:00 +1: shows progress and responds to the action
00:01 +2: All tests passed!
Terminal showing two passing Flutter widget tests
The tests confirm the action updates the count and the row fits at a narrow width.

Common Row and Column Layout Issues

Row and Column arrange children along one axis, so check the parent’s width and height first because overflow occurs when children need more space than it provides.

SymptomCauseNext step
Yellow and black stripe at the edge of a RowNon-flexible children need more width than the Row hasWrap the text in Expanded or Flexible
Bottom overflow in a ColumnIts children are taller than the available spaceUse a scrolling widget such as ListView
Expanded throws an unbounded constraint errorThe Column has no finite remaining height to divideRemove Expanded in a scrolling parent or give the Column bounded height
A long button label crowds nearby textBoth children need more width than the Row providesUse Flexible for the text or stack the controls in a Column
Several short items should continue on a new lineRow keeps every child on one lineUse Wrap, which places later children in another run

Flutter’s Row documentation describes horizontal arrangement, while the Column documentation covers vertical placement. Check these constraints before choosing a layout because the right fix depends on the space the parent can provide.

Expanded divides remaining space only when its flex parent has a finite constraint. A SingleChildScrollView gives its child unbounded space in the scrolling direction, so it cannot provide a finite height for a Column’s Expanded child.

SituationLayout choiceReason
A short page may extend beyond a phone screenSingleChildScrollViewIt lets the single child scroll when the full page does not fit.
A long list extends beyond the viewportListViewIt is designed for a scrollable sequence of items.
Several short children should flow onto another lineWrapIt starts another run when children no longer fit together.

A short English label can grow after translation or when system text is enlarged. Test the longest supported copy and the narrowest viewport. Put the action below the status if the two no longer fit together.

For a single long string, Expanded or Flexible gives Text a bounded share of the Row’s width. Use Column when the action should follow the text in a clear vertical order.

Conclusion: Choose Layout by Direction

Use Text for visible words and a button for an action. Choose Row when the status and action should stay on one line. Use Column when they need a vertical reading order or less horizontal space.

Add Expanded when text needs to share limited Row width, and use ListView when vertical content must scroll.

Start with widget roles: use Text for content, an action widget for interaction, and choose Row or Column based on whether items should read side-by-side or vertically. Give long text a share of available width with Expanded or Flexible so the parent can measure it and wrap within its constraints. Match scrolling to content: SingleChildScrollView suits a short page, while ListView fits a long sequence and ListView.builder creates visible children on demand as they scroll into view.

Next questionReference
Which widgets fit a task?Flutter widget catalog
How does a flex child behave?Flexible API and Expanded API
How can a small screen scroll?SingleChildScrollView API
How are long lists built on demand?ListView.builder API
What can the button open?CodeForGeek Flutter dialogs guide
How does this fit in an app?CodeForGeek Flutter getting-started guide

FAQ

These answers cover the layout choices in the example.

What is the difference between Row and Column in Flutter?

Row arranges children horizontally. Column arranges children vertically.

How do I prevent text overflow in a Flutter Row?

Wrap the flexible text child in Expanded or Flexible so it receives a bounded share of the remaining width.

Can a Flutter Column scroll?

No. Use a scrolling widget such as ListView when the content must move beyond the available viewport.

Sushant Dhiman
Sushant Dhiman

Sushant Dhiman writes beginner-friendly Flutter and Dart tutorials covering widgets, layouts, navigation, dialogs, and state. He also covers Node.js, Express, and jQuery fundamentals.

Articles: 14