[flutter] Text 위젯의 글씨 부분 스타일을 바꾸는 방법, 아이콘 넣기

곽준영·2023년 5월 9일
0

1. RichText 위젯 사용하기

RichText 위젯은 여러 개의 TextSpan 위젯을 포함할 수 있으므로 각각 다른 스타일과 텍스트를 가질 수 있습니다.

RichText(
  text: TextSpan(
    text: 'Hello ',
    style: TextStyle(color: Colors.black),
    children: [
      WidgetSpan(
        child: Icon(
          Icons.call,
          color: Colors.white,
          size: 18,
        ),
      ),
      TextSpan(
        text: 'World',
        style: TextStyle(
          color: Colors.red,
          fontWeight: FontWeight.bold,
        ),
      ),
    ],
  ),
)

2. Text.rich() 사용하기

Text.rich()는 RichText 위젯과 비슷하지만 더 간단하게 작성할 수 있습니다.

Text.rich(
  TextSpan(
    text: 'Hello ',
    style: TextStyle(color: Colors.black),
    children: [
      WidgetSpan(
        child: Icon(
          Icons.call,
          color: Colors.white,
          size: 18,
        ),
      ),
      TextSpan(
        text: 'World',
        style: TextStyle(
          color: Colors.red,
          fontWeight: FontWeight.bold,
        ),
      ),
    ],
  ),
)
profile
I want to become a versatile freelancer programmer💻

0개의 댓글