Hibok
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

380 líneas
13 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/utils/CustomUI.dart';
  5. import 'package:chat/utils/TutorialOverlay.dart';
  6. import 'package:flutter/material.dart';
  7. import '../utils/ShadowButton.dart';
  8. import '../home/EditData.dart';
  9. import '../data/UserData.dart';
  10. import '../utils/TokenMgr.dart';
  11. import 'package:dio/dio.dart';
  12. import '../utils/HttpUtil.dart';
  13. double opacityRate = 0.4;
  14. class SelectSex extends StatefulWidget {
  15. SelectSex({Key key}) : super(key: key);
  16. _SelectSexState createState() => _SelectSexState();
  17. }
  18. class _SelectSexState extends State<SelectSex> {
  19. int boyFlag = 1;
  20. @override
  21. Widget build(BuildContext context) {
  22. Widget appBar = new AppBar(
  23. title: new Text(I18n.of(context).who, textScaleFactor: 1.0),
  24. centerTitle: true,
  25. elevation: 0,
  26. // leading: IconButton(
  27. // onPressed: () {
  28. // HttpUtil().clearCacheData();
  29. // Navigator.of(context).pushAndRemoveUntil(new MaterialPageRoute(
  30. // builder: (context) {
  31. // return IndexPage();
  32. // },
  33. // ), (route) => route == null);
  34. // },
  35. // icon: Icon(Icons.arrow_back),
  36. // ),
  37. leading: CustomUI.buildCustomLeading(context, onTap: () {
  38. HttpUtil().clearCacheData();
  39. Navigator.of(context).pushAndRemoveUntil(new MaterialPageRoute(
  40. builder: (context) {
  41. return IndexPage();
  42. },
  43. ), (route) => route == null);
  44. }),
  45. );
  46. return Scaffold(
  47. backgroundColor: Colors.white,
  48. body: SafeArea(
  49. child: Center(
  50. child: Container(
  51. height: MediaQuery.of(context).size.height,
  52. width: MediaQuery.of(context).size.width,
  53. child: _buildBody(),
  54. ),
  55. )),
  56. appBar: appBar,
  57. );
  58. }
  59. Widget _buildBody() {
  60. return new Column(
  61. children: <Widget>[
  62. _buildTips(),
  63. _buildSex(),
  64. _buildRegisterButton(),
  65. ],
  66. );
  67. }
  68. Widget _buildTips() {
  69. return new Container(
  70. alignment: Alignment.center,
  71. child: new Text(
  72. I18n.of(context).cannot_modified,
  73. textScaleFactor: 1.0,
  74. style: TextStyle(color: const Color(0xFF787878), fontSize: 14),
  75. ),
  76. );
  77. }
  78. postSexSetting() async {
  79. var sex = this.boyFlag;
  80. Map data = {
  81. "userid": UserData().basicInfo.userId,
  82. "sex": sex,
  83. };
  84. data['sign'] = TokenMgr().getSign(data);
  85. try {
  86. Response res = await HttpUtil().post('user/setting/sex', data: data);
  87. var resData = res.data;
  88. if (resData['code'] == 0) {
  89. UserData().basicInfo.sex = sex;
  90. Navigator.of(context).pushReplacement(MaterialPageRoute(
  91. builder: (context) => EditPage(
  92. isEditPage: false,
  93. )));
  94. } else {}
  95. } catch (e) {}
  96. }
  97. Widget _buildRegisterButton() {
  98. Text text = new Text(I18n.of(context).determine,
  99. textScaleFactor: 1.0,
  100. style: TextStyle(fontSize: 15, color: Colors.white));
  101. LinearGradient gradientColor = new LinearGradient(colors: <Color>[
  102. Constants.ConfrimButtonColor,
  103. Constants.ConfrimButtonColor,
  104. ]);
  105. return new Container(
  106. margin: EdgeInsets.only(top: 10),
  107. height: 44,
  108. width: MediaQuery.of(context).size.width * 0.6,
  109. child: ShadowButton().builder(gradientColor, text, () {
  110. Navigator.of(context).push(TutorialOverlay(
  111. child: Align(
  112. child: Container(
  113. height: 192,
  114. decoration: BoxDecoration(
  115. color: Colors.white, borderRadius: BorderRadius.circular(10)),
  116. alignment: Alignment.center,
  117. width: 298,
  118. child: Column(
  119. children: <Widget>[
  120. Align(
  121. alignment: Alignment.centerRight,
  122. child: InkWell(
  123. onTap: () {
  124. Navigator.of(context).pop();
  125. },
  126. child: Container(
  127. padding: EdgeInsets.only(
  128. bottom: 10, right: 14, top: 10, left: 14),
  129. child: Icon(
  130. IconData(
  131. 0xe679,
  132. fontFamily: 'iconfont',
  133. ),
  134. size: 17,
  135. color: Colors.grey[400] //const Color(0xFF939393),
  136. )),
  137. ),
  138. ),
  139. Container(
  140. padding: EdgeInsets.only(left: 20, right: 20, top: 12),
  141. child: Text(
  142. I18n.of(context).cannot_modified,
  143. textAlign: TextAlign.center,
  144. style: TextStyle(fontSize: 18),
  145. ),
  146. ),
  147. Container(
  148. margin: EdgeInsets.only(top: 40),
  149. child: Row(
  150. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  151. children: <Widget>[
  152. InkWell(
  153. onTap: () {
  154. Navigator.of(context).pop();
  155. },
  156. child: Container(
  157. decoration: BoxDecoration(
  158. color: Colors.white,
  159. border: Border.all(
  160. color: const Color(0xFF2D81FF)),
  161. borderRadius: BorderRadius.all(
  162. Radius.circular(
  163. Constants.LittleButtonRadius))),
  164. height: 36.5,
  165. width: 93.5,
  166. alignment: Alignment.center,
  167. child: Text(
  168. I18n.of(context).cancel,
  169. style: TextStyle(
  170. fontSize: 15,
  171. color: const Color(0xFF2D81FF),
  172. ),
  173. )),
  174. ),
  175. InkWell(
  176. onTap: postSexSetting,
  177. child: Container(
  178. decoration: Constants.ConfirmBUttonBoxDecoration,
  179. height: 36.5,
  180. width: 93.5,
  181. alignment: Alignment.center,
  182. child: Text(
  183. I18n.of(context).determine,
  184. style: TextStyle(
  185. fontSize: 15,
  186. color: Colors.white,
  187. ),
  188. )),
  189. ),
  190. ],
  191. ))
  192. ],
  193. ),
  194. ),
  195. )));
  196. // CustomUI.buildOneConfirm(context, I18n.of(context).cannot_modified,
  197. // I18n.of(context).determine, postSexSetting);
  198. }),
  199. );
  200. }
  201. Widget _buildPostion(flag, color) {
  202. return Positioned(
  203. right: 0,
  204. top: 10,
  205. child: flag
  206. ? Container(
  207. padding: EdgeInsets.zero,
  208. margin: EdgeInsets.zero,
  209. decoration: BoxDecoration(shape: BoxShape.circle, color: color),
  210. child: Icon(
  211. Icons.check,
  212. color: Colors.white,
  213. size: 20,
  214. ))
  215. : Container(),
  216. );
  217. }
  218. Widget _buildSex() {
  219. Widget pictureMan = new Align(
  220. alignment: Alignment.centerLeft,
  221. child: Image.asset(
  222. 'assets/images/login/xzxb_male.png',
  223. width: MediaQuery.of(context).size.width * 0.53,
  224. ),
  225. );
  226. Widget pictureWomen = new Align(
  227. alignment: Alignment.centerRight,
  228. child: Image.asset(
  229. 'assets/images/login/xzxb_female.png',
  230. width: MediaQuery.of(context).size.width * 0.53,
  231. ),
  232. );
  233. Widget manBox = new Align(
  234. alignment: Alignment.center,
  235. child: Stack(
  236. children: <Widget>[
  237. Container(
  238. height: 100,
  239. width: 100,
  240. alignment: Alignment.center,
  241. decoration: BoxDecoration(
  242. color: Colors.white,
  243. shape: BoxShape.circle,
  244. boxShadow: boyFlag == 1
  245. ? [
  246. BoxShadow(
  247. color: const Color(0xBF045080),
  248. offset: Offset(0, 2.5),
  249. blurRadius: 4,
  250. )
  251. ]
  252. : [],
  253. border: new Border.all(color: Color(0xFF0767A4), width: 3),
  254. ),
  255. child: new InkWell(
  256. onTap: () {
  257. setState(() {
  258. boyFlag = 1;
  259. });
  260. },
  261. highlightColor: Colors.transparent,
  262. radius: 0.0,
  263. child: new Column(
  264. mainAxisAlignment: MainAxisAlignment.center,
  265. children: <Widget>[
  266. new Text(
  267. I18n.of(context).boy,
  268. textScaleFactor: 1.0,
  269. style: TextStyle(
  270. fontSize: 30, color: const Color(0xFF0767A4)),
  271. ),
  272. UserData().language == LanguageType.English
  273. ? Container()
  274. : new Text(
  275. 'Male',
  276. textScaleFactor: 1.0,
  277. style: TextStyle(
  278. fontSize: 11, color: const Color(0xFF0767A4)),
  279. )
  280. ],
  281. )),
  282. ),
  283. _buildPostion(boyFlag == 1, const Color(0xFF0767A4))
  284. ],
  285. ));
  286. Widget womanBox = Align(
  287. alignment: Alignment.center,
  288. child: Stack(children: <Widget>[
  289. InkWell(
  290. onTap: () {
  291. setState(() {
  292. boyFlag = 2;
  293. });
  294. },
  295. highlightColor: Colors.transparent,
  296. radius: 0.0,
  297. child: Container(
  298. alignment: Alignment.center,
  299. height: 100,
  300. width: 100,
  301. decoration: BoxDecoration(
  302. shape: BoxShape.circle,
  303. color: Colors.white,
  304. boxShadow: boyFlag == 2
  305. ? [
  306. BoxShadow(
  307. color: const Color(0xBF720041),
  308. offset: Offset(0, 2.5),
  309. blurRadius: 4,
  310. )
  311. ]
  312. : [],
  313. border: Border.all(color: Color(0xFFE80D89), width: 3),
  314. ),
  315. child: Column(
  316. mainAxisAlignment: MainAxisAlignment.center,
  317. children: <Widget>[
  318. Text(
  319. I18n.of(context).girl,
  320. textScaleFactor: 1.0,
  321. style:
  322. TextStyle(fontSize: 30, color: const Color(0xFFE80D89)),
  323. ),
  324. UserData().language == LanguageType.English
  325. ? Container()
  326. : Text(
  327. 'Female',
  328. textScaleFactor: 1.0,
  329. style: TextStyle(
  330. fontSize: 11, color: const Color(0xFFE80D89)),
  331. )
  332. ],
  333. )),
  334. ),
  335. _buildPostion(boyFlag == 2, const Color(0xFFE80D89))
  336. ]),
  337. );
  338. return new Stack(
  339. children: <Widget>[
  340. Opacity(
  341. opacity: boyFlag == 1 ? 1.0 : opacityRate,
  342. child: pictureMan,
  343. ),
  344. Opacity(
  345. opacity: boyFlag == 2 ? 1 : opacityRate,
  346. child: pictureWomen,
  347. ),
  348. new Column(
  349. children: <Widget>[
  350. SizedBox(height: MediaQuery.of(context).size.height * 0.68 * 0.2),
  351. Opacity(
  352. opacity: boyFlag == 1 ? 1 : opacityRate,
  353. child: manBox,
  354. ),
  355. SizedBox(height: MediaQuery.of(context).size.height * 0.68 * 0.14),
  356. Opacity(
  357. opacity: boyFlag == 2 ? 1 : opacityRate,
  358. child: womanBox,
  359. ),
  360. ],
  361. )
  362. ],
  363. );
  364. }
  365. }