RichText
를 사용해 작업하던 중 같은 폰트, 같은 사이즈, 모든 옵션이 모두 같은데
WidgetSpan
내의 Text
와 TextSpan
의 Text
가 사이즈가 달라보이는 것을 확인했습니다
좌 widgetSpan
-Text
, 우 TextSpan
RichText(
text: TextSpan(
text: '',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w400,
fontFamily: 'NotoSans',
color: Colors.black,
),
children: [
WidgetSpan(
child: Text(
'안녕하세요',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w400,
fontFamily: 'NotoSans',
color: Colors.black,
),
),
),
TextSpan(
text: '안녕하세요',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w400,
fontFamily: 'NotoSans',
color: Colors.black,
),
),
],
),
)
이것은 Text
위젯의 size
가 절대적인 크기로 동일하게 들어가는 것이 아닌
기기의 폰트 크기에 영향을 받고 있어 생긴 문제입니다.
MaterialApp
의 builder
에서(없으면 추가) 기준 스케일이 변경되지 않도록 1로 고정시켜주면 됩니다.
MaterialApp{
...
builder: (context, child) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: child!);
},
}