14

In our app we're using a bottomSheet along with a bottomNavigationBar.

The bottomSheet appears above the bottomNavigationBar, is there a way to make it appear underneath?

Here's a sample app:

import 'package:flutter/material.dart';

void main() {
  runApp(SampleApp());
}

class SampleApp extends StatefulWidget {
  @override
  _SampleAppState createState() => new _SampleAppState();
}

class _SampleAppState extends State<SampleApp> {
  final _scaffoldKey = GlobalKey<ScaffoldState>();
  PersistentBottomSheetController _sheetController;

  @override
  Widget build(BuildContext context) {
    final _showBottomSheet = () {
      _sheetController = _scaffoldKey.currentState.showBottomSheet((context) {
        return Container(
            color: Colors.grey[200],
            child: Column(mainAxisSize: MainAxisSize.min, children: [
              RadioListTile(dense: true, title: Text('Test'), groupValue: 'test', onChanged: (value) {}, value: true),
              RadioListTile(dense: true, title: Text('Test'), groupValue: 'test', onChanged: (value) {}, value: true),
            ]));
      });
    };

    return MaterialApp(
      home: Scaffold(
        key: _scaffoldKey,
        appBar: AppBar(
          title: Text('Sample App'),
        ),
        bottomNavigationBar: Container(
          child: IconButton(
            icon: Icon(Icons.edit),
            onPressed: _showBottomSheet,
          ),
        ),
      ),
    );
  }
}
Hillel Coren
  • 429
  • 2
  • 10
  • 28
  • 1
    I am pretty sure that this is impossible. I understand what you are aiming for, but that is just an issue with the way it works generally. The new FAB positions also do not work well with the `bottomNavigationBar`. Might just check issues on GitHub. – creativecreatorormaybenot Jun 03 '18 at 18:13

3 Answers3

16

add : useRootNavigator: true,

showModalBottomSheet(
      context: context,
      useRootNavigator: true,
      builder: (context) {},
    );
3

Noticed your question. Had same problem and found better solution. Use showModalBottomSheet(). It will overlay bottom navigation.

Kostya1375
  • 99
  • 6
  • Don't get why this isn't the accepted answer. The accepted answer looks like a hacky work around and yours just works like a charm. – NiklasLehnfeld Nov 10 '20 at 13:54
  • 1
    showModalBottomSheet overlays the entire view, also adding a barrier which prevents interaction with any view below it. There are business cases for both, however the question asked relates to `showBottomSheet`, the non-modal version. – Andy Shephard Feb 25 '21 at 16:46
2

You can combine your popup with the bottom navigation bar using Column and simulate bottom sheet behavior using Expandable:

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

void main() {
  runApp(SampleApp());
}

class SampleApp extends StatefulWidget {
  @override
  _SampleAppState createState() => new _SampleAppState();
}

class _SampleAppState extends State<SampleApp> {

  @override
  Widget build(BuildContext context) {
    buildBottomSheet() {
      return Container(
          color: Colors.grey[200],
          child: Column(mainAxisSize: MainAxisSize.min, children: [
            RadioListTile(dense: true, title: Text('Test'), groupValue: 'test', onChanged: (value) {}, value: true),
            RadioListTile(dense: true, title: Text('Test'), groupValue: 'test', onChanged: (value) {}, value: true),
          ]));
    }

    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Sample App'),
        ),
        body: Container(
          color: Colors.green,
        ),
        bottomNavigationBar: ExpandableNotifier(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              ExpandableButton(
                child: SizedBox(height: 50,
                  child: Center(
                    child: Icon(Icons.edit),
                  ),
                ),
              ),
              Expandable(
                expanded: buildBottomSheet(),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

For a production app, consider using SafeArea to add proper padding at the bottom.

Alexander Ryzhov
  • 2,705
  • 3
  • 19
  • 19