bind_phone_page.dart 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:sport/pages/login/auth_code_verify.dart';
  4. import 'package:sport/pages/login/login_widget.dart';
  5. import 'package:sport/provider/login_info_model.dart';
  6. import 'package:sport/router/navigator_util.dart';
  7. import 'package:sport/widgets/appbar.dart';
  8. import 'package:sport/widgets/dialog/alert_dialog.dart';
  9. import 'package:sport/widgets/dialog/request_dialog.dart';
  10. class BindPhonePage extends StatefulWidget {
  11. @override
  12. State<StatefulWidget> createState() {
  13. return _PageState();
  14. }
  15. }
  16. class _PageState extends State<BindPhonePage> {
  17. int _progress = 0;
  18. String _phone;
  19. @override
  20. void initState() {
  21. super.initState();
  22. }
  23. setProgress({int progress}) {
  24. setState(() {
  25. progress != null ? _progress = progress : _progress += 1;
  26. });
  27. }
  28. @override
  29. Widget build(BuildContext context) {
  30. return WillPopScope(
  31. onWillPop: () async => _progress > 0
  32. ? showDialog(
  33. context: context,
  34. builder: (context) => CustomAlertDialog(
  35. title: '你真的要退出吗',
  36. ok: () {
  37. Navigator.of(context).pop(true);
  38. },
  39. ))
  40. : true,
  41. child: Scaffold(
  42. backgroundColor: Colors.white,
  43. body: CustomScrollView(slivers: <Widget>[
  44. SliverAppBar(
  45. pinned: true,
  46. elevation: 0,
  47. leading: buildBackButton(context),
  48. expandedHeight: 140.0,
  49. flexibleSpace: FlexibleSpaceBar(
  50. title: Text(
  51. "绑定手机号",
  52. style: titleStyle,
  53. ),
  54. ),
  55. ),
  56. SliverFillRemaining(
  57. hasScrollBody: false,
  58. fillOverscroll: false,
  59. child: Container(
  60. color: Colors.white,
  61. width: double.infinity,
  62. padding: EdgeInsets.only(top: 20.0),
  63. child: Column(
  64. mainAxisAlignment: MainAxisAlignment.start,
  65. children: <Widget>[
  66. Input(
  67. labelText: "请输入手机号",
  68. textInputType: TextInputType.phone,
  69. maxLength: 11,
  70. callBack: (value) {
  71. _phone = value; // onchanged
  72. },
  73. ),
  74. Container(
  75. padding: EdgeInsets.only(bottom: 48.0),
  76. child: Text(
  77. "请输入要绑定的手机号",
  78. style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1), fontSize: 12.0),
  79. ),
  80. ),
  81. button("获取验证码", () async {
  82. setProgress();
  83. final _loginInfoModel = LoginInfoModel();
  84. var code = await request(context, () async {
  85. return await _loginInfoModel.getCaptcha(_phone).catchError((err) {});
  86. });
  87. if (code == true) {
  88. var result = await NavigatorUtil.goPage(
  89. context,
  90. (context) => AuthCodeVerifyPage(_phone, (captcha) async {
  91. return await _loginInfoModel.loginApi.bindPhone(_phone, captcha);
  92. }));
  93. if (result != null && result['code'] == 0) {
  94. _loginInfoModel.saveUserInfo({"phone": _phone});
  95. Navigator.of(context).pop(true);
  96. }
  97. print("result $result");
  98. }
  99. }),
  100. ],
  101. ),
  102. )),
  103. ]),
  104. ),
  105. );
  106. }
  107. }