首页 > 解决方案 > Flutter:如何更改 Appbar 文本的字体?

问题描述

这是我当前的 main.dart 代码。我尝试将'主题:ThemeData(fontFamily:'Bebas Neue Regular')'放在标题下:Text('SMARTID'),因为我想更改为SMARTID的Appbar文本,但它似乎不起作用。

import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(
  home: MyApp(),
  debugShowCheckedModeBanner: false,
));

class MyApp extends StatefulWidget {
  @override 
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override 
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Smart ID',
      home: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            image: AssetImage("assets/background.png"), fit: BoxFit.cover)),
        child: Scaffold(
          backgroundColor: Colors.transparent,
          appBar: AppBar(
            elevation: 0,
            backgroundColor: Color(0xff05B068),
            title: Text('SMARTID'),
            theme: ThemeData(fontFamily: 'Bebas Neue Regular'),
            centerTitle: true,
          ),
        ),
      )
    );
  }
}

标签: flutterdart

解决方案


喜欢做,

appBar: AppBar(
            elevation: 0,
            backgroundColor: Color(0xff05B068),
            title: Text('SMARTID',style: TextStyle(fontFamily: 'YOUR_FONT_FAMILY')),
            centerTitle: true,
          ),

编辑:不要忘记像这张图片一样创建字体文件夹,

在此处输入图像描述

然后打开你的 pubspec.yaml 并像这样声明字体, 在此处输入图像描述

不要忘记获取包裹


推荐阅读