Show bottomSheet beneath bottomNavigationBar

后端 未结 3 738
谎友^
谎友^ 2021-02-15 19:43

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 underneat

相关标签:
3条回答
  • 2021-02-15 19:48

    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.

    0 讨论(0)
  • 2021-02-15 19:49

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

    0 讨论(0)
  • 2021-02-15 20:08

    add : useRootNavigator: true,

    showModalBottomSheet(
          context: context,
          useRootNavigator: true,
          builder: (context) {},
        );
    
    0 讨论(0)
提交回复
热议问题