문제 설명
Flutter ThemeData가 텍스트에서 작동하지 않습니다 (Flutter ThemeData is not working for the Text)
코드:
6@override
Widget build(BuildContext context) {
return Theme(
data: ThemeData(textTheme: TextTheme(body1: TextStyle(fontSize: 40))),
child: Text("Hello World!"), // size not changing
);
}
하지만
6data: ThemeData(textTheme: TextTheme(body1: TextStyle(fontSize: 40))),
를 사용할 때 MaterialApp
의 테마
크기는 Text
가 변경됩니다.
추신: style:
속성을 사용하여 Text
에 크기를 줄 수 있다는 것을 알고 있지만 알고 싶습니다. 내 코드가 Text
글꼴 크기를 변경하지 않는 이유.
참조 솔루션
방법 1:
Text does not use Theme. Theme is material design specific, while Text is general purpose.
What Text uses is DefaultTextStyle, which is edited by MaterialApp
(or some other widgets such as AppBar
) with values from the Theme.
The following should work:
DefaultTextStyle(
style: TextStyle(fontSize: 40),
child: Text("Hello World"),
);
(by user6274128、Rémi Rousselet)