You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter TextTheme各属性对应哪些Widget?求速查表或文档指引

Flutter TextTheme 属性对应Widget速查表及常见问题解答

一、TextTheme 属性与对应Widget速查表(Material 3)

以下是各个TextTheme属性的典型使用场景和对应Widget:

  • displayLarge:超大号展示文本,比如启动页主标题、Hero区域大标题
  • displayMedium:次一级展示类文本,如页面顶部的大标题(非AppBar)
  • displaySmall:较小的展示类标题,用于强调但不抢视觉焦点的场景
  • headlineLarge:页面内的章节大标题,比如滚动页面的分段标题
  • headlineMedium:章节副标题,辅助说明大标题内容
  • headlineSmall:小章节标题,用于更细分的内容模块
  • titleLarge:AppBar标题、Dialog弹窗标题、BottomSheet底部弹窗标题
  • titleMedium:卡片主标题、部分列表项的主文本
  • titleSmall:小型卡片标题、次要列表项的标题文本
  • bodyLarge:列表项正文文本、页面正文内容、TextField输入框文本
  • bodyMedium:默认文本样式、辅助说明文本、音频播放器控件文本
  • bodySmall:小字提示文本、版权信息、次要说明内容
  • labelLarge:各类按钮文本(ElevatedButton、TextButton、OutlinedButton等)、Chip标签文本
  • labelMedium:次要按钮文本、开关/复选框旁的说明文本
  • labelSmall:小型按钮文本、图标按钮下方的小字标签

二、全局主题的自动生效逻辑

你在MaterialApp中配置的theme是全局主题,所有基于Material设计的Widget都会自动通过Theme.of(context)获取全局样式,不需要手动传递主题到子页面(比如page1.dart)。这是Flutter主题系统的默认机制,目的是保证整个App的样式一致性。

三、官方文档里的关键细节

官方文档其实有明确的Typography使用规范,只是容易被新手忽略:

  • TextTheme的每个属性对应Material Design 3的类型等级(Type Scale),每个等级都有明确的设计用途
  • 你可以在任意Widget中直接调用全局主题样式,比如:Text('示例文本', style: Theme.of(context).textTheme.titleLarge)
  • 如果需要局部修改样式,直接给Widget设置style属性覆盖即可,或者用Theme小部件包裹局部区域自定义子主题

附:你的main.dart代码

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Recording Insights',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
        textTheme: const TextTheme(
          displayLarge: TextStyle(fontSize: 57),
          headlineLarge: TextStyle(fontSize: 32),
          titleLarge: TextStyle(fontSize: 42),  //Affects appbar
          labelLarge: TextStyle(fontSize:26), //Affects buttons
          labelMedium: TextStyle(fontSize: 24),
          labelSmall: TextStyle(fontSize: 22),
          bodyLarge: TextStyle(fontSize: 22), //Affects list text
          bodyMedium: TextStyle(fontSize: 20),  //Affects the audio player text
          bodySmall: TextStyle(fontSize: 18)
        )
      ),

      home: const MyHomePage(title: 'Recording Insights'),
    );
  }
}

内容的提问来源于stack exchange,提问作者Tom Wiz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 16:15:12