<|start_filename|>lib/src/flip_bar_element.dart<|end_filename|>
import 'package:flutter/material.dart';
import 'flip_box.dart';

/// Class for initialising the FlipBox
class FlipBarElement extends StatelessWidget {
  /// Passing down icon widget from upper widget
  final Widget icon;

  /// Passing down text widget from upper widget
  final Widget text;

  /// Passing down widget from upper widget
  final Color frontColor;

  /// Passing down widget from upper widget
  final Color backColor;

  /// Passing down widget from upper widget
  final AnimationController controller;

  /// Passing down widget from upper widget
  final ValueChanged<int> onTapped;

  /// The index of the box.
  final index;

  /// Passing down widget from upper widget
  final double appBarHeight;

  FlipBarElement(this.icon, this.text, this.frontColor, this.backColor,
      this.controller, this.onTapped, this.index, this.appBarHeight);

  @override
  Widget build(BuildContext context) {
    return FlipBox(
      controller: controller,
      bottomChild: Container(
        width: double.infinity,
        height: double.infinity,
        color: backColor,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            icon,
            text,
          ],
        ),
      ),
      topChild: Container(
        width: double.infinity,
        height: double.infinity,
        color: frontColor,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            icon,
          ],
        ),
      ),
      onTapped: () {
        onTapped(index);
      },
      height: appBarHeight,
    );
  }
}


<|start_filename|>lib/src/flip_box.dart<|end_filename|>
import 'package:flutter/material.dart';
import 'dart:math';

/// FlipBox constructs a Box consisting of two planes which can be controlled using a given Animation Controller.
class FlipBox extends StatefulWidget {
  /// The widget on the top side of the box. (Here, "top" refers to position in Stack).
  final Widget bottomChild;

  /// The widget in front of the user initially.
  final Widget topChild;

  /// The height of the box (Carries the BottomNavigationBar height).
  final double height;

  /// The animation controller to control the flip animation.
  final AnimationController controller;

  /// Callback for when the box is selected (Not when the box is reversed).
  final VoidCallback onTapped;

  FlipBox({
    this.bottomChild,
    this.topChild,
    this.height = 100.0,
    this.controller,
    this.onTapped,
  });

  @override
  _FlipBoxState createState() => _FlipBoxState();
}

class _FlipBoxState extends State<FlipBox> with SingleTickerProviderStateMixin {
  /// Tween for going from 0 to pi/2 radian and vice versa.
  Animation animation;

  /// Controller for controlling the Box.
  AnimationController controller;

  @override
  void initState() {
    super.initState();
    if (widget.controller == null) {
      controller = AnimationController(
          vsync: this, duration: Duration(milliseconds: 2000));
    } else {
      controller = widget.controller;
    }
    animation = Tween(begin: 0.0, end: pi / 2).animate(
      CurvedAnimation(parent: controller, curve: Curves.elasticInOut),
    );

    controller.addListener(() {
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: widget.height,
      width: double.infinity,
      child: Stack(
        children: <Widget>[
          Transform(
            alignment: Alignment.center,
            transform: Matrix4.identity()
              ..setEntry(3, 2, 0.001)
              ..translate(0.0, -(cos(animation.value) * (widget.height / 2)),
                  ((-widget.height / 2) * sin(animation.value)))
              ..rotateX(-(pi / 2) + animation.value),
            child: Container(
              child: Center(child: widget.bottomChild),
            ),
          ),
          GestureDetector(
            onTap: () {
              widget.onTapped();
              controller.forward();
            },
            child: animation.value < (85 * pi / 180)
                ? Transform(
                    alignment: Alignment.center,
                    transform: Matrix4.identity()
                      ..setEntry(3, 2, 0.001)
                      ..translate(
                        0.0,
                        (widget.height / 2) * sin(animation.value),
                        -((widget.height / 2) * cos(animation.value)),
                      )
                      ..rotateX(animation.value),
                    child: Container(
                      child: Center(child: widget.topChild),
                    ),
                  )
                : Container(),
          ),
        ],
      ),
    );
  }
}


<|start_filename|>example/lib/main.dart<|end_filename|>
import 'package:flutter/material.dart';
import 'package:flip_box_bar/flip_box_bar.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  int selectedIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Column(), //
      bottomNavigationBar: FlipBoxBar(
        selectedIndex: selectedIndex,
        items: [
          FlipBarItem(
              icon: Icon(Icons.map),
              text: Text("Map"),
              frontColor: Colors.blue,
              backColor: Colors.blueAccent),
          FlipBarItem(
              icon: Icon(Icons.add),
              text: Text("Add"),
              frontColor: Colors.cyan,
              backColor: Colors.cyanAccent),
          FlipBarItem(
              icon: Icon(Icons.chrome_reader_mode),
              text: Text("Read"),
              frontColor: Colors.orange,
              backColor: Colors.orangeAccent),
          FlipBarItem(
              icon: Icon(Icons.print),
              text: Text("Print"),
              frontColor: Colors.purple,
              backColor: Colors.purpleAccent),
          FlipBarItem(
              icon: Icon(Icons.print),
              text: Text("Print"),
              frontColor: Colors.pink,
              backColor: Colors.pinkAccent),
        ],
        onIndexChanged: (newIndex) {
          setState(() {
            selectedIndex = newIndex;
          });
        },
      ),
    );
  }
}


<|start_filename|>lib/src/flip_bar_item.dart<|end_filename|>
import 'package:flutter/material.dart';

/// Template for a [FlipBoxBar] item.
class FlipBarItem {
  /// The icon to be displayed on the sides (Can be replaced by any other widget).
  final Widget icon;

  /// The text to be displayed when item is selected (Can be replaced by any other widget).
  final Widget text;

  /// The color of the front side (Originally towards the user).
  final Color frontColor;

  /// The color of the top side (Towards the user when selected).
  final Color backColor;

  FlipBarItem({
    @required this.icon,
    @required this.text,
    this.frontColor = Colors.blueAccent,
    this.backColor = Colors.blue,
  });
}


<|start_filename|>lib/flip_box_bar.dart<|end_filename|>
library flip_box_bar;

export 'package:flip_box_bar/src/flip_box_bar.dart';
export 'package:flip_box_bar/src/flip_bar_item.dart';


<|start_filename|>lib/src/flip_box_bar.dart<|end_filename|>
library flip_box_bar;

import 'package:flip_box_bar/src/flip_bar_element.dart';
import 'package:flip_box_bar/src/flip_bar_item.dart';
import 'package:flutter/material.dart';

/// Top level widget for BottomNavigationBar.
class FlipBoxBar extends StatefulWidget {
  /// The items to be displayed in the BottomNavBar.
  final List<FlipBarItem> items;

  /// The duration of the animation of the box flip.
  final Duration animationDuration;

  /// Callback for getting value of item selection.
  final ValueChanged<int> onIndexChanged;

  /// The selected index of the bar
  final int selectedIndex;

  /// The height of the BottomNavBar.
  final double navBarHeight;

  FlipBoxBar({
    @required this.items,
    this.animationDuration = const Duration(seconds: 1),
    @required this.onIndexChanged,
    @required this.selectedIndex,
    this.navBarHeight = 100.0,
  });

  @override
  _FlipBoxBarState createState() => _FlipBoxBarState();
}

class _FlipBoxBarState extends State<FlipBoxBar> with TickerProviderStateMixin {
  /// Hosts all the controllers controlling the boxes.
  List<AnimationController> _controllers = [];

  @override
  void initState() {
    super.initState();

    // Initialise all animation controllers.
    for (int i = 0; i < widget.items.length; i++) {
      _controllers.add(
        AnimationController(
          vsync: this,
          duration: widget.animationDuration,
        ),
      );
    }

    // Start animation for initially selected controller.
    _controllers[widget.selectedIndex].forward();
  }

  @override
  Widget build(BuildContext context) {
    _changeValue();
    return Container(
      height: 100.0,
      child: Row(
        children: widget.items.map((item) {
          int index = widget.items.indexOf(item);
          // Create the boxes in the NavBar.
          return Expanded(
            child: FlipBarElement(
              item.icon,
              item.text,
              item.frontColor,
              item.backColor,
              _controllers[index],
              (index) {
                _changeValue();
                widget.onIndexChanged(index);
              },
              index,
              widget.navBarHeight,
            ),
          );
        }).toList(),
      ),
    );
  }

  void _changeValue() {
    _controllers.forEach((controller) => controller.reverse());
    _controllers[widget.selectedIndex].forward();
  }

  @override
  void dispose() {
    super.dispose();
    _controllers.forEach((controller) => controller.dispose());
  }
}
