在Flutter中导航时,防止第一个屏幕的元素显示在第二个屏幕上

时间:2019-05-10 16:40:36

标签: flutter navigation

我使用的是slide_up_panel,当我导航到第二个屏幕时,sliding_up_panel仍与菜单按钮一起出现,而这两个我都不想显示。

我已经弹出当前上下文,然后按下新屏幕。

First screen

Second screen that shouldn't have menu and sliding_up_panel

// This is what I do when I click my second screen button
onTap: () {
    Navigator.of(context).pop();
    Navigator.push(
        context,
        new MaterialPageRoute(
        builder: (BuildContext context) => new Settings()),
        );
},
// This is how I build my sliding_up_panel
body: SlidingUpPanel(
        controller: _pc,
        backdropTapClosesPanel: true,
        backdropEnabled: true,
        margin: const EdgeInsets.fromLTRB(10.0, 15.0, 10.0, 22.0),
        borderRadius: radius,
        panel: new GridView.count(
          crossAxisCount: 3,
          physics: new NeverScrollableScrollPhysics(),
          padding: const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
          children: <Widget>[
            FlatButton.icon(
                icon: Icon(Icons.transfer_within_a_station),
                onPressed: null,
                label: Text('Trash')),
            FlatButton.icon(
                icon: Icon(Icons.local_car_wash),
                onPressed: null,
                label: Text('Wash')),
            FlatButton.icon(
                icon: Icon(Icons.radio), onPressed: null, label: Text('Radio')),
            FlatButton.icon(
                icon: Icon(Icons.cake), onPressed: null, label: Text('Cake')),
            FlatButton.icon(
                icon: Icon(Icons.ac_unit), onPressed: null, label: Text('AC')),
            FlatButton.icon(
                icon: Icon(Icons.terrain),
                onPressed: null,
                label: Text('Testing')),
            FlatButton.icon(
                icon: Icon(Icons.access_alarm),
                onPressed: null,
                label: Text('Alarm')),
            FlatButton.icon(
                icon: Icon(Icons.tab), onPressed: null, label: Text('Tab')),
            FlatButton.icon(
                icon: Icon(Icons.backup),
                onPressed: null,
                label: Text('Backup')),
          ],
        ),
        body: Stack(children: <Widget>[
          GoogleMap(
            mapType: MapType.normal,
            onMapCreated: _onMapCreated,
            initialCameraPosition: CameraPosition(
              target: _center,
              zoom: 11.0,
            ),
            myLocationButtonEnabled: false,
          ),
          new Center(
              child: new Column(
            children: <Widget>[],
          )),
          Positioned(
            left: 20,
            top: 40,
            child: IconButton(
              icon: Icon(
                Icons.menu,
                size: 35,
                color: Colors.black,
              ),
              onPressed: () => scaffoldKey.currentState.openDrawer(),
            ),
          ),
        ]),
        collapsed: Container(
          decoration: BoxDecoration(color: Colors.green, borderRadius: radius),
          child: Center(
            child: Text(
              "Request a Service",
              style: TextStyle(
                  color: Colors.white,
                  fontSize: 18.0,
                  fontWeight: FontWeight.bold),
            ),
          ),
        ),
      ),

我希望第二个屏幕不包含第一个屏幕中的任何元素,但是从现在开始,将显示在堆栈中创建的菜单按钮和slide_up_panel。

编辑:经过更多测试后,看来这仅在热重装/热重启动之后发生。在执行其中一项操作之前,该应用程序可以正常正常运行。

0 个答案:

没有答案