flutter 입문 _ 텍스트 (Text, TextStyle, RichText, TextSpan)

한별onestar·2023년 7월 6일

flutter

목록 보기
4/17
post-thumbnail

Text()

기본 텍스트 입력

  • 활용
class Home extends StatelessWidget {
  // const Home({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Text('안녕 나는 한별'),
    );
  }
}
  • 결과



TextStyle()

텍스트 스타일 지정

  • 활용
class Home extends StatelessWidget {
  // const Home({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Text('안녕 나는 한별',
        style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold),
      ),
    );
  }
}
  • 결과



RichText()

여러개의 다른 스타일을 가진 문자를 화면에 그린다.
RichText는 DefaultTextStyle을 기본적으로 적용하지 않아 기본 스타일을 명시해야한다. (이게 대체 먼소리당가 ㅡㅡ)

  • 활용
class Home extends StatelessWidget {
  // const Home({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: RichText(
        text: TextSpan(
          text:'안녕하세요',
          style: DefaultTextStyle.of(context).style,
          children: <TextSpan>[
            TextSpan(text: '텍스트',style: TextStyle(fontWeight: FontWeight.bold, color: Colors.red)),
            TextSpan(text:'한별이예요')
          ]
        ),
      ),
    );
  }
}
  • 결과
profile
한별잉

0개의 댓글