Flutter

[Flutter, 토이 프로젝트] 위젯 안의 요소의 TextStyle 한번에 지정 - DefaultTextStyle

hminor 2023. 8. 30. 22:40

 

목적

  • Container() 위젯에 있는 여러 요소들의 TextStyle을 한번에 지정하고 싶음.
  • Text() 위젯 하나하나에 지정하기 너무 귀찮으니깐...

코드

  • DefaultTextStyle() 위젯의 style을 사용해 한번에 적용하기
  • 개꿀
  • 물론 Theme 파일로 한번에 지정할 수 도 있을 듯?

 

Container(
    margin: EdgeInsets.fromLTRB(10, 0, 0, 0),
    child: DefaultTextStyle( // <--- 요고!
      style: TextStyle(
        color: Colors.black45,
        fontWeight: FontWeight.w700
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              요소()
            ],
          ),
          Row(
            children: [
              요소()
            ],
          )
        ],
      ),
    )
  )