기본 레이아웃 위젯
Row, Column, Container 및 Stack과 같은 필수 레이아웃 위젯을 익혀 구조적이고 반응형인 사용자 인터페이스를 만듭니다.
기본 레이아웃 위젯은(는) CoddyKit의 무료 Flutter Mobile Development 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Flutter Mobile Development 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Flutter Mobile Development 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Why Layouts Matter
In Flutter, everything is a widget! To build complex and beautiful user interfaces, you need to arrange these widgets on the screen.
Layout widgets are special widgets designed to help you organize other widgets, defining their size, position, and how they interact with each other.
Meet the Container
The Container widget is one of the most versatile layout widgets. Think of it as a customizable box that can hold a single child widget.
You can use it to:
- Add padding or margins
- Set background colors or decorations
- Define specific width and height
- Transform its position or rotation
Simple Colored Box
Let's create a basic Container with a child Text widget. Notice how we set its color and padding.
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Container Demo')),
body: Center(
child: Container(
padding: const EdgeInsets.all(20.0),
color: Colors.blueAccent,
child: const Text(
'Hello from Container!',
style: TextStyle(color: Colors.white, fontSize: 18),
),
),
),
),
);
}
}Horizontal with Row
When you need to arrange multiple widgets side-by-side horizontally, the Row widget is your go-to. It takes a list of widgets as its children.
Row automatically tries to fit its children along the horizontal axis, and you can control their alignment within the row.
Row of Buttons
Here's how you can place three buttons next to each other using a Row. We'll add some spacing between them.
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Row Demo')),
body: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
ElevatedButton(onPressed: () {}, child: const Text('Button 1')),
ElevatedButton(onPressed: () {}, child: const Text('Button 2')),
ElevatedButton(onPressed: () {}, child: const Text('Button 3')),
],
),
),
),
);
}
}Vertical with Column
Just as Row arranges widgets horizontally, the Column widget arranges them vertically, one below the other.
It also takes a list of children and lets you control their vertical alignment.
Stacked Text Fields
Let's create a simple login-like form using a Column to stack two TextFields and a button vertically.
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Column Demo')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Padding(
padding: EdgeInsets.all(8.0),
child: TextField(
decoration: InputDecoration(labelText: 'Username'),
),
),
const Padding(
padding: EdgeInsets.all(8.0),
child: TextField(
obscureText: true,
decoration: InputDecoration(labelText: 'Password'),
),
),
ElevatedButton(onPressed: () {}, child: const Text('Login')),
],
),
),
),
);
}
}Aligning Children
Both Row and Column use two important properties for alignment:
mainAxisAlignment: How children are positioned along the primary axis (horizontal forRow, vertical forColumn). Examples:start,center,end,spaceAround.crossAxisAlignment: How children are positioned along the perpendicular axis (vertical forRow, horizontal forColumn). Examples:start,center,end,stretch.
These give you fine control over your layouts!
Overlapping with Stack
Sometimes you need to place widgets on top of each other, like text over an image. That's where the Stack widget comes in.
Stack allows you to layer multiple children widgets. You can control their exact position within the stack using the Positioned widget.
Image with Text Overlay
Let's put some text directly on top of an image using a Stack. We'll use Positioned to place the text precisely.
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Stack Demo')),
body: Center(
child: SizedBox(
width: 300,
height: 200,
child: Stack(
children: <Widget>[
Image.network(
'https://picsum.photos/300/200',
fit: BoxFit.cover,
),
const Positioned(
bottom: 10,
left: 10,
child: Text(
'Beautiful Scenery',
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold,
shadows: [
Shadow(blurRadius: 5, color: Colors.black)
],
),
),
),
],
),
),
),
),
);
}
}Layout Challenge
Which of the following widgets are primarily used for arranging multiple children widgets in a single direction (either horizontally or vertically)?
Layouts Mastered!
Great job! You've now mastered the fundamental layout widgets in Flutter:
Container: A versatile box for single children, offering padding, margin, color, and size control.Row: Arranges multiple children horizontally.Column: Arranges multiple children vertically.Stack: Layers children on top of each other, often used withPositioned.
Understanding these is key to building any Flutter UI!
자주 묻는 질문
“기본 레이아웃 위젯” 강의는 무료인가요?
네 — “기본 레이아웃 위젯” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Flutter Mobile Development 강의 전체를 잠금 해제할 수 있습니다. Flutter Mobile Development 강의에는 총 4개의 강의가 포함되어 있습니다.
“기본 레이아웃 위젯”에서 뭘 배우나요?
Row, Column, Container 및 Stack과 같은 필수 레이아웃 위젯을 익혀 구조적이고 반응형인 사용자 인터페이스를 만듭니다. 브라우저에서 직접 실행하는 실습 코드로 Flutter Mobile Development을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Flutter Mobile Development을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Flutter Mobile Development은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.
“기본 레이아웃 위젯” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Flutter Mobile Development 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Flutter Mobile Development 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.