Flutter ThemeData不适用于文本

编程入门 行业动态 更新时间:2024-10-26 00:28:41
本文介绍了Flutter ThemeData不适用于文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

代码:

@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 的主题中,然后文本已更改。

in my MaterialApp's theme then size of the Text gets changed.

PS :我知道我可以给 Text 通过使用 style:属性设置大小,但是我想知道为什么我的代码没有更改 Text 字体尺寸。

PS: I know I can give Text a size by using style: property but I wanna know why my code isn't changing Text font size.

推荐答案

文本不使用主题 。 主题是特定于材料设计的,而文本是通用的。

Text does not use Theme. Theme is material design specific, while Text is general purpose.

什么文本使用的是 DefaultTextStyle ,由 MaterialApp (或其他一些小部件,例如 AppBar ),其值来自主题。

What Text uses is DefaultTextStyle, which is edited by MaterialApp (or some other widgets such as AppBar) with values from the Theme.

以下应该起作用:

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

更多推荐

Flutter ThemeData不适用于文本

本文发布于:2023-11-27 05:07:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636723.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不适用于   文本   Flutter   ThemeData

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!