Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Layout System: Row, Column, Stack | Core UI Building
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Flutter App Foundations

bookLayout System: Row, Column, Stack

Note
Definition

Layout widgets are Flutter widgets that arrange their child widgets in a specific manner, controlling the position and size of each child within the parent.

When you want to lay out widgets horizontally, use the Row widget. The mainAxisAlignment property controls how the children are spaced along the main axis, which is horizontal for Row. You can align children to the start, end, center, or space them evenly.

main.dart

main.dart

copy
1234567891011121314151617
import 'package:flutter/material.dart'; void main() { runApp(MaterialApp( home: Scaffold( body: Center( child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Text('Hello'), Text('World'), ], ), ), ), )); }

To arrange widgets vertically, use the Column widget. The crossAxisAlignment property determines how children are aligned across the horizontal axis. For instance, you can align them to the start, end, or center of the column.

main.dart

main.dart

copy
123456789101112131415161718192021
import 'package:flutter/material.dart'; void main() { runApp(MaterialApp( home: Scaffold( body: Center( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text('First'), SizedBox(height: 20), Text('Second'), SizedBox(height: 20), Text('Third'), ], ), ), ), )); }

If you need to overlap widgets, the Stack widget is the right choice. Stack allows you to place widgets on top of each other and position them using the Positioned widget.

main.dart

main.dart

copy
12345678910111213141516171819202122232425
import 'package:flutter/material.dart'; void main() { runApp(MaterialApp( home: Scaffold( body: Center( child: Stack( children: [ Container(width: 100, height: 100, color: Colors.blue), Positioned( left: 20, top: 20, child: Container(width: 60, height: 60, color: Colors.red), ), Positioned( right: 10, bottom: 10, child: Text('Stacked'), ), ], ), ), ), )); }
question mark

Which layout widget would you use to overlap widgets in Flutter?

Select the correct answer

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 2

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Suggested prompts:

Can you give examples of when to use Row, Column, and Stack in a real app?

How do I choose between Row, Column, and Stack for my layout?

Can you explain more about mainAxisAlignment and crossAxisAlignment?

bookLayout System: Row, Column, Stack

Svep för att visa menyn

Note
Definition

Layout widgets are Flutter widgets that arrange their child widgets in a specific manner, controlling the position and size of each child within the parent.

When you want to lay out widgets horizontally, use the Row widget. The mainAxisAlignment property controls how the children are spaced along the main axis, which is horizontal for Row. You can align children to the start, end, center, or space them evenly.

main.dart

main.dart

copy
1234567891011121314151617
import 'package:flutter/material.dart'; void main() { runApp(MaterialApp( home: Scaffold( body: Center( child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Text('Hello'), Text('World'), ], ), ), ), )); }

To arrange widgets vertically, use the Column widget. The crossAxisAlignment property determines how children are aligned across the horizontal axis. For instance, you can align them to the start, end, or center of the column.

main.dart

main.dart

copy
123456789101112131415161718192021
import 'package:flutter/material.dart'; void main() { runApp(MaterialApp( home: Scaffold( body: Center( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text('First'), SizedBox(height: 20), Text('Second'), SizedBox(height: 20), Text('Third'), ], ), ), ), )); }

If you need to overlap widgets, the Stack widget is the right choice. Stack allows you to place widgets on top of each other and position them using the Positioned widget.

main.dart

main.dart

copy
12345678910111213141516171819202122232425
import 'package:flutter/material.dart'; void main() { runApp(MaterialApp( home: Scaffold( body: Center( child: Stack( children: [ Container(width: 100, height: 100, color: Colors.blue), Positioned( left: 20, top: 20, child: Container(width: 60, height: 60, color: Colors.red), ), Positioned( right: 10, bottom: 10, child: Text('Stacked'), ), ], ), ), ), )); }
question mark

Which layout widget would you use to overlap widgets in Flutter?

Select the correct answer

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 2
some-alt