【发布时间】:2020-06-10 06:50:20
【问题描述】:
我是新来的颤振和尝试的东西。
我用 Center Widget 替换了 Scaffold Widget(只是胡闹)。所有文字都有一个黄色下划线,为了解决这个问题,我使用了TextDecoration
Text(
friend.name,
style: TextStyle(
decoration: TextDecoration.none
),
));
但这是所有 Text 小部件所必需的,因此我尝试通过在根 MaterialApp 中设置主题数据来为所有 Text 小部件通用设置它。
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Friends List',
theme: ThemeData(
primaryColor: Colors.black,
primarySwatch: Colors.teal,
primaryTextTheme: TextTheme(
headline1: TextStyle(color: Colors.green, decoration: TextDecoration.none),
headline2: TextStyle(color: Colors.green, decoration: TextDecoration.none),
headline3: TextStyle(color: Colors.green, decoration: TextDecoration.none),
headline4: TextStyle(color: Colors.green, decoration: TextDecoration.none),
headline5: TextStyle(color: Colors.green, decoration: TextDecoration.none),
headline6: TextStyle(color: Colors.green, decoration: TextDecoration.none),
bodyText1: TextStyle(color: Colors.green, decoration: TextDecoration.none),
bodyText2: TextStyle(color: Colors.green, decoration: TextDecoration.none),
),
textTheme: TextTheme(
headline1: TextStyle(decoration: TextDecoration.none),
headline2: TextStyle(decoration: TextDecoration.none),
headline3: TextStyle(decoration: TextDecoration.none),
headline4: TextStyle(decoration: TextDecoration.none),
headline5: TextStyle(decoration: TextDecoration.none),
headline6: TextStyle(decoration: TextDecoration.none),
bodyText1: TextStyle(decoration: TextDecoration.none),
bodyText2: TextStyle(decoration: TextDecoration.none)
),
),
home: MyHomePage(title: 'Friends list'),
);
}
}
但 Text 小部件仍然是下划线。我正在尝试的类似于在 css 中为标签设置样式,而不必每次都设置。
p
{
universal style here
}
我做错了吗?颤振中是否有类似的支持。如有不妥请指正
【问题讨论】:
-
也许这会对你的情况有所帮助:stackoverflow.com/q/47114639/4934409
-
你为什么不创建自己的 Text 类,我想它更容易
-
是的,这样会更容易。但我只是好奇flutter中是否存在这样的功能
-
那里的答案解决了我的问题@Scriptim,但我想要为每个文本小部件全局设置样式,而不必更改每个小部件。
标签: flutter flutter-widget flutter-theme