Flutter登陆界面(含dio网络请求)

前言

点击登陆后先页面判断是否为空,不为空则将user和password传递给接口,由接口判断返回是否登陆成功的判断字段success。如果成功则跳转到主页,并销毁主页之前所有页面(即不能返回,点击物理返回键则退出程序)。还没写传给下个页面值的方法,后续会添加

loadDataByDio() async {
    try {
      print('登陆中');
      Response response;
      Dio dio = new Dio();
      response = await dio.get(
          "接口地址?LOGIN_NAME=$_user&PASSWORD=$_password");
      if (response.statusCode == 200) {
        _decodeTest(response.data);
      } else {
        _result = 'error code : ${response.statusCode}';
      }
    } catch (exception) {
      print('exc:$exception');
      _result = '网络异常';
    }

    setState(() {});
  }

  _decodeTest(var body) {
    bool usertxt = body['success'];
    String errMess = body['message'];
    if (usertxt == false) {
      _modalBottomSheetMenu(errMess);
    } else {
      Navigator.of(context).pushAndRemoveUntil(
          new MaterialPageRoute(builder: (context) => new NavBar()),
          (route) => route == null);
    }
  }

  _modalBottomSheetMenu(errMess) {
    showModalBottomSheet(
        context: context,
        builder: (builder) {
          return new Container(
            height: 50.0,
            child: new Container(
                decoration: new BoxDecoration(
                    color: Colors.grey,
                ),
                child: new Center(
                  child: new Text(errMess,style: TextStyle(color: Colors.white),),
                )),
          );
        });
  }
完整代码在我的码云仓库:

链接: https://gitee.com/siwuji/Flutter_try.

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值