以编程方式关闭模态底表

时间:2020-07-06 10:11:16

标签: flutter flutter-layout flutter-showmodalbottomsheet

在下面的示例中,我通过按下“加高”按钮打开了一个模式底部页面。在打开的页面中,我有另一个图标可以打开另一个页面,但是我想在打开页面后关闭第一张页面。第二页底页。我该如何实现?

         import 'package:flutter/material.dart';

        class SecondScreen extends StatefulWidget {
         @override
        _SecondScreenState createState() => _SecondScreenState();
        }

        class _SecondScreenState extends State<SecondScreen> {
           @override
            Widget build(BuildContext context) {
              return Center(
                child: Container(
                 child:RaisedButton(child: Text('Click'), onPressed: () => _openSheet()),
                     ),
                  );
              }

           _openSheet() {
                        showModalBottomSheet(
                          context: context,
                          builder: (BuildContext context) 
                       {
                                return Column(
                                 children: <Widget>[
                                   Container(
                                     height: MediaQuery.of(context).size.height / 2,
                                     width: MediaQuery.of(context).size.width,
                                      child: IconButton(
                                       icon: Icon(Icons.info),
                                        iconSize: 50.0,
                                         onPressed: () => _openSecondSheet(),
                                          ),
                                         ),
                                        ],
                                       );
                                    });
                                  }

                             _openSecondSheet() {
                                showModalBottomSheet(
                               context: context,
                               builder: (BuildContext context) {
                               return Container(
                               height: MediaQuery.of(context).size.height / 3,
                               width: MediaQuery.of(context).size.width,
                               );
                             });
                           }
                        }

1 个答案:

答案 0 :(得分:1)

打开第二只绵羊pop的同时,

onPressed: () {
             Navigator.pop(context);
             _openSecondSheet()
            },