Hibok
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

162 行
4.8 KiB

  1. import 'package:chat/data/constants.dart';
  2. import 'package:chat/generated/i18n.dart';
  3. import 'package:chat/utils/CustomUI.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter/services.dart';
  6. import 'package:oktoast/oktoast.dart';
  7. import '../utils/ShadowButton.dart';
  8. import '../utils/HttpUtil.dart';
  9. import 'package:dio/dio.dart';
  10. import "../data/UserData.dart";
  11. import '../utils/TokenMgr.dart';
  12. class BindCodePage extends StatefulWidget {
  13. BindCodePage({Key key, bool flag}) : super(key: key);
  14. _BindCodePageState createState() => _BindCodePageState();
  15. }
  16. class _BindCodePageState extends State<BindCodePage> {
  17. String _code = '';
  18. @override
  19. Widget build(BuildContext context) {
  20. Widget appBar = AppBar(
  21. backgroundColor: AppColors.NewAppbarBgColor,
  22. title: Text(
  23. I18n.of(context).bind_code,
  24. style: TextStyle(color:AppColors.NewAppbarTextColor ),
  25. textScaleFactor: 1.0,
  26. ),
  27. leading: CustomUI.buildCustomLeading(context),
  28. centerTitle: true,
  29. );
  30. return Scaffold(
  31. body: SafeArea(
  32. child: Center(
  33. child: Container(
  34. height: MediaQuery.of(context).size.height,
  35. width: MediaQuery.of(context).size.width,
  36. child: _buildBody(),
  37. ),
  38. )),
  39. appBar: appBar,
  40. resizeToAvoidBottomPadding: false,
  41. );
  42. }
  43. @override
  44. void initState() {
  45. super.initState();
  46. print('BindCodePage initState');
  47. }
  48. @override
  49. void dispose() {
  50. super.dispose();
  51. }
  52. Widget _buildBody() {
  53. return new Column(
  54. children: <Widget>[
  55. _buildTextInput(),
  56. _buildTips(),
  57. _buildLoginButton(),
  58. ],
  59. );
  60. }
  61. Widget _buildTips() {
  62. var greyStyle = TextStyle(fontSize: 12, color: Constants.GreyTextColor);
  63. var redStyle = TextStyle(fontSize: 12, color: Colors.red);
  64. List list = I18n.of(context).fill_tips.split('/s1');
  65. return Container(
  66. alignment: Alignment.centerLeft,
  67. margin: EdgeInsets.only(top: 12, left: 13.5),
  68. child: RichText(
  69. text: TextSpan(children: [
  70. TextSpan(text: list[0], style: greyStyle),
  71. TextSpan(text: UserData().inviteCodePrice.toString(), style: redStyle),
  72. TextSpan(text: list[1], style: greyStyle),
  73. ])),
  74. );
  75. }
  76. Widget _buildTextInput() {
  77. return Container(
  78. margin: EdgeInsets.only(top: 5.5),
  79. color: Colors.white,
  80. child: Row(
  81. children: <Widget>[
  82. Container(
  83. margin:
  84. EdgeInsets.only(left: 14, right: 25, top: 27.5, bottom: 27.5),
  85. child: Text(I18n.of(context).invide_code,
  86. style: TextStyle(color: Constants.BlackTextColor)),
  87. ),
  88. Expanded(
  89. child: TextField(
  90. keyboardAppearance: Brightness.light,
  91. style:
  92. TextStyle(fontSize: 14, textBaseline: TextBaseline.alphabetic),
  93. decoration: new InputDecoration(
  94. hintText: I18n.of(context).enter_incode,
  95. hintStyle: TextStyle(fontSize: 14),
  96. border: InputBorder.none,
  97. ),
  98. maxLines: 1,
  99. keyboardType: TextInputType.phone,
  100. inputFormatters: [
  101. WhitelistingTextInputFormatter.digitsOnly,
  102. LengthLimitingTextInputFormatter(5)
  103. ],
  104. onChanged: (str) {
  105. _code = str;
  106. setState(() {});
  107. },
  108. ))
  109. ],
  110. ),
  111. );
  112. }
  113. //构建绑定按钮
  114. Widget _buildLoginButton() {
  115. Text text = new Text(I18n.of(context).determine,
  116. textScaleFactor: 1.0,
  117. style: TextStyle(
  118. fontSize: Constants.ShaderButtonFontSize, color: Colors.white));
  119. LinearGradient gradientColor = new LinearGradient(colors: <Color>[
  120. Constants.ConfrimButtonColor,
  121. Constants.ConfrimButtonColor,
  122. ]);
  123. callback() async {
  124. if (_code == null || _code == "") {
  125. showToast(I18n.of(context).enter_incode);
  126. return;
  127. }
  128. Map data = {
  129. "userId": UserData().basicInfo.userId,
  130. "agentId": int.parse(_code),
  131. };
  132. data['sign'] = TokenMgr().getSign(data);
  133. Response res = await HttpUtil()
  134. .post('user/bind/agent', data: data, isShowLoading: true);
  135. var resData = res.data;
  136. showToast(resData['msg']);
  137. if (resData['code'] == 0) {
  138. UserData().agentId = int.parse(_code);
  139. Navigator.of(context).pop();
  140. }
  141. }
  142. return new Container(
  143. margin: EdgeInsets.only(top: 35.5),
  144. height: Constants.ShaderButtonHeight,
  145. width: MediaQuery.of(context).size.width * 0.85,
  146. child: ShadowButton().builder(gradientColor, text, callback),
  147. );
  148. }
  149. }