Learn App Making
with Ionic, Cordova & Flutter.

Start Here Buy Themes

Flutter Appbar Example

In this tutorial, we’re going to add AppBar with your flutter application. where the app bar contains menu icons, title, action buttons, change the background color of AppBar.

Checkout Flutter Tutorials for more articles on flutter

Let’s start by creating a new project or you can also choose exiting project

flutter create appbar
cd appbar

once we created a new project, we can start working with lib/main.dart file

Flutter AppBar Example

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: Scaffold(
      appBar: AppBar(
        title: Text("CODESUNDAR"),
        leading: Icon(Icons.menu),
        backgroundColor: Colors.redAccent,
        actions: <Widget>[
          IconButton(icon: Icon(Icons.videocam), onPressed: () => { }),
          IconButton(icon: Icon(Icons.account_circle), onPressed: () => { })
        ]
      )
    ));
  }
}

Explanation: We have created a stateless widget (because we’re not going to handle any data at this moment).

  • We have implemented material design with MaterialApp, which needs Scaffold (is nothing but a single page/view).
  • Scaffold widget contains more parameters but for now, we only need appBar
  • Inside AppBar widget we have passed title: as a Text widget
  • We have set backgroundColor using Colors objects (you can choose any colors)
  • The leading parameter allows you to put any widget as the left side (front slot) where actions are the right side.
  • Now, we have created IconButton inside actions

The final output for flutter AppBar

Hope this tutorial helps you.