목표

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에서 더 알아보기

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

댓글 남기기

  • Build Your First Website from Scratch using HTML & CSS

    Hello, World! This is my first website.

  • Building a Simple Web Page: HTML & CSS Fundamentals

    Welcome to My Website This is a basic web page example.

  • Introduction to Data Science Concepts in C++

    [Tutorial] · 2026-01-13 23:41 UTC Introduction to Data Science Concepts in C++ 💡 TL;DR Explore fundamental data science concepts like arrays, strings, and basic math functions in C++, opening doors to practical data manipulation tasks. 📚 Learning Objectives This tutorial provides an introduction to key data science concepts in C++, including arrays, strings, and mathematical…

  • Building a Simple Game in C++: Beginner’s Guide to Object Oriented Programming and Graphic Design

    [Tutorial] · 2026-01-13 23:20 UTC Building a Simple Game in C++: Beginner’s Guide to Object Oriented Programming and Graphic Design 💡 TL;DR Learn how to create basic games using C++ by exploring object-oriented programming and drawing on the screen! 📚 Learning Objectives This tutorial will introduce beginners to game development using C++, covering basic programming…

  • Unveiling C++’s Power for Data Science

    [Tutorial] · 2026-01-13 08:25 UTC Unveiling C++’s Power for Data Science 💡 TL;DR Discover how to manipulate data efficiently using C++’s array, string, and math features for impactful data-driven solutions. 📚 Learning Objectives This tutorial introduces fundamental C++ concepts crucial for data science applications, focusing on arrays, strings, and mathematical functions. 🎯 Key Concepts Arrays…

← 뒤로

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

TechTinkerer's에서 더 알아보기

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

계속 읽기

TechTinkerer's에서 더 알아보기

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

계속 읽기