您可以为您的应用尝试 2 个选项:
- 在您的
MaterialApp 中定义a global theme:
MaterialApp(
title: 'Sample App',
theme: ThemeData(
// Define the default TextTheme. Use this to specify the default
// text styling for headlines, titles, bodies of text, and more.
textTheme: const TextTheme(
bodyText2: TextStyle(fontSize: 22, color: Colors.green), // Define your default Text style
subtitle1: TextStyle(fontSize: 24, color: Colors.green), // Define your own subtitle style
),
),
home: Scaffold(
appBar: AppBar(title: Text('Sample title', style: Theme.of(context).textTheme.subtitle1)), // Use your config like this
body: Text('Sample content'), // Without specifying style, the app will auto use your bodyText2 config
),
);
- 在本地小部件级别定义 DefaultTextTheme:
Scaffold(
body: DefaultTextStyle(
style: TextStyle(color: Colors.green),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'The first text', // A green color text
),
],
),
),
),
)
DefaultTextThemecan be found here 上的一个很好的例子。
您可以快速浏览official documentation,了解如何快速配置Text。