在底部导航栏下显示底部弹出框

14
我们的应用程序中使用了底部导航栏和底部抽屉式面板。
底部抽屉式面板出现在底部导航栏之上,是否有一种方法使其出现在其下方?
这里是一个示例应用程序:
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,
          ),
        ),
      ),
    );
  }
}

1
我非常确定这是不可能的。我理解你的目标,但这只是通常工作方式的问题。新的 FAB 位置也与 bottomNavigationBar 不兼容。最好在 GitHub 上检查一下问题。 - creativecreatorormaybenot
3个回答

17

添加: useRootNavigator: true,

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

谢谢您的建议!这是针对showModalBottomSheet的,而我想使用showBottomSheet。 - Hillel Coren
这应该是答案。对我有效。 - Panduranga Rao Sadhu

3

注意到了你的问题。我之前也遇到了同样的问题,不过找到了更好的解决方案。使用showModalBottomSheet()函数,它可以覆盖底部导航。


不明白为什么这不是被接受的答案。被接受的答案看起来像是一个笨拙的解决方法,而你的方法却非常完美。 - NiklasLehnfeld
1
showModalBottomSheet覆盖整个视图,并添加一个屏障,防止与其下方的任何视图进行交互。对于这两种情况都有业务案例,但是所提出的问题涉及到非模态版本的showBottomSheet - Andy Shephard

2
您可以使用Column将弹出窗口与底部导航栏结合,并使用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(),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

对于生产应用程序,请考虑使用 SafeArea 在底部添加适当的填充。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接