加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

dart – Flutter ThemeData不适用于Text

发布时间:2020-12-14 14:49:57 所属栏目:百科 来源:网络整理
导读:码: @overrideWidget build(BuildContext context) { return Theme( data: ThemeData(textTheme: TextTheme(body1: TextStyle(fontSize: 40))),child: Text("Hello World!"),// size not changing );} 但是当我使用时 data: ThemeData(textTheme: TextTheme
码:

@override
Widget build(BuildContext context) {
  return Theme(
    data: ThemeData(textTheme: TextTheme(body1: TextStyle(fontSize: 40))),child: Text("Hello World!"),// size not changing
  );
}

但是当我使用时

data: ThemeData(textTheme: TextTheme(body1: TextStyle(fontSize: 40))),

在我的MaterialApp主题中,然后文本的大小发生了变化.

PS:我知道我可以通过使用style:property来给Text一个大小,但我想知道为什么我的代码没有改变文本字体大小.

解决方法

Text不使用 Theme. Theme是特定材料设计,而 Text是通用的.

Text使用的是DefaultTextStyle,它由MaterialApp(或其他一些小部件,如AppBar)编辑,其值来自Theme.

以下应该有效:

DefaultTextStyle(
  style: TextStyle(fontSize: 40),child: Text("Hello World"),);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读