企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ## theme 从 Flutter 3.16 版本开始, Material 3 是 Flutter 的默认主题。 **设置主题** ``` MaterialApp( title: appName, theme: ThemeData( useMaterial3: true, // Define the default brightness and colors. colorScheme: ColorScheme.fromSeed( seedColor: Colors.purple, // ··· brightness: Brightness.dark, ), // Define the default `TextTheme`. Use this to specify the default // text styling for headlines, titles, bodies of text, and more. textTheme: TextTheme( displayLarge: const TextStyle( fontSize: 72, fontWeight: FontWeight.bold, ), // ··· titleLarge: GoogleFonts.oswald( fontSize: 30, fontStyle: FontStyle.italic, ), bodyMedium: GoogleFonts.merriweather(), displaySmall: GoogleFonts.pacifico(), ), ), home: const MyHomePage( title: appName, ), ); ``` 大部分`ThemeData`实例会设置以下两个属性。它们会影响大部分样式属性。 1. [`colorScheme`](https://api.flutter-io.cn/flutter/material/ThemeData/colorScheme.html)定义了颜色。 2. [`textTheme`](https://api.flutter-io.cn/flutter/material/ThemeData/textTheme.html)定义了文字样式。 **应用指定的主题** ``` Container( padding: const EdgeInsets.symmetric( horizontal: 12, vertical: 12, ), color: Theme.of(context).colorScheme.primary, child: Text( 'Text with a background color', // ··· style: Theme.of(context).textTheme.displaySmall ), ), ``` **继承样式** ``` ```