Flutter BottomNavigationBar 和 Signout 问题

Flutter BottomNavigationBar and Signout problem

我试图在其中一个页面上制作注销按钮,但每当我在页面上有一个按钮时,BottomNavigationBarItem 就会消失。

class Profile extends StatefulWidget {
  //final Function(User) onSignOut;
  //Profile({@required this.onSignOut});
  Profile({Key key}) : super(key: key);

  @override
  _ProfileState createState() => _ProfileState();
}

问题是我不能同时写 Profile({@required this.onSignOut}) 和 Profile({Key key}) : super(key: key) 。如果我使用第一个,我有没有任何导航栏的注销屏幕,但如果我使用第二个,我会有导航栏,但我无法添加 onsignout。如果我同时使用 配置文件({@required this.onSignOut,Key key}):super(key: key)

单击“注销”按钮时会出现错误。我的 github 中提供了更多代码:https://github.com/bagmk/StartUp_Project/blob/master/TestFlutter/my_app/lib/pages/profile.dart

谢谢

将你的代码改成这样,它应该可以工作:

class Profile extends StatefulWidget {
  final Function(User) onSignOut;
 
  Profile({required Key key, required this.onSignOut}) : super(key: key);

  @override
  _ProfileState createState() => _ProfileState();
}