목표

Flutter의 주요 위젯인 Text, Button, Row, Column을 알아보고 이를 활용하여 간단한 UI를 구성합니다.

1.1 소개

Flutter에서 UI는 위젯으로 구성됩니다. Text, Button, Row, Column은 Flutter의 가장 기본적인 위젯으로, UI를 배치하고 상호작용을 구현할 때 자주 사용됩니다. 이번에는 위젯들을 알아보고 간단한 레이아웃을 만들어 보겠습니다.

1.2 사전 준비

  • Flutter 개발 환경이 준비되어 있어야 합니다.
  • 이전 단계에서 만든 프로젝트(또는 새 프로젝트)를 열어야 합니다.

이전 단계를 진행하지 않았다면 아래 버튼을 눌러 이전 단계를 완료하세요.

1.2 핵심 내용

1단계: Text 위젯

Text 위젯은 화면에 텍스트를 출력합니다. 이전 단계에서 작성한 hello_flutter 또는 새로운 프로젝트를 생성한 후 다음과 같이 작성합니다.

결과:

  • 텍스트 내용: “Flutter는 재미있어요!” 문구가 출력.
  • 스타일: 폰트 크기 24, 텍스트 색상 파란색.

2단계: ElevatedButton 위젯

ElevatedButton은 클릭 가능한 버튼을 생성합니다. 다음과 같이 소스코드를 변경하여 어떻게 변화되는지 확인해 보세요.

결과:

  • 버튼 텍스트:”클릭하세요”.
  • 클릭 이벤트: 버튼을 클릭하면 “버튼 클릭됨”이 콘솔에 출력됩니다.

3단계: Row와 Column 위젯

Row는 가로 방향, Column 세로 방향 위젯을 배치합니다.

다음과 같이 소스코드를 수정해 보세요.

결과:

  • Row: “Row 1”, “Row 2”, “Row 3” 텍스트가 가로로 정렬.
  • Column: “Column text 1”, “Column text 2” 텍스트가 세로로 정렬.
  • 정렬 방식: mainAxisAlignment를 사용하여 정렬.

1.4 실습

1단계: Text 스타일 추가

  • Text 위젯에 폰트 굵기, 배경색, 글꼴 스타일을 추가해 보세요.

2단계: Row와 Column 혼합

  • Row 내부에 Column을 추가하여 복잡한 레이아웃을 만들어 보세요.

3단계: 버튼 클릭 이벤트

  • 버튼을 클릭하면 화면에 “Hello, World!”가 나타나도록 구현 해보세요.
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    String txt1 = 'Change Text 1';

    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(title: const Text('Row와 Column 위젯')),
          body: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              const Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                      style: TextStyle(fontSize: 30, color: Colors.blue),
                      'text 1  '),
                  Text(
                      style: TextStyle(fontSize: 30, color: Colors.red),
                      'text 2  '),
                  Text(
                      style: TextStyle(fontSize: 30, color: Colors.purple),
                      'text 3  '),
                ],
              ),
              const SizedBox(height: 20),
              Text(txt1),
              const Text('Column Text 2'),
              ElevatedButton(
                onPressed: () {
                  print('text');
                },
                child: const Text('Change Text'),
              ),
            ],
          )),
    );
  }
}

1.5 결론

이번에는 Flutter의 기본 위젯 Text, Button, Row, Column을 알아 보았습니다. 이를 조합하면 간단한 레이아웃을 쉽게 구성할 수 있습니다. 다음 단계에서는 Flutter의 상태 관리를 알아보며 동적 UI를 구현해 보겠습니다.

1.6 Q&A

Q:Row와 Column에 위젯을 어떻게 배치하나요?

A: children 속성세 추가할 위젯들을 리스트 형식으로 전달하면 됩니다.

Q: 버튼 클릭시 상태를 업데이트할 수 있나요?

A: StatefulWidget을 사용하면 버튼 클릭 이벤트를 통해 상태를 업대이트할 수 있습니다. 다음 강좌에서 다룹니다.

다음 단계에서는 *Flutter의 상태 관리(StatelessWidget & StatefulWidget)*에 대해 알아 보겠습니다.

감사합니다.


TechTinkerer's에서 더 알아보기

구독을 신청하면 최신 게시물을 이메일로 받아볼 수 있습니다.

댓글 남기기

  • Understanding Pointers and Memory Management in C++

    [Tutorial] · 2026-04-30 05:10 UTC Understanding Pointers and Memory Management in C++ 💡 TL;DR Mastering pointers in C++ is crucial for efficient memory management and writing effective code. 📚 Learning Objectives This tutorial covers the fundamentals of pointers in C++, including declaration, initialization, and memory management. Students will learn how to effectively use pointers to…

  • Building a Command-Line Calculator with C++

    [Tutorial] · 2026-04-30 04:08 UTC Building a Command-Line Calculator with C++ 💡 TL;DR Learn how to build a command-line calculator in C++ that takes user input and performs basic arithmetic operations. 📚 Learning Objectives This tutorial guides you through creating a basic command-line calculator in C++. You’ll learn how to take user input, perform arithmetic…

  • Mastering Python Data Structures for Efficient Coding

    [Tutorial] · 2026-04-30 03:05 UTC Mastering Python Data Structures for Efficient Coding 💡 TL;DR Learn about Python’s fundamental data structures – arrays, lists, tuples, and dictionaries – to write efficient and scalable code. 📚 Learning Objectives This tutorial covers the essential Python data structures – arrays, lists, tuples, and dictionaries. You’ll learn about their usage,…

  • Introduction to Object-Oriented Programming in Python

    [Tutorial] · 2026-04-30 02:02 UTC Introduction to Object-Oriented Programming in Python 💡 TL;DR Learn the fundamentals of object-oriented programming in Python, including classes and objects, inheritance, and polymorphism. 📚 Learning Objectives This tutorial introduces the basics of object-oriented programming in Python, covering classes, objects, inheritance, and polymorphism. By the end of this tutorial, beginners will…

  • Complete Guide to Python List Comprehensions

    [Tutorial] · 2026-04-30 01:00 UTC Complete Guide to Python List Comprehensions 💡 TL;DR Master Python list comprehensions to write concise and efficient code for data manipulation and transformation tasks. 📚 Learning Objectives This tutorial covers the basics of Python list comprehensions, including syntax, use cases, and execution results. You’ll learn how to write efficient and…

← 뒤로

응답해 주셔서 감사합니다. ✨

TechTinkerer's에서 더 알아보기

지금 구독하여 계속 읽고 전체 아카이브에 액세스하세요.

계속 읽기

TechTinkerer's에서 더 알아보기

지금 구독하여 계속 읽고 전체 아카이브에 액세스하세요.

계속 읽기