Hibok
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

542 righe
17 KiB

  1. import 'package:chat/data/constants.dart';
  2. import 'package:chat/generated/i18n.dart';
  3. import 'package:chat/home/IndexPage.dart';
  4. import 'package:chat/home/VipPage.dart';
  5. import 'package:chat/utils/CustomUI.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:oktoast/oktoast.dart';
  8. import '../utils/ShadowButton.dart';
  9. import '../home/EditData.dart';
  10. import 'package:flutter/services.dart';
  11. import '../home/VerificationPage.dart';
  12. import '../data/UserData.dart';
  13. import '../utils/TokenMgr.dart';
  14. import 'package:dio/dio.dart';
  15. import '../utils/HttpUtil.dart';
  16. import 'GetRegisterCodePage.dart';
  17. import '../utils/MessageMgr.dart';
  18. import 'package:chat/models/money_change.dart';
  19. import 'package:provider/provider.dart';
  20. class WelcomePage extends StatefulWidget {
  21. WelcomePage({Key key, bool flag}) : super(key: key);
  22. _WelcomePageState createState() => _WelcomePageState();
  23. }
  24. class _WelcomePageState extends State<WelcomePage> {
  25. List registerList = [];
  26. String registerCode = '';
  27. bool isCanApplay = true;
  28. @override
  29. void initState() {
  30. super.initState();
  31. getNewData(null);
  32. MessageMgr().on('register_code', getNewData);
  33. MessageMgr().on('refresh_money', msgBuyVip);
  34. }
  35. msgBuyVip(data) {
  36. HttpUtil().getWealth(context, (data) {
  37. if (mounted) {
  38. Provider.of<MoneyChangeProvider>(context).initMoney(data['CoinValue']);
  39. }
  40. });
  41. }
  42. initList(resData) {
  43. if (resData != null) {
  44. registerList = resData;
  45. }
  46. isCanApplay = true;
  47. for (int i = 0; i < registerList.length; i++) {
  48. if (registerList[i]['Status'] == 0 || registerList[i]['Status'] == 1) {
  49. isCanApplay = false;
  50. break;
  51. }
  52. }
  53. setState(() {});
  54. }
  55. void getNewData(data) {
  56. getRegisterState(initList);
  57. }
  58. @override
  59. void dispose() {
  60. MessageMgr().off('register_code', getNewData);
  61. MessageMgr().off('refresh_money', msgBuyVip);
  62. super.dispose();
  63. }
  64. @override
  65. Widget build(BuildContext context) {
  66. Widget appBar = new AppBar(
  67. elevation: 1,
  68. // leading: IconButton(
  69. // onPressed: () {
  70. // HttpUtil().clearCacheData();
  71. // Navigator.of(context).pushAndRemoveUntil(new MaterialPageRoute(
  72. // builder: (context) {
  73. // return IndexPage();
  74. // },
  75. // ), (route) => route == null);
  76. // },
  77. // icon: Icon(Icons.arrow_back),
  78. // ),
  79. leading: CustomUI.buildCustomLeading(context, onTap: () {
  80. HttpUtil().clearCacheData();
  81. Navigator.of(context).pushAndRemoveUntil(new MaterialPageRoute(
  82. builder: (context) {
  83. return IndexPage();
  84. },
  85. ), (route) => route == null);
  86. }),
  87. title: new Text(
  88. I18n.of(context).welcome,
  89. textScaleFactor: 1.0,
  90. ),
  91. centerTitle: true,
  92. );
  93. return Scaffold(
  94. body: SafeArea(
  95. child: Center(
  96. child: Container(
  97. height: MediaQuery.of(context).size.height,
  98. width: MediaQuery.of(context).size.width,
  99. child: _buildBody(),
  100. ),
  101. )),
  102. appBar: appBar,
  103. resizeToAvoidBottomPadding: false,
  104. );
  105. }
  106. Widget _buildBody() {
  107. return SingleChildScrollView(
  108. child: Column(
  109. children: <Widget>[
  110. Container(
  111. margin: EdgeInsets.only(top: 10),
  112. width: double.infinity,
  113. color: Colors.white,
  114. child: Column(
  115. children: <Widget>[
  116. _buildTopTips(),
  117. _buildInput(),
  118. _buildRegisterButton(),
  119. ],
  120. ),
  121. ),
  122. Container(
  123. margin: EdgeInsets.only(top: 59, bottom: 8.5),
  124. child: Text(
  125. I18n.of(context).how_get,
  126. style: TextStyle(fontSize: 11.59, color: Constants.GreyTextColor),
  127. ),
  128. ),
  129. _buildBottom(),
  130. ],
  131. ),
  132. );
  133. }
  134. void getRegisterState(callback) async {
  135. Map data = {
  136. "userId": UserData().basicInfo.userId,
  137. };
  138. data['sign'] = TokenMgr().getSign(data);
  139. try {
  140. Response res = await HttpUtil().post('user/apply/records', data: data);
  141. var resData = res.data;
  142. print(resData);
  143. if (resData['code'] == 0) {
  144. callback(resData['data']);
  145. } else {
  146. showToast(resData['msg']);
  147. }
  148. } catch (e) {}
  149. }
  150. Widget _buildTopTips() {
  151. return Container(
  152. margin: EdgeInsets.only(top: 22),
  153. child: Column(
  154. children: <Widget>[
  155. Text(
  156. I18n.of(context).enter_incode,
  157. textScaleFactor: 1.0,
  158. style: TextStyle(fontWeight: FontWeight.normal, fontSize: 16),
  159. ),
  160. SizedBox(height: 8),
  161. Text(
  162. I18n.of(context).must_incode,
  163. textScaleFactor: 1.0,
  164. style: TextStyle(color: const Color(0xFFC3C3C3), fontSize: 11.53),
  165. )
  166. ],
  167. ),
  168. );
  169. }
  170. Widget _buildRegisterButton() {
  171. Text text = new Text(I18n.of(context).determine,
  172. textScaleFactor: 1.0,
  173. style: TextStyle(fontSize: 15, color: Colors.white));
  174. LinearGradient gradientColor = new LinearGradient(colors: <Color>[
  175. Constants.ConfrimButtonColor,
  176. Constants.ConfrimButtonColor,
  177. ]);
  178. callback() async {
  179. if (registerCode == null || registerCode == '') {
  180. showToast(I18n.of(context).enter_incode);
  181. return;
  182. }
  183. var data = {
  184. "UserId": UserData().basicInfo.userId,
  185. "Code": registerCode,
  186. };
  187. data['sign'] = TokenMgr().getSign(data);
  188. try {
  189. Response res = await HttpUtil().post('user/register/code', data: data);
  190. var resData = res.data;
  191. print(resData);
  192. if (resData['code'] == 0) {
  193. Navigator.of(context).push(
  194. new MaterialPageRoute(
  195. builder: (context) {
  196. return EditPage(
  197. isEditPage: false,
  198. );
  199. },
  200. ),
  201. );
  202. } else {
  203. showToast(resData['msg']);
  204. }
  205. } catch (e) {}
  206. }
  207. return new Container(
  208. margin: EdgeInsets.only(top: 36, left: 34, right: 34, bottom: 50),
  209. height: 42.7,
  210. child: ShadowButton().builder(gradientColor, text, callback),
  211. );
  212. }
  213. Widget _buildInput() {
  214. return Container(
  215. margin: EdgeInsets.only(top: 34, left: 34, right: 34),
  216. child: TextField(
  217. keyboardAppearance: Brightness.light,
  218. onChanged: (str) {
  219. registerCode = str;
  220. },
  221. textAlign: TextAlign.center,
  222. inputFormatters: [
  223. WhitelistingTextInputFormatter.digitsOnly,
  224. LengthLimitingTextInputFormatter(6)
  225. ],
  226. style: TextStyle(textBaseline: TextBaseline.alphabetic),
  227. decoration: InputDecoration(
  228. hintText: I18n.of(context).your_incode,
  229. hintStyle: TextStyle(fontSize: 19.21, color: const Color(0xFFB4B4B4)),
  230. contentPadding: EdgeInsets.all(10.0),
  231. border: OutlineInputBorder(
  232. borderRadius: BorderRadius.circular(30.0),
  233. ),
  234. ),
  235. ),
  236. );
  237. }
  238. Widget _buildBottom() {
  239. return Container(
  240. child: Column(
  241. mainAxisAlignment: MainAxisAlignment.end,
  242. children: <Widget>[
  243. _buildBottomItemFirst(),
  244. _buildBottomItemSecond(),
  245. ],
  246. ),
  247. );
  248. }
  249. Widget _buildBottomItemFirst() {
  250. double leftPadding = 30;
  251. register() async {
  252. Navigator.of(context).push(
  253. new MaterialPageRoute(
  254. builder: (context) {
  255. return GetRegisterCodePage();
  256. },
  257. ),
  258. );
  259. }
  260. var color = isCanApplay ? const Color(0xFF2D81FF) : Colors.grey;
  261. Widget left = Container(
  262. padding: EdgeInsets.only(left: leftPadding),
  263. width: MediaQuery.of(context).size.width * 0.6,
  264. child: Column(
  265. children: <Widget>[
  266. Container(
  267. padding: EdgeInsets.only(top: 10),
  268. alignment: Alignment.centerLeft,
  269. child: Text(
  270. I18n.of(context).free,
  271. textScaleFactor: 1.0,
  272. style: TextStyle(
  273. fontSize: 14,
  274. fontWeight: FontWeight.w500,
  275. color: Constants.BlackTextColor),
  276. ),
  277. ),
  278. Container(
  279. padding: EdgeInsets.only(top: 4),
  280. alignment: Alignment.centerLeft,
  281. child: Text(
  282. I18n.of(context).so_get,
  283. textScaleFactor: 1.0,
  284. style: TextStyle(color: const Color(0xFF949494), fontSize: 13),
  285. ),
  286. ),
  287. ],
  288. ),
  289. );
  290. Widget right = new Container(
  291. padding: EdgeInsets.only(top: 10),
  292. width: MediaQuery.of(context).size.width * 0.4,
  293. child: Column(
  294. children: <Widget>[
  295. InkWell(
  296. onTap: isCanApplay ? register : null,
  297. child: Container(
  298. padding:
  299. EdgeInsets.only(top: 5, left: 20, right: 20, bottom: 5),
  300. decoration: BoxDecoration(
  301. border: Border.all(color: color, width: 1),
  302. color: Colors.white,
  303. borderRadius: BorderRadius.all(Radius.circular(30))),
  304. child: Text(
  305. isCanApplay
  306. ? I18n.of(context).apply_now
  307. : I18n.of(context).already_applied,
  308. textScaleFactor: 1.0,
  309. style: TextStyle(color: color),
  310. ),
  311. )),
  312. InkWell(
  313. onTap: () {
  314. getRegisterState((data) {
  315. initList(data);
  316. Navigator.of(context).push(
  317. new MaterialPageRoute(
  318. builder: (context) {
  319. return VerificationPage(
  320. applyList: data == null ? [] : data,
  321. );
  322. },
  323. ),
  324. );
  325. });
  326. },
  327. child: Align(
  328. child: Container(
  329. padding: EdgeInsets.only(right: 25, top: 10),
  330. child: Row(
  331. mainAxisAlignment: MainAxisAlignment.end,
  332. children: <Widget>[
  333. Text(
  334. I18n.of(context).check_incode,
  335. textScaleFactor: 1.0,
  336. style: TextStyle(color: Colors.red, fontSize: 13),
  337. ),
  338. Icon(
  339. IconData(0xe63c, fontFamily: 'iconfont'),
  340. size: 18.0,
  341. color: Colors.red,
  342. //color: const Color(0xFF2D81FF),
  343. ),
  344. ],
  345. ),
  346. ),
  347. ),
  348. )
  349. ],
  350. ),
  351. );
  352. return Container(
  353. padding: EdgeInsets.only(bottom: 20),
  354. margin: EdgeInsets.only(bottom: 10),
  355. color: Colors.white,
  356. child: Column(
  357. children: <Widget>[
  358. Container(
  359. alignment: Alignment.centerLeft,
  360. padding: EdgeInsets.only(left: leftPadding, top: 2, bottom: 2),
  361. width: double.infinity,
  362. child: Text(
  363. I18n.of(context).method1,
  364. style: TextStyle(
  365. fontSize: 15,
  366. fontWeight: FontWeight.w500,
  367. color: Constants.BlackTextColor),
  368. ),
  369. decoration: BoxDecoration(
  370. border: Border(
  371. bottom: BorderSide(color: const Color(0xFFF3F3F3)))),
  372. ),
  373. Row(
  374. children: <Widget>[left, right],
  375. ),
  376. ],
  377. ));
  378. }
  379. Widget _buildBottomItemSecond() {
  380. double leftPadding = 30;
  381. Widget left = Container(
  382. padding: EdgeInsets.only(left: leftPadding),
  383. width: MediaQuery.of(context).size.width * 0.6,
  384. child: Column(
  385. children: <Widget>[
  386. Container(
  387. padding: EdgeInsets.only(top: 10),
  388. alignment: Alignment.centerLeft,
  389. child: Text(
  390. I18n.of(context).joinvip,
  391. textScaleFactor: 1.0,
  392. style: TextStyle(
  393. fontSize: 14,
  394. fontWeight: FontWeight.w500,
  395. color: Constants.BlackTextColor),
  396. ),
  397. ),
  398. Container(
  399. padding: EdgeInsets.only(top: 4),
  400. alignment: Alignment.centerLeft,
  401. child: Text(
  402. I18n.of(context).join_odds,
  403. textScaleFactor: 1.0,
  404. style: TextStyle(color: const Color(0xFF949494), fontSize: 13),
  405. ),
  406. ),
  407. ],
  408. ),
  409. );
  410. Widget right = new Container(
  411. width: MediaQuery.of(context).size.width * 0.4,
  412. child: Column(
  413. children: <Widget>[
  414. InkWell(
  415. onTap: () {
  416. Navigator.of(context).push(
  417. new MaterialPageRoute(
  418. builder: (context) {
  419. return UserData().isVip
  420. ? EditPage(
  421. isEditPage: false,
  422. )
  423. : VipPage();
  424. },
  425. ),
  426. );
  427. },
  428. child: Container(
  429. padding:
  430. EdgeInsets.only(top: 5, left: 15, right: 15, bottom: 5),
  431. decoration: BoxDecoration(
  432. border:
  433. Border.all(color: const Color(0xFF2D81FF), width: 1),
  434. color: Colors.white,
  435. borderRadius: BorderRadius.all(Radius.circular(30))),
  436. child: Text(
  437. UserData().isVip
  438. ? I18n.of(context).joined
  439. : I18n.of(context).join_now,
  440. textScaleFactor: 1.0,
  441. style: TextStyle(color: const Color(0xFF2D81FF)),
  442. ),
  443. )),
  444. // UserData().isVip
  445. // ? InkWell(
  446. // onTap: () {
  447. // Navigator.of(context).push(
  448. // new MaterialPageRoute(
  449. // builder: (context) {
  450. // return EditPage(
  451. // isEditPage: false,
  452. // );
  453. // },
  454. // ),
  455. // );
  456. // },
  457. // child: Align(
  458. // child: Container(
  459. // padding: EdgeInsets.only(
  460. // right: MediaQuery.of(context).size.width * 0.1,
  461. // top: 10),
  462. // child: Row(
  463. // mainAxisAlignment: MainAxisAlignment.end,
  464. // children: <Widget>[
  465. // Text(
  466. // I18n.of(context).joined,
  467. // textScaleFactor: 1.0,
  468. // style: TextStyle(
  469. // color: const Color(0xFFB4B4B4), fontSize: 13),
  470. // ),
  471. // Text(
  472. // '>',
  473. // textScaleFactor: 1.0,
  474. // style: TextStyle(color: const Color(0xFFF6C5CC)),
  475. // )
  476. // ],
  477. // ),
  478. // ),
  479. // ),
  480. // )
  481. // : Container(
  482. // height: 13,
  483. // ),
  484. Container(
  485. height: 13,
  486. )
  487. ],
  488. ),
  489. );
  490. return Container(
  491. padding: EdgeInsets.only(bottom: 20),
  492. margin: EdgeInsets.only(bottom: 10),
  493. color: Colors.white,
  494. child: Column(
  495. children: <Widget>[
  496. Container(
  497. alignment: Alignment.centerLeft,
  498. padding: EdgeInsets.only(left: leftPadding, top: 2, bottom: 2),
  499. width: double.infinity,
  500. child: Text(
  501. I18n.of(context).method2,
  502. style: TextStyle(
  503. fontSize: 15,
  504. fontWeight: FontWeight.w500,
  505. color: Constants.BlackTextColor),
  506. ),
  507. decoration: BoxDecoration(
  508. border: Border(
  509. bottom: BorderSide(color: const Color(0xFFF3F3F3)))),
  510. ),
  511. Row(
  512. children: <Widget>[left, right],
  513. ),
  514. ],
  515. ));
  516. }
  517. }