👉 거의 모든 앱에서 사용됨 (제목, 내용, 버튼 등)
Text("Hello Flutter")
👉 화면에 "Hello Flutter" 출력
Text(
"Hello Flutter",
style: TextStyle(
fontSize: 20,
color: Colors.blue,
fontWeight: FontWeight.bold,
),
)
| 속성 | 설명 |
|---|---|
| fontSize | 글자 크기 |
| color | 글자 색 |
| fontWeight | 굵기 |
| fontStyle | italic 등 |
| letterSpacing | 글자 간격 |
| height | 줄 간격 |
Text(
"가운데 정렬 텍스트",
textAlign: TextAlign.center,
)
Text(
"엄청 긴 텍스트를 한 줄로 줄이고 싶을 때...",
maxLines: 1,
overflow: TextOverflow.ellipsis,
)
👉 결과:
"엄청 긴 텍스트..." → "엄청 긴 텍..."
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
Widget build(BuildContext context) {
return const MaterialApp(
home: TextExample(),
);
}
}
class TextExample extends StatelessWidget {
const TextExample({super.key});
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Text Example")),
body: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"상품 제목",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 10),
Text(
"가격: 10,000원",
style: TextStyle(
color: Colors.grey,
),
),
SizedBox(height: 10),
Text(
"이것은 상품 설명입니다. 길어지면 자동으로 줄바꿈이 됩니다.",
),
],
),
),
);
}
}
👉 여러 스타일 혼합
RichText(
text: TextSpan(
text: "Hello ",
style: TextStyle(color: Colors.black),
children: [
TextSpan(
text: "Flutter",
style: TextStyle(color: Colors.blue, fontWeight: FontWeight.bold),
),
],
),
)
| 기능 | 방법 |
|---|---|
| 텍스트 표시 | Text() |
| 스타일 | TextStyle |
| 정렬 | textAlign |
| 줄 제한 | maxLines |
| 말줄임 | overflow |
👉 Text + TextStyle = 모든 텍스트 UI의 기본
overflow 꼭 처리