Hibok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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