텍스트 끝에 Widget을 넣는 방법

sumong·2023년 6월 20일
0

참고


RichText 안에 WidgetSpan을 넣어주면 됩니다!

예시)

RichText(
  textAlign: TextAlign.start,
  text: TextSpan(
    children: [
      const TextSpan(
        text: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum ',
        style: TextStyle(
          fontSize: 12,
          color: Colors.white,
        ),
      ),
      WidgetSpan(
        child: GestureDetector(
          onTap: () {},
          child: Container(
            padding: const EdgeInsets.all(8),
            color: Colors.blueAccent,
            child: const Text('Click'),
          ),
        ),
      ),
    ],
  ),
)

위 코드의 경우 아래처럼 나옵니다. 버튼이 텍스트 맨 끝에 붙게 됩니다. (배경색은 부모 위젯에서 지정한 것이니 신경쓰지 않으셔도 됩니다.)

profile
Flutter 메인의 풀스택 개발자 / 한양대 컴퓨터소프트웨어학과, HUHS의 화석

0개의 댓글