Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show bottomSheet beneath bottomNavigationBar

Tags:

flutter

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,
          ),
        ),
      ),
    );
  }
}
like image 630
Hillel Coren Avatar asked Jun 03 '18 15:06

Hillel Coren


2 Answers

add : useRootNavigator: true,

showModalBottomSheet(
      context: context,
      useRootNavigator: true,
      builder: (context) {},
    );
like image 151
Nguyễn Hồng Quang Avatar answered Nov 15 '22 17:11

Nguyễn Hồng Quang


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

like image 35
Kostya1375 Avatar answered Nov 15 '22 19:11

Kostya1375