1

I was working on a Flutter project and I tried to add the title parameter to AppBarTheme but it gave me an error. This is the code:

@override Widget build(BuildContext context){ return MaterialApp( theme: ThemeData( primarySwatch: Colors.green, accentColor: Colors.pinkAccent, fontFamily: 'Quicksand', appBarTheme: AppBarTheme(textTheme: ThemeData.light().textTheme.copyWith( title: const TextStyle( fontFamily: 'Quicksand', fontSize: 20, ) ) ) ) ); } 

The error was: The named parameter 'title' isn't defined. How can I solve this?

2
  • Please provide the entire code instead of a photo or screenshot so that it will be easy to debug for others and provide a solution for you. Commented Nov 24, 2021 at 1:09
  • My bad I am new here, fine I am going to edit it right now, thank you. Commented Nov 24, 2021 at 14:24

2 Answers 2

3

Here is the way :

import 'package:flutter/material.dart'; class Home extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('AppBar titleTextStyle')), body: Center(child: Text('Hello World')), ); } } void main() { runApp( MaterialApp( theme: ThemeData.light().copyWith( appBarTheme: AppBarTheme( backgroundColor: Colors.yellow, titleTextStyle: TextStyle(color: Colors.black), backwardsCompatibility: false, // !!! ), ), home: Home(), ), ); } 
Sign up to request clarification or add additional context in comments.

Comments

1

You cannot add title to AppBarTheme, you can only provide the TextStyle for the title in themeData and add the title in AppBar like this:

AppBar( title: Text( 'your text', // You need to add this line style: Theme.of(context).appBarTheme.TextStyle, ), ), 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.