你能改变飘动文字的主题吗



如果主题在main.dart中设置为

return MaterialApp(
title: 'MY APP',
theme: ThemeData(
primarySwatch: Colors.blue,
fontFamily: 'Cabin',
textTheme: TextTheme(
headline1: TextStyle(
fontFamily: 'Raleway',
color: Colors.black,
fontWeight: FontWeight.w600,
fontSize: 18,
),
subtitle1: TextStyle(
fontFamily: 'Raleway',
color: Colors.black54,
fontWeight: FontWeight.w600,
fontSize: 16,
),
),
),

我用这个主题作为

Text('MY STRING',
style: Theme.of(context).textTheme.subtitle1),

如何使"我的字符串"的颜色与副标题1的主题颜色不同,同时保留主题数据的其他属性,如字体大小、系列等。?

您可以使用de方法copyWith(color: your_color)来更改TextTheme的属性。

示例:

Text('MY STRING',
style: Theme.of(context).textTheme.subtitle1
.copyWith(color: Colors.red),
)

文件参考:https://api.flutter.dev/flutter/material/TextTheme/copyWith.html

最新更新