[flutter] 플러터 RichText 활용 예시

텍스트 스타일을 다양하게 적용할 수 있는 RichText 위젯플러터(Flutter) 앱에서 텍스트를 다룰 때 유용하게 활용됩니다.

RichText 위젯을 사용하여 텍스트에 서로 다른 글꼴, 색상, 크기 등을 쉽게 적용할 수 있습니다. 아래는 RichText 위젯을 사용한 예시 코드입니다.

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: RichText(
            text: TextSpan(
              text: 'Hello ',
              style: TextStyle(
                color: Colors.black,
                fontSize: 20,
                fontWeight: FontWeight.bold,
                fontStyle: FontStyle.italic,
              ),
              children: <TextSpan>[
                TextSpan(
                  text: 'world',
                  style: TextStyle(
                    color: Colors.blue,
                    fontSize: 30,
                    fontWeight: FontWeight.normal,
                    fontStyle: FontStyle.normal,
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

위 코드는 “Hello”와 “world” 사이에 서로 다른 스타일을 적용한 RichText를 보여주는 간단한 예제입니다.

플러터 앱에서 다양한 텍스트 스타일을 쉽게 적용하고 싶을 때, RichText 위젯을 활용해보세요.

더 많은 정보는 플러터 공식 문서를 참고하세요.