kBottomNavigationBarHeight returning incorrect value

52 views Asked by At

In my app, I want to overlay another bar above the bottom navigation bar, which stays constant throughout the app. The overlay mechanism works as I desire, except for the fact that the position of it is incorrect when I put it at kBottomNavigationBarHeight from bottom.

Code:

  @override
  Widget build(BuildContext context) {

    final bar = SizedBox(
      height: 60,
      child: Container(
        color: Colors.green,
      ),
    );

    return Scaffold(
      backgroundColor: Colors.white,
      body: Stack(
        children: [
          childWidget, // the other page that has a BottomNavigationAppBar 
          Positioned(
            left: 0,
            right: 0,
            bottom: kBottomNavigationBarHeight,
            child: bar, //OfflineAd(),
          ),
        ],
      ),
    );
  }

This gives me the below where the green-bar overlaps the bottomNavigationAppBar.

enter image description here

So seems like kBottomNavigationBarHeight does not give me the correct value. I tried adding to it the MediaQuery.of(context).padding.bottom and MediaQuery.of(context).viewInsets.bottom, but adding those doesn't get me the right value either. This seems like something that should be really simple. Am I missing something obvious?

If I hardcode, then I can set it correctly for a specific phone model - but obviously that fails on other phones. But for reference, if I hardcode a value of kBottomNavigationBarHeight + 24, then for this phone model it sits perfectly on top of the bottom bar:

enter image description here

0

There are 0 answers