Show bottomSheet beneath bottomNavigationBar

后端 未结 3 726
谎友^
谎友^ 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    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 {
    
      @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.

提交回复
热议问题