构建后页面正在导航到上一个屏幕-颤动

时间:2019-08-07 07:40:10

标签: flutter dart flutter-dependencies

我正在为我的应用实现office365登录。当用户注销时,他进入了启动屏幕。在启动屏幕中单击登录按钮后,他就进行了Office登录。完成登录过程后,他被带回了家。但是,在显示2秒钟后,该页面正被导航到启动屏幕。

Launch screen:
class Launch extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return FloatingActionButton(
      onPressed: (){
        Navigator.push(context,
            MaterialPageRoute(builder: (BuildContext context) { return Login(); }));
      },
    );
  }
}


Login Screen:
class LoginState extends State<Login> {
  bool isValid = false;
  String name;

  @override
  initState() {
    super.initState();
    name = getNameFromOffice();
//gets the name of logged in user after logging into office365
    if(name == ''){
      setState(() {
        isValid = true;
      });

    }
    else{
      setEmail(name);
    }
  }


  @override
  Widget build(BuildContext context) {
    return
      isValid ? Home() :
      Scaffold(
          backgroundColor: Colors.white,
          resizeToAvoidBottomInset:true,
          body: Text('whatever')
      );
  }
  setEmail(name) async{
    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.setString('email', name);
     setState(() {
      isValid = true;
    });

  }
}

0 个答案:

没有答案