Convex Bottom Bar In Flutter

Convex Bottom Bar In Flutter :

dependencies:
convex_bottom_bar:

Screenshot 1:

Convex Bottom Bar In Flutter

Screenshot 2:

Convex Bottom Bar In Flutter

Screenshot 3:

Convex Bottom Bar In Flutter

color_item_view.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class ColorItemView extends StatelessWidget {
  final Color color;

  ColorItemView(this.color);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: color,
      alignment: Alignment.center,
      child: Text(
        color.value.toRadixString(16).toUpperCase(),
        style: const TextStyle(color: Colors.white),
      ),
    );
  }
}

custom_appbar_sample.dart

import 'package:convex_bottom_bar/convex_bottom_bar.dart';
import 'package:flutter/material.dart';

import 'color_item_view.dart';

class CustomAppBarDemo extends StatefulWidget {
  @override
  State createState() {
    return _State();
  }
}

class _State extends State<CustomAppBarDemo> {
  List<TabItem> items = <TabItem>[
    TabItem(icon: Icons.home, title: 'Home'),
    TabItem(icon: Icons.map, title: 'Discovery'),
    TabItem(icon: Icons.message, title: 'Message'),
    TabItem(icon: Icons.people, title: 'Profile')
  ];

  static const paletteColors = [
    Color(0xFFf44336),
    Color(0xFFE91E63),
    Color(0xFF9C27B0),
    Color(0xFF673AB7),
    Color(0xFF3F51B5),
    Color(0xFF2196F3),
    Color(0xFF00BCD4),
    Color(0xFF009688),
    Color(0xFF4CAF50),
    Color(0xFF8BC34A),
    Color(0xFFCDDC39),
    Color(0xFFFFEB3B),
    Color(0xFFFFC107),
    Color(0xFFFF9800),
    Color(0xFFFF5722),
    Color(0xFF795548),
    Color(0xFF9E9E9E),
    Color(0xFF607D8B),
  ];
  Color _tabBackgroundColor = paletteColors[5];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Custom ConvexAppBar')),
      body: paletteBody(),
      bottomNavigationBar: ConvexAppBar.builder(
        count: items.length,
        backgroundColor: _tabBackgroundColor,
        tabBuilder: (BuildContext context, int index, bool active) {
          var navigationItem = items[index];
          var _color = active ? Colors.white : Colors.white60;
          var _icon = active
              ? navigationItem.activeIcon ?? navigationItem.icon
              : navigationItem.icon;
          return Container(
            color: Colors.transparent,
            padding: EdgeInsets.only(bottom: 2),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.end,
              children: <Widget>[
                Icon(_icon, color: _color),
                Text(navigationItem.title, style: TextStyle(color: _color))
              ],
            ),
          );
        },
        actionBuilder: (BuildContext context, int index, bool active) {
          var _color = active ? Colors.white : Colors.white60;

          return Stack(
            alignment: Alignment.center,
            children: <Widget>[
              SizedBox(
                width: 60,
                height: 60,
                child: Container(
                  decoration:
                      BoxDecoration(shape: BoxShape.circle, color: _color),
                  child: Icon(
                    Icons.add,
                    size: 40,
                    color: _tabBackgroundColor,
                  ),
                ),
              )
            ],
          );
        },
      ),
    );
  }

  Container tabContent(TabItem data, Color color) {
    return Container(
        height: 50,
        padding: EdgeInsets.only(bottom: 2),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.end,
          children: <Widget>[
            Icon(data.icon, color: color),
            Text(data.title, style: TextStyle(color: color))
          ],
        ));
  }

  GridView paletteBody() {
    return GridView.count(
      crossAxisCount: 5,
      childAspectRatio: 1,
      mainAxisSpacing: 1,
      crossAxisSpacing: 1,
      children: paletteColors
          .map((c) => GestureDetector(
                child: ColorItemView(c),
                onTap: () => _onColorChanged(c),
              ))
          .toList(),
    );
  }

  void _onColorChanged(Color color) {
    setState(() {
      _tabBackgroundColor = color;
    });
  }
}

default_appbar_demo.dart

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:convex_bottom_bar/convex_bottom_bar.dart';

class DefaultAppBarDemo extends StatefulWidget {
  @override
  State createState() {
    return _State();
  }
}

class _State extends State<DefaultAppBarDemo> {
  int _selectedIndex = 0;
  static const INDEX_PUBLISH = 2;
  static const TAB_ITEMS = const <TabItem>[
    TabItem(icon: Icons.home, title: 'Home'),
    TabItem(icon: Icons.map, title: 'Discovery'),
    TabItem(icon: Icons.message, title: 'Message'),
    TabItem(icon: Icons.people, title: 'Profile')
  ];
  static const ACTIVE_COLOR = Colors.red;
  static const NORMAL_COLOR = Colors.black;

  @override
  Widget build(BuildContext context) {
    debugPrint('build');
    return Scaffold(
      appBar: AppBar(
        title: const Text('Default ConvexAppBar'),
      ),
      body: Center(
        child: Text('TAB $_selectedIndex', style: TextStyle(fontSize: 20)),
      ),
      bottomNavigationBar: ConvexAppBar(
        items: TAB_ITEMS,
        onTap: (int i) => setState(() {
          _selectedIndex = i;
        }),
        actionItem: const TabItem(icon: Icons.add, title: "Publish"),
        onTapActionButton: () => setState(() {
          _selectedIndex = -1;
        }),
      ),
    );
  }
}

main.dart

import 'package:flutter/material.dart';

import 'custom_appbar_sample.dart';
import 'default_appbar_demo.dart';

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

class MyApp extends StatefulWidget {
  @override
  State createState() => _State();
}

class _State extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      initialRoute: "/",
      routes: {
        "/": (BuildContext context) => Home(),
        "/default": (BuildContext context) => DefaultAppBarDemo(),
        "/custom": (BuildContext context) => CustomAppBarDemo(),
      },
    );
  }
}

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('ConvexAppBar Example'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            FlatButton(
              child: Text('Default  ConvexAppBar',
                  style: TextStyle(fontSize: 20.0)),
              color: Colors.blue,
              textColor: Colors.white,
              disabledColor: Colors.grey,
              disabledTextColor: Colors.black,
              padding: EdgeInsets.all(8.0),
              splashColor: Colors.blueAccent,
              onPressed: () => Navigator.of(context).pushNamed('/default'),
            ),
            FlatButton(
              child:
                  Text('Custom ConvexAppBar', style: TextStyle(fontSize: 20.0)),
              color: Colors.blue,
              textColor: Colors.white,
              disabledColor: Colors.grey,
              disabledTextColor: Colors.black,
              padding: EdgeInsets.all(8.0),
              splashColor: Colors.blueAccent,
              onPressed: () => Navigator.of(context).pushNamed('/custom'),
            ),
          ],
        ),
      ),
    );
  }
}

The flutter tutorial  is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application

For more information about Flutter. visit www.fluttertutorial.in