颤振导航无限循环

时间:2019-03-16 16:18:39

标签: flutter navigation

所以我似乎有一个导航无限循环。

获取用户个人资料后,它将检查是否存在付款令牌。如果没有,它将导航到一个无状态付款小部件,在此我将显示价格计划并显示该小部件,用于从条带中收集付款信息。

由于某种原因,它导航到无状态页面,然后返回,发出网络请求,然后再次转到无状态支付页面,返回....

付款类别

class Payment extends StatelessWidget {

  void _savePayment() {

  }

  @override
  Widget build(BuildContext context) {
    return  Scaffold(
          appBar: AppBar(
            title: Text('Payment'),
            leading: FlatButton(
                child: new Icon(FontAwesomeIcons.userCircle, color: Colors.white),
                onPressed: () => _savePayment(),
              )
          ),
          backgroundColor: Color(0xff01579B),
          body: Column(
            children: <Widget>[
              //SoloCard()
            ],
          )
      );
  }

} 

网络通话

void getDoctors(BuildContext context) async {
    try {
      FirebaseUser firebaseUser = await FirebaseAuth.instance.currentUser();
      var user = await ProfileApi.getUser(firebaseUser);
      setState(() {
        doctors = user.doctors;
      });
      if (user.userToken == null || user.userToken.isEmpty) {
        Navigator.of(context).push(new MaterialPageRoute(builder: (context) => Payment()));
      }
    } catch(e) {
      if (_scaffoldKey.currentState == null) {
        return;
      }
      WidgetsBinding.instance.addPostFrameCallback((_) =>
        _scaffoldKey.currentState.showSnackBar(
          SnackBar(
            content: Text('Unable to get your profile try again'),
            duration: const Duration(minutes: 5),
            action: SnackBarAction(label: "Retry", onPressed:() => getDoctors(context))
          )
        )
      );
    }
  } 

0 个答案:

没有答案