Ad

A Hole In Bottom Nav Bar With A Fab Inside It - Flutter

With flutter, how can I create a hole inside the bottom nav bar and put the fab inside it, something like the image below

I have tried wrapping the fab with padding, increase the top padding to move it down and increase the notch margin but the bottom nav bar did not look like I want.

FAb code:

Padding(
    padding: const EdgeInsets.only(top: 90),
    child: FloatingActionButton(...)
)

bottom nav bar code:

BottomAppBar(
    elevation: 0,
    color: Colors.transparent,
    shape: const CircularNotchedRectangle(),
    clipBehavior: Clip.antiAlias,
    notchMargin: 50.0,
    child: SizedBox(...)
)

Here is how I want it to look like

enter image description here

Ad

Answer

I am using Stack to draw on UI. play with widget's size, position, and color.

enter image description here

Run on dartPad

bottomNavigationBar: LayoutBuilder(
  builder: (context, constraints) => SizedBox(
    width: constraints.maxWidth,
    height: kToolbarHeight,
    child: Stack(
      children: [
        Positioned.fill(
          child: Container(
            color: Colors.white,
          ),
        ),

        /// middle fab
        Positioned(
          bottom: -20,
          top: -20,
          left: 0,
          right: 0,
          child: Container(
            height: kToolbarHeight * 1.5,
            width: kToolbarHeight * 1.5,
            decoration: BoxDecoration(
              color: Theme.of(context).scaffoldBackgroundColor,
              // Colors.deepPurple,

              shape: BoxShape.circle,
            ),
          ),
        ),

        Align(
          alignment: Alignment.center,
          child: Container(
            width: kToolbarHeight * .8,
            height: kToolbarHeight * .8,
            alignment: Alignment.center,
            decoration: const BoxDecoration(
              color: Colors.amber,
              shape: BoxShape.circle,
            ),
            child: const Text("A"),
          ),
        )
      ],
    ),
  ),
),
Ad
source: stackoverflow.com
Ad