通过叠加水龙头观察导航栏关闭

时间:2018-10-25 17:03:23

标签: android flutter

我有一个带有导航抽屉的应用程序。这是我已经实现的:

我的应用程序有3页,如果我在第二个抽屉中,然后按返回按钮,则该应用程序会将我带回到我的第一页(例如Gmail应用程序)。我有下一个错误,如果我位于第二个片段中,请打开抽屉,然后在右侧的深色区域中按一下将其关闭,然后按“后退”按钮,该应用会将我发送到登录页面。

如何在黑暗区域收到此新闻通知?

如果我能赶上这个事件,我可以解决我的问题。

enter image description here

这是我的代码:

int _selectedDrawerIndex = 0;
  _getDrawerItemWidget(int pos) {
    switch (pos) {
      case 0:
        return new FirstFragment(value: this.order);
      case 1:
        return new SecondFragment();
      case 2:
        return new ThirdFragment(value: suscribed);
      case 3:
        return new UserProfile();
      case 4:
      //auth.currentUser()==null?print('sin logueo'):print('con logueo');
        signOutWithGoogle().then((e){
          Navigator.of(context).pop(LoginPage.tag);
        });
        break;

      default:
        return new Text("Error");
    }
  }
  _onSelectItem(int index) {
    setState(() => _selectedDrawerIndex = index);
    Navigator.of(context).pop();// close the drawer
    this.draweropen=false;//drawer is closed
  }


  GlobalKey<ScaffoldState> _key = new GlobalKey<ScaffoldState>();
  _handleDrawer(){
    _key.currentState.openDrawer();
    setState(() {
      print('Opening drawer..');
      this.draweropen=true;//drawer is open
      //doAsyncStuff();
    });

  }

  Future<bool> _onWillPop() {
    print(this._selectedDrawerIndex);
    if(this.draweropen==true)
    {
      print('closing drawer..');
      Navigator.of(context).pop();
      this.draweropen=false;
      return null;
    }
    else
    {
      if(this._selectedDrawerIndex==0)
      {
        exit(0);
      }else
      {
        setState(() {
          this._selectedDrawerIndex=0;
        });
      }


      return null;
    }

  }
  Icon actionIcon = new Icon(Icons.search);
  //Widget appBarTitle = new Text("SaleFutbol",style: TextStyle(color: Theme.of(context).textTheme.title.color));
  @override
  Widget build(BuildContext context) {


    //print(_currentUserPhotoURL);
    if(photorefresh!=true)
    {
      updatePhoto();
      photorefresh=true;
    }

    //updatePhoto();
    var drawerOptions = <Widget>[];
    for (var i = 0; i < widget.drawerItems.length; i++) {
      var d = widget.drawerItems[i];
      drawerOptions.add(
          new ListTile(
            leading: new Icon(d.icon),
            title: new Text(d.title),
            selected: i == _selectedDrawerIndex,
            onTap: () => _onSelectItem(i),
          )
      );
    }

    return WillPopScope(
      onWillPop: _onWillPop,
      child: new
      Scaffold(
          key: _key,
          appBar: new AppBar(
            elevation: 0.0,
            title: Text("SaleFutbol",style: TextStyle(color: Theme.of(context).textTheme.title.color)),
            actions: <Widget>[
            GestureDetector(
              child: Stack(
                children: <Widget>[
                  Column(
                    children: <Widget>[
                      SizedBox(height: 20.0),
                      Icon(FontAwesomeIcons.solidBell,color: Colors.white,),
                    ],
                  ),
                  this.notnum>0?Column(
                    children: <Widget>[
                      SizedBox(height: 13.0),
                      Row(
                        children: <Widget>[
                          SizedBox(width: 10.0),
                          Material(
                            elevation: 3.0,
                            borderRadius: BorderRadius.circular(210.0),
                            color: Colors.red,
                            child: Container(
                              height: 20.0,
                              width: 20.0,
                              child: Center(child: Text(this.notnum.toString(),style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold))),),
                          ),
                        ],
                      ),
                    ],
                  ):Column(
                    children: <Widget>[
                      SizedBox(height: 13.0),
                      Row(
                        children: <Widget>[
                          SizedBox(width: 10.0),
                          SizedBox(width: 20.0),
                        ],
                      ),
                    ],
                  )
                ],
              ),onTap: (){ setState(() {
              this._selectedDrawerIndex=1;
              this.notnum=0;
            });},
            ),
            SizedBox(width: 15.0),
            ],
            leading: new IconButton(icon: new Icon(
              Icons.menu
              ,color: Theme.of(context).textTheme.title.color,),onPressed:(){
              _handleDrawer();
            }),
          ),
          drawer: new Drawer(
            child: new ListView(
              padding: EdgeInsets.zero,
              children: <Widget>[
                new UserAccountsDrawerHeader(
                  accountName: new Text(_currentUserName), accountEmail: new Text(_currentEmail),currentAccountPicture: GestureDetector(child: Hero(tag: 'UserPH', child: CircleAvatar(backgroundImage: _currentUserPhotoURL==null?AssetImage('images/logo.png'):CachedNetworkImageProvider(_currentUserPhotoURL))),onTap: null,),),
                new Column(children: drawerOptions),
              ],
            ),
          ),
          body: _getDrawerItemWidget(_selectedDrawerIndex),
      ),
    );
  }

}

0 个答案:

没有答案