为什么appBar的字体比body

Why is the appBar font weight more than in the body

当我尝试 运行 我的 Flutter 应用程序(在 windows 上)时,我发现 appBar 标题权重大于 body 文本权重(即使它们是相同的字体)

This is what I mean - the appBar weight is more than the weight of the text on the body

我的代码如下所示:

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(fontFamily: 'SegoeUIVar'),
      debugShowCheckedModeBanner: false,
      title: 'Hello World',
      home: Scaffold(
        appBar: PreferredSize(
          preferredSize: const Size.fromHeight(32.0),
          child: AppBar(
            elevation: 0,
            backgroundColor: const Color.fromARGB(230, 30, 31, 28),
            centerTitle: true,
            title: const Text("Hello World", style: TextStyle(fontSize: 15, fontFamily: 'SegoeUIVar')),
          )
        ),

        body: const Center(
          child: Text('Hello World'),
        ),
      ),
    );
  }
}

在flutter中,每个widget都有自己的主题,所以即使分配了不同的fontFamily,fontWeight也会默认为那个widgets的主题。要分配相同的 fontWweight,您需要在 TextStyle 或实际主题中执行此操作

 Text(
    'Hello',
    style: TextStyle(fontWeight: FontWeight.bold),
  ),
)