How to Change Appbar Color in Flutter?

In this tutorial, we are going learn to change Appbar Color in Flutter app using five different ways.

Customizing its color not only ensures consistency with your app’s theme but also enhances its visual appeal. Flutter empowers developers to effortlessly modify the AppBar’s color by leveraging the app’s theme, color properties, and the framework itself.

In this guide, you will get and implement the full code directly into your app. Let’s get started…

Change Appbar Color in Flutter

5 Ways to Change Appbar Color in Flutter

In Flutter, there are several ways to change the color of the AppBar. Here are the most common methods:

1. Change Appbar Color in Flutter-  backgroundColor property

This is the most straightforward way to change the AppBar color. You can set the backgroundColor property of the AppBar widget to the desired color value.

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'AppBar Color Demo',
      home: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.red,
          title: Text('Background Color'),
        ),
        body: Center(
          child: Text('Hello, World!'),
        ),
      ),
    );
  }
}

Output

Using backgroundColor Property to Change Appbar Color in Flutter

2. Using the brightness property

The brightness property of the AppBar determines whether the app bar is rendered with a light or dark color. By setting the brightness to Brightness.light or Brightness.dark, the app bar will automatically use the appropriate color based on the current theme.

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'AppBar Color Demo',
      theme: ThemeData(
        brightness: Brightness.dark, // Set to Brightness.light for light theme
      ),
      home: Scaffold(
        appBar: AppBar(
          title: Text('Brightness'),
        ),
        body: Center(
          child: Text('Hello, World!'),
        ),
      ),
    );
  }
}

Output

Using Brightness Property to Change Appbar Color in Flutter

3. Using the theme property

You can also set the AppBar color by modifying the theme of your app. In your MaterialApp widget, you can define the appBarTheme property and set the color property of appBarTheme to the desired color.

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'AppBar Color Demo',
      theme: ThemeData(
        appBarTheme: const AppBarTheme(
          color: Colors.green,
        ),
      ),
      home: Scaffold(
        appBar: AppBar(
          title: Text('Theme'),
        ),
        body: Center(
          child: Text('Hello, World!'),
        ),
      ),
    );
  }
}

Output

Changing the Appbar Color using Theme Property

4. Using the primary and primaryColor properties

In some cases, the AppBar color is determined by the primary and primaryColor properties of the ThemeData. You can modify these properties to change the AppBar color globally.

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'AppBar Color Demo',
      theme: ThemeData(
        primaryColor: Colors.purple,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: Text('Primary Color'),
        ),
        body: Center(
          child: Text('Hello, World!'),
        ),
      ),
    );
  }
}

Output

Changing the Appbar Color using Primary and PrimaryColor Property

5. Using a custom AppBar widget

If you need more control over the AppBar appearance, you can create a custom AppBar widget by extending the AppBar class and overriding the build method to customize the UI as per your requirements.

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'AppBar Color Demo',
      home: Scaffold(
        appBar: CustomAppBar(),
        body: Center(
          child: Text('Hello, World!'),
        ),
      ),
    );
  }
}

class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
  @override
  Widget build(BuildContext context) {
    return AppBar(
      backgroundColor: Colors.orange,
      title: Text('Custom AppBar'),
    );
  }

  @override
  Size get preferredSize => Size.fromHeight(kToolbarHeight);
}

Output

Changing the Appbar Color using custom Appbar Widget

Also Read:

Summary

In summary, there are multiple ways to change the AppBar color in Flutter, including using the backgroundColor, brightness, theme, primary and primaryColor properties, or creating a custom AppBar widget.

If you haven’t already installed Flutter, you can follow the official: Flutter Installation Guide. to set it up.

Share:
Ambika Dulal

Ambika Dulal is a Flutter Developer from Nepal who is passionate about building beautiful and user-friendly apps. She is always looking for new challenges and is eager to learn new things. She is also a strong believer in giving back to the community and is always willing to help others.

Leave a Comment

AO Logo

App Override is a leading mobile app development company based in Kathmandu, Nepal. Specializing in both Android and iOS app development, the company has established a strong reputation for delivering high-quality and innovative mobile solutions to clients across a range of industries.

Services

UI/UX Design

Custom App Development

Mobile Strategy Consulting

App Testing and Quality Assurance

App Maintenance and Support

App Marketing and Promotion

Contact

App Override

New Plaza, Kathmandu