我认为颤振的答案很好。但它的力量ThemeData远超你的想象。这是有关应用程序部分主题的官方文档。
您可以提供 aTheme来包装您的容器以提供新主题。这里有两种方法来slove它:
/*Not recommended, this could make a totally different If you just want a little part changed.*/
Theme(
// Create a unique theme with "ThemeData"
data: ThemeData(
textTheme: /* Your Text Theme*/,
),
child: Container(
onPressed: () {},
child: Text("Your Text Here"),
),
);
Run Code Online (Sandbox Code Playgroud)
Theme(
// Find and extend the parent theme using "copyWith". See the next
// section for more info on `Theme.of`.
data: Theme.of(context).copyWith(textTheme: /* Provide your theme here! */),
child: Container(
child: Text("your text here"),
),
);
Run Code Online (Sandbox Code Playgroud)
您也可以使用现有主题稍作更改:
Theme.of(context).textTheme.copyWith(
body1: Theme.of(context).textTheme.body1.copyWith(color: Colors.red),
)
Run Code Online (Sandbox Code Playgroud)
TextStyle仅将某些属性应用于应用程序的子树。您可以使用DefaultTextStyle
DefaultTextStyle(
child: Container(child: /* your subtree */),
style: TextStyle(color: Colors.red),
),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
431 次 |
| 最近记录: |