AppBar with a custom bottom widget

This Article is posted by seven.srikanth at 21-07-2018 06:56:39

Click here to support us by Subscribing to our youtube channel.

Any widget with a PreferredSize can appear at the bottom of an AppBar.

Android screenshot

Typically an AppBar’s bottom widget is a TabBar however any widget with a PreferredSize can be used. In this app, the app bar’s bottom widget is a TabPageSelector that displays the relative position of the selected page in the app’s TabBarView. The arrow buttons in the toolbar part of the app bar and they select the previous or the next page.

Try this app out by creating a new project with flutter create and replacing the contents of lib/main.dart with the code that follows.

// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';

class AppBarBottomSample extends StatefulWidget {
  _AppBarBottomSampleState createState() => _AppBarBottomSampleState();

class _AppBarBottomSampleState extends State<AppBarBottomSample>
    with SingleTickerProviderStateMixin {
  TabController _tabController;

  void initState() {
    _tabController = TabController(vsync: this, length: choices.length);

  void dispose() {

  void _nextPage(int delta) {
    final int newIndex = _tabController.index + delta;
    if (newIndex < 0 || newIndex >= _tabController.length) return;

  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('AppBar Bottom Widget'),
          leading: IconButton(
            tooltip: 'Previous choice',
            icon: const Icon(Icons.arrow_back),
            onPressed: () {
          actions: <Widget>[
              icon: const Icon(Icons.arrow_forward),
              tooltip: 'Next choice',
              onPressed: () {
          bottom: PreferredSize(
            preferredSize: const Size.fromHeight(48.0),
            child: Theme(
              data: Theme.of(context).copyWith(accentColor: Colors.white),
              child: Container(
                height: 48.0,
                child: TabPageSelector(controller: _tabController),
        body: TabBarView(
          controller: _tabController,
          children: choice) {
            return Padding(
              padding: const EdgeInsets.all(16.0),
              child: ChoiceCard(choice: choice),

class Choice {
  const Choice({this.title, this.icon});

  final String title;
  final IconData icon;

const List<Choice> choices = const <Choice>[
  const Choice(title: 'CAR', icon: Icons.directions_car),
  const Choice(title: 'BICYCLE', icon: Icons.directions_bike),
  const Choice(title: 'BOAT', icon: Icons.directions_boat),
  const Choice(title: 'BUS', icon: Icons.directions_bus),
  const Choice(title: 'TRAIN', icon: Icons.directions_railway),
  const Choice(title: 'WALK', icon: Icons.directions_walk),

class ChoiceCard extends StatelessWidget {
  const ChoiceCard({Key key, this.choice}) : super(key: key);

  final Choice choice;

  Widget build(BuildContext context) {
    final TextStyle textStyle = Theme.of(context).textTheme.display1;
    return Card(
      color: Colors.white,
      child: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Icon(choice.icon, size: 128.0, color: textStyle.color),
            Text(choice.title, style: textStyle),

void main() {

See also:

Credits: This article was initially posted in

Tags: AppBar with a custom bottom widget.

Click here to support us by Subscribing to our youtube channel.

Login to comment.
Recent Comments

Be the first to Comment. You can ask a Query or Share your toughts or Just say thanks.

Wave animation in Flutter

Search Results

©2018 - Fluttercentral | Email to me -