Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: How to change font of Appbar text?

Tags:

flutter

dart

Here's my current code of my main.dart. I tried putting 'theme: ThemeData(fontFamily: 'Bebas Neue Regular')' under the title: Text('SMARTID'), as I want to change the Appbar text which is SMARTID, but it doesn't seem to work.

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,
          ),
        ),
      )
    );
  }
}
like image 571
Nadia M Avatar asked Nov 15 '19 11:11

Nadia M


2 Answers

Do it like,

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

EDIT: Do not forget to create fonts folder like this image,

enter image description here

Then open your pubspec.yaml and declare fonts like this, enter image description here

DO not forget to get packages

like image 82
Ravinder Kumar Avatar answered Sep 26 '22 21:09

Ravinder Kumar


In addition, you also can declare the textStyle directly in your ThemeData, if you want to apply iny our entire app. Like this:

final ThemeData themeData = ThemeData(
  ...
  appBarTheme: AppBarTheme(
    titleTextStyle: TextStyle(
      fontWeight: FontWeight.bold,
    ),
  ),
  ...
);
like image 45
ricardogobbo Avatar answered Sep 22 '22 21:09

ricardogobbo