Flutter unable to add title on AppBarTheme

Question

Asked by SUPER_AMORY on November 24, 2021 (source).

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?

Answer

Question answered by gretal (source).

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(),
    ),
  );
}
DART FLUTTER
SHARE: