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.
 
 
 
 
 
 

1034 rivejä
32 KiB

  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:chat/data/UserData.dart';
  3. import 'package:chat/data/constants.dart';
  4. import 'package:chat/generated/i18n.dart';
  5. import 'package:chat/home/MyDialogContent.dart';
  6. import 'package:chat/home/SelectPage.dart';
  7. import 'package:chat/utils/CustomUI.dart';
  8. import 'package:chat/utils/HttpUtil.dart';
  9. import 'package:chat/utils/MessageMgr.dart';
  10. import 'package:chat/utils/screen.dart';
  11. import 'package:dio/dio.dart';
  12. import 'package:flutter/material.dart';
  13. import 'package:city_pickers/city_pickers.dart';
  14. import 'package:flutter/services.dart';
  15. import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
  16. import 'package:image_cropper/image_cropper.dart';
  17. import 'package:oktoast/oktoast.dart';
  18. import 'package:url_launcher/url_launcher.dart';
  19. import '../utils/ShadowButton.dart';
  20. import 'package:image_picker/image_picker.dart';
  21. import 'dart:io';
  22. import '../data/UserData.dart';
  23. import '../utils/TokenMgr.dart';
  24. import '../data/WebData.dart';
  25. import 'IndexPage.dart';
  26. import 'UserAgreement.dart';
  27. const double TipLeft = 20;
  28. const double BorderLeft = 25;
  29. const double LeftTextFontSize = 13;
  30. const LetfTextStyle = TextStyle(
  31. fontSize: LeftTextFontSize,
  32. fontWeight: FontWeight.w600,
  33. color: Constants.BlackTextColor);
  34. class EditPage extends StatefulWidget {
  35. @required
  36. final bool isEditPage;
  37. EditPage({Key key, this.isEditPage = false}) : super(key: key);
  38. _EditPageState createState() => _EditPageState();
  39. }
  40. class _EditPageState extends State<EditPage> {
  41. //职业
  42. String profession = '';
  43. Set<String> professionId = Set.from([
  44. UserData().basicInfo.occupation == null
  45. ? 'Information-Internet'
  46. : UserData().basicInfo.occupation
  47. ]);
  48. //国家
  49. String country = '';
  50. Set<String> countryId = Set.from([
  51. UserData().basicInfo.country == null
  52. ? 'Country-VietNam'
  53. : 'Country-${UserData().basicInfo.country}'
  54. ]);
  55. //期待对象
  56. String lovePeople = '';
  57. Set<String> lovePeopleId = Set.from(UserData().basicInfo.hopeObject == null
  58. ? ['Indifferent']
  59. : UserData().basicInfo.hopeObject.split(','));
  60. //是否展示社交账号
  61. bool isHiddenSocialAccount = UserData().basicInfo.accountStatus == 1;
  62. //昵称
  63. String nickname = UserData().basicInfo.nickName;
  64. //约会范围
  65. String dateRange = '';
  66. Set<String> dateRangeId = Set.from(UserData().basicInfo.meetPlace == null
  67. ? [UserData().currentCity]
  68. : UserData().basicInfo.meetPlace.split(','));
  69. //生日
  70. String birthday = '';
  71. String birthdayId = UserData().basicInfo.birthday == null
  72. ? '1995-01-01'
  73. : UserData().basicInfo.birthday;
  74. //身高数据
  75. String heightStr = '';
  76. String heightId = UserData().basicInfo.height == null
  77. ? '0'
  78. : UserData().basicInfo.height.toInt().toString();
  79. //体重数据
  80. String weightStr = '';
  81. String weightId = UserData().basicInfo.weight == null
  82. ? '0'
  83. : UserData().basicInfo.weight.toInt().toString();
  84. //是否同意用户协议
  85. bool isAgree = false;
  86. File headFile;
  87. bool loadSuccess = false;
  88. String wechat = UserData().basicInfo.wechat;
  89. String facebook = UserData().basicInfo.facebook;
  90. TextEditingController nickNameController =
  91. new TextEditingController(text: UserData().basicInfo.nickName);
  92. TextEditingController mymsgController =
  93. new TextEditingController(text: UserData().basicInfo.ownMsg);
  94. TextEditingController wechatController =
  95. new TextEditingController(text: UserData().basicInfo.wechat);
  96. TextEditingController fbController =
  97. new TextEditingController(text: UserData().basicInfo.facebook);
  98. initValue() {
  99. if (!loadSuccess) {
  100. profession = WebData().getProffesionName(professionId.first);
  101. if (!widget.isEditPage) {
  102. switch (UserData().language) {
  103. case LanguageType.English:
  104. countryId = Set.from(['Country-UnitedStates']);
  105. break;
  106. case LanguageType.Vietnamese:
  107. countryId = Set.from(['Country-VietNam']);
  108. break;
  109. case LanguageType.TraditionalChinese:
  110. case LanguageType.TraditionalChinese:
  111. countryId = Set.from(['Country-China']);
  112. break;
  113. case LanguageType.Korean:
  114. countryId = Set.from(['Country-Korea']);
  115. break;
  116. case LanguageType.Japanese:
  117. countryId = Set.from(['Country-Japan']);
  118. break;
  119. default:
  120. }
  121. }
  122. country = WebData().getCountry(countryId.first.split('-')[1]);
  123. var hopeObject = '';
  124. lovePeopleId.forEach((f) => hopeObject += hopeObject == '' ? f : ',$f');
  125. lovePeople = WebData().getLovePeople(hopeObject);
  126. var dateRangeStr = '';
  127. dateRangeId
  128. .forEach((f) => dateRangeStr += dateRangeStr == '' ? f : ',$f');
  129. dateRange = WebData().getDateRange(dateRangeStr);
  130. birthday = birthdayId;
  131. heightStr = (UserData().basicInfo.height == 0.0 ||
  132. UserData().basicInfo.height == null)
  133. ? I18n.of(context).not_show
  134. : '${UserData().basicInfo.height.toInt()}CM';
  135. weightStr = (UserData().basicInfo.weight == 0.0 ||
  136. UserData().basicInfo.weight == null)
  137. ? I18n.of(context).not_show
  138. : '${UserData().basicInfo.weight.toInt()}KG';
  139. loadSuccess = true;
  140. setState(() {});
  141. }
  142. }
  143. BoxDecoration _getCardDecoration() {
  144. return new BoxDecoration(
  145. color: Colors.white,
  146. border: Border(
  147. top: Constants.GreyBorderSide, bottom: Constants.GreyBorderSide));
  148. }
  149. @override
  150. void initState() {
  151. super.initState();
  152. MessageMgr().on('change_currentcity', changeCurrentcity);
  153. print('EditPage initState');
  154. }
  155. changeCurrentcity(data) {
  156. if (!widget.isEditPage && dateRangeId.length == 0) {
  157. var dateRangeStr = '';
  158. dateRangeId = Set.from([UserData().currentCity]);
  159. dateRangeId
  160. .forEach((f) => dateRangeStr += dateRangeStr == '' ? f : ',$f');
  161. dateRange = WebData().getDateRange(dateRangeStr);
  162. setState(() {});
  163. }
  164. }
  165. @override
  166. void dispose() {
  167. nickNameController.dispose();
  168. mymsgController.dispose();
  169. MessageMgr().on('change_currentcity', changeCurrentcity);
  170. super.dispose();
  171. }
  172. _showDialog() {
  173. CustomUI.buildOneConfirm(
  174. context, I18n.of(context).exit_registration, I18n.of(context).determine,
  175. () {
  176. HttpUtil().clearCacheData();
  177. Navigator.of(context).pushAndRemoveUntil(new MaterialPageRoute(
  178. builder: (context) {
  179. return IndexPage();
  180. },
  181. ), (route) => route == null);
  182. });
  183. }
  184. Future<bool> _requestPop() {
  185. if (!widget.isEditPage) {
  186. _showDialog();
  187. } else {
  188. Navigator.of(context).pop();
  189. }
  190. return new Future.value(false);
  191. }
  192. @override
  193. Widget build(BuildContext context) {
  194. initValue();
  195. var keyHeight = MediaQuery.of(context).viewInsets.bottom;
  196. if (keyHeight > 0) {
  197. UserData().setKeyboardHeight(keyHeight);
  198. }
  199. Widget appBar = new AppBar(
  200. backgroundColor: AppColors.NewAppbarBgColor,
  201. title: new Text(
  202. widget.isEditPage
  203. ? I18n.of(context).edit_information
  204. : I18n.of(context).complete_material,
  205. textScaleFactor: 1.0,
  206. style: TextStyle(color: AppColors.NewAppbarTextColor),
  207. ),
  208. elevation: 1,
  209. leading: CustomUI.buildCustomLeading(context),
  210. actions: <Widget>[
  211. widget.isEditPage
  212. ? Container(
  213. alignment: Alignment.center,
  214. child: new InkWell(
  215. child: new Padding(
  216. padding: EdgeInsets.only(
  217. right: 15, left: 15, top: 10, bottom: 10),
  218. child: new Text(
  219. I18n.of(context).save,
  220. textScaleFactor: 1.0,
  221. style: TextStyle(color: Constants.BlueTextColor),
  222. ),
  223. ),
  224. onTap: () {
  225. postSettion((data) {
  226. showToast(I18n.of(context).successfully_saved);
  227. Navigator.of(context).pop();
  228. MessageMgr().emit('update_data', data);
  229. });
  230. },
  231. ),
  232. )
  233. : Container(),
  234. ],
  235. centerTitle: true);
  236. return WillPopScope(
  237. onWillPop: _requestPop,
  238. child: Scaffold(
  239. backgroundColor: const Color(0xFFEDEDED),
  240. body: SafeArea(
  241. child: Center(
  242. child: Container(
  243. height: MediaQuery.of(context).size.height,
  244. width: MediaQuery.of(context).size.width,
  245. child: _buildBody(),
  246. ),
  247. )),
  248. appBar: appBar,
  249. ));
  250. }
  251. Widget _buildBody() {
  252. List<Widget> body = [
  253. _buildHeadUrl(),
  254. _buildBasicData(context),
  255. UserData().isMan() ? Container() : _buildSocialContact(),
  256. // _buildHiddenButtom(),
  257. // _buildMoreInfo(),
  258. _buildCommitButton(),
  259. ];
  260. List<Widget> body2 = [
  261. _buildBasicData(context),
  262. _buildSocialContact(),
  263. _buildHiddenButtom(),
  264. _buildMoreInfo(),
  265. ];
  266. return new ListView(
  267. children: widget.isEditPage ? body2 : body,
  268. );
  269. }
  270. Widget _buildCommitButton() {
  271. return new Column(
  272. children: <Widget>[
  273. _buildRegisterButton(),
  274. _buildAgreement(),
  275. ],
  276. );
  277. }
  278. Widget _buildAgreement() {
  279. return InkWell(
  280. onTap: () async {
  281. // Navigator.of(context).push(
  282. // new MaterialPageRoute(
  283. // builder: (context) {
  284. // return UserAgreement();
  285. // },
  286. // ),
  287. // );
  288. launch(
  289. 'http://datechatagent.chengyouhd.com/zh-CN/Home/UserAgreement?language=${UserData().language}');
  290. },
  291. child: Container(
  292. margin: EdgeInsets.only(top: 10, bottom: 20, left: 10, right: 10),
  293. child: Text(
  294. I18n.of(context).agreed_agreement,
  295. style: TextStyle(color: Colors.red),
  296. textAlign: TextAlign.center,
  297. )));
  298. }
  299. postSettion(callback) async {
  300. if (nickname == null || nickname == "" || nickname.length > 25) {
  301. showToast(I18n.of(context).only1_8);
  302. return;
  303. }
  304. if (dateRangeId.length == 0 && UserData().hasLocationPermission) {
  305. showToast(I18n.of(context).Please_select_a_resident_city);
  306. return;
  307. }
  308. if (birthdayId == null || birthdayId == '0') {
  309. showToast(I18n.of(context).choose_birthday);
  310. return;
  311. }
  312. if (professionId.length == 0) {
  313. showToast(I18n.of(context).choose_career);
  314. return;
  315. }
  316. if (countryId.length == 0) {
  317. showToast(I18n.of(context).select_program);
  318. return;
  319. }
  320. if (lovePeopleId.length == 0) {
  321. showToast(I18n.of(context).choose_lover);
  322. return;
  323. }
  324. if (!UserData().isMan() &&
  325. (wechat == null || wechat == '') &&
  326. (facebook == null || facebook == '')) {
  327. showToast(I18n.of(context).least_account);
  328. return;
  329. }
  330. var program = '';
  331. var hopeObject = '';
  332. lovePeopleId.forEach((f) => hopeObject += hopeObject == '' ? f : ',$f');
  333. var dateRangeStr = '';
  334. dateRangeId.forEach((f) => dateRangeStr += dateRangeStr == '' ? f : ',$f');
  335. Map data = {
  336. "userId": UserData().basicInfo.userId,
  337. "nickName": nickname,
  338. "birthday": birthdayId,
  339. };
  340. data['sign'] = TokenMgr().getSign(data);
  341. data["occupation"] = professionId.first;
  342. data["program"] = program;
  343. data["hopeObject"] = hopeObject;
  344. data["height"] = heightId;
  345. data['Country'] = countryId.first.split('-')[1];
  346. data["weight"] = weightId;
  347. data["ownMsg"] = mymsgController.text.trim();
  348. data["meetPlace"] = dateRangeStr;
  349. data['wxAccount'] = wechat;
  350. data['fbAccount'] = facebook;
  351. data['accountStatus'] = isHiddenSocialAccount ? 1 : 0;
  352. data["lat"] = UserData().latitude;
  353. data["lng"] = UserData().longitude;
  354. try {
  355. Response res = await HttpUtil()
  356. .post('user/complete/material', data: data, isShowLoading: true);
  357. Map resData = res.data;
  358. if (resData['code'] == 0) {
  359. UserData().basicInfo.ownMsg = mymsgController.text;
  360. callback(mymsgController.text);
  361. } else {
  362. showToast(resData['msg']);
  363. }
  364. } catch (e) {}
  365. }
  366. //构建注册按钮
  367. Widget _buildRegisterButton() {
  368. Text text =
  369. fixedText(I18n.of(context).submit, fontSize: 15, color: Colors.white);
  370. LinearGradient gradientColor = new LinearGradient(colors: <Color>[
  371. Constants.ConfrimButtonColor,
  372. Constants.ConfrimButtonColor,
  373. ]);
  374. callback() {
  375. postSettion((data) async {
  376. Navigator.of(context)
  377. .pushNamedAndRemoveUntil('/main', (route) => route == null);
  378. });
  379. }
  380. return new Container(
  381. margin: EdgeInsets.only(top: 20),
  382. height: 44,
  383. width: MediaQuery.of(context).size.width * 0.85,
  384. child: ShadowButton().builder(gradientColor, text, callback),
  385. );
  386. }
  387. //自定义item
  388. Widget _bottomBorderBox(String textLeft, String textRight, bool flag,
  389. controller, bool isInit, callback,
  390. {inputFormatters}) {
  391. Widget left = Container(
  392. width: 90,
  393. margin: EdgeInsets.only(right: 10),
  394. child: Text(
  395. textLeft,
  396. textScaleFactor: 1.0,
  397. style: LetfTextStyle,
  398. ));
  399. Widget right = flag
  400. ? Expanded(
  401. child: TextField(
  402. keyboardAppearance: Brightness.light,
  403. controller: controller,
  404. style: TextStyle(
  405. fontSize: 14, textBaseline: TextBaseline.alphabetic),
  406. decoration: InputDecoration(
  407. contentPadding: EdgeInsets.zero,
  408. hintText: textRight,
  409. hintStyle: TextStyle(
  410. fontSize: 14,
  411. color: Constants.LightGreyTextColor,
  412. fontWeight: FontWeight.normal),
  413. border: InputBorder.none,
  414. ),
  415. maxLines: 1,
  416. inputFormatters: inputFormatters,
  417. onChanged: (str) {
  418. if (flag && callback != null) callback(str);
  419. },
  420. ),
  421. )
  422. : Expanded(
  423. child: Text(
  424. textRight,
  425. textScaleFactor: 1.0,
  426. style: TextStyle(
  427. fontSize: 14,
  428. color: !isInit
  429. ? Constants.LightGreyTextColor
  430. : Constants.BlackTextColor),
  431. ),
  432. );
  433. var icon = !flag
  434. ? Padding(
  435. padding: EdgeInsets.only(right: 7),
  436. child: Icon(
  437. IconData(0xe63c, fontFamily: 'iconfont'),
  438. size: 20.0,
  439. color: Color(AppColors.TabIconNormal),
  440. ))
  441. : Container();
  442. return new InkWell(
  443. highlightColor: Colors.transparent,
  444. radius: 0.0,
  445. onTap: () {
  446. if (!flag && callback != null) callback();
  447. },
  448. child: Container(
  449. height: 53,
  450. margin: EdgeInsets.only(left: BorderLeft, bottom: 0),
  451. child: new Row(
  452. children: <Widget>[left, right, icon],
  453. ),
  454. ));
  455. }
  456. //下划线
  457. Widget _buildDivider() {
  458. return new Container(
  459. margin: EdgeInsets.zero,
  460. padding: EdgeInsets.zero,
  461. height: 1,
  462. width: MediaQuery.of(context).size.width,
  463. child: new Divider(
  464. color: Colors.grey[300],
  465. ),
  466. );
  467. }
  468. //基本数据
  469. Widget _buildBasicData(context) {
  470. Widget tip = CustomUI.buildTopTip(
  471. BorderLeft, I18n.of(context).basic_information,
  472. showStar: true);
  473. //选择约会地区
  474. void selectDateRange() async {
  475. print(WebData().provinces['China']);
  476. Navigator.of(context).push(
  477. new MaterialPageRoute(
  478. builder: (context) {
  479. return SelectPage(
  480. mostNum: 1,
  481. dataId: dateRangeId,
  482. title: I18n.of(context).Resident_city,
  483. provinces: UserData().isInChina
  484. ? {'China': WebData().provinces['China']}
  485. : {
  486. 'VietNam': WebData().provinces['VietNam'],
  487. },
  488. cities: WebData().cities,
  489. isSingle: true,
  490. callback: (tempRankId) {
  491. if (tempRankId.length == 0) return;
  492. dateRangeId = tempRankId.toSet();
  493. if (dateRangeId.length != 0) {
  494. dateRange = '';
  495. dateRangeId.forEach((item) {
  496. var city = item.split('-');
  497. dateRange += dateRange == ''
  498. ? WebData().cities[city[0]][city[1]]
  499. : '/${WebData().cities[city[0]][city[1]]}';
  500. });
  501. }
  502. Navigator.of(context).pop();
  503. },
  504. );
  505. },
  506. ),
  507. );
  508. }
  509. //选择生日
  510. void selectDate() async {
  511. var locale;
  512. switch (UserData().language) {
  513. case LanguageType.English:
  514. locale = LocaleType.en;
  515. break;
  516. case LanguageType.Vietnamese:
  517. locale = LocaleType.vi;
  518. break;
  519. case LanguageType.TraditionalChinese:
  520. case LanguageType.SimplifiedChinese:
  521. locale = LocaleType.zh;
  522. break;
  523. case LanguageType.Korean:
  524. locale = LocaleType.ko;
  525. break;
  526. case LanguageType.Japanese:
  527. locale = LocaleType.jp;
  528. break;
  529. default:
  530. locale = LocaleType.en;
  531. }
  532. var list = [];
  533. if (birthdayId != null) list = birthdayId.split('-');
  534. var nowDate;
  535. nowDate = list.length == 3
  536. ? DateTime(int.parse(list[0]), int.parse(list[1]), int.parse(list[2]))
  537. : DateTime(1990, 1, 1);
  538. DatePicker.showDatePicker(context,
  539. showTitleActions: true,
  540. minTime: DateTime(1900, 3, 5),
  541. maxTime: DateTime(DateTime.now().year - 18, 1, 1),
  542. onChanged: (date) {}, onConfirm: (date) {
  543. birthday = '${date.year}-${date.month}-${date.day}';
  544. birthdayId = '${date.year}-${date.month}-${date.day}';
  545. setState(() {});
  546. }, currentTime: nowDate, locale: locale);
  547. }
  548. //选择职业
  549. void selectProfession() async {
  550. Navigator.of(context).push(
  551. new MaterialPageRoute(
  552. builder: (context) {
  553. return SelectPage(
  554. mostNum: 4,
  555. dataId: professionId,
  556. provinces: WebData().professionCate,
  557. isSingle: true,
  558. cities: WebData().professionList,
  559. title: I18n.of(context).choose_career,
  560. callback: (Set tempRankId) {
  561. professionId = tempRankId.toSet();
  562. if (professionId.length != 0) {
  563. profession = '';
  564. professionId.forEach((item) {
  565. var city = item.split('-');
  566. profession += profession == ''
  567. ? WebData().professionList[city[0]][city[1]]
  568. : '/${WebData().professionList[city[0]][city[1]]}';
  569. });
  570. }
  571. Navigator.of(context).pop();
  572. },
  573. );
  574. },
  575. ),
  576. );
  577. }
  578. //选择国家
  579. void selectCountry() async {
  580. Navigator.of(context).push(
  581. new MaterialPageRoute(
  582. builder: (context) {
  583. return SelectPage(
  584. mostNum: 4,
  585. dataId: countryId,
  586. title: I18n.of(context).country,
  587. provinces: {'Country': I18n.of(context).country},
  588. cities: {'Country': WebData().provinces},
  589. isSingle: true,
  590. callback: (tempRankId) {
  591. countryId = tempRankId.toSet();
  592. print('countryID ${countryId.length}');
  593. if (countryId.length != 0) {
  594. country = '';
  595. countryId.forEach((item) {
  596. var city = item.split('-');
  597. country += country == ''
  598. ? WebData().provinces[city[1]]
  599. : '/${WebData().provinces[city[1]]}';
  600. });
  601. }
  602. Navigator.of(context).pop();
  603. },
  604. );
  605. },
  606. ),
  607. );
  608. }
  609. //选择期待对象
  610. void selectLovePeople() {
  611. var tempSet = lovePeopleId.toSet();
  612. List<Widget> actions = [
  613. FlatButton(
  614. child: fixedText(I18n.of(context).close),
  615. onPressed: () {
  616. tempSet.clear();
  617. Navigator.of(context).pop();
  618. },
  619. ),
  620. FlatButton(
  621. child: fixedText(I18n.of(context).determine),
  622. onPressed: () {
  623. Navigator.of(context).pop();
  624. setState(() {
  625. lovePeopleId = tempSet.toSet();
  626. if (lovePeopleId.length != 0) {
  627. lovePeople = '';
  628. lovePeopleId.forEach((k) {
  629. lovePeople += (lovePeople == '')
  630. ? WebData().loverPeopleMap[k]
  631. : ('/' + WebData().loverPeopleMap[k]);
  632. });
  633. }
  634. });
  635. },
  636. ),
  637. ];
  638. //约会节目
  639. showDialog(
  640. context: context,
  641. builder: (BuildContext context) {
  642. return AlertDialog(
  643. title: new Align(
  644. alignment: Alignment.center,
  645. child: Text(I18n.of(context).expect_lover),
  646. ),
  647. content: new MyDialogContent(
  648. mostNum: 4,
  649. dataMap: WebData().loverPeopleMap,
  650. keyList: tempSet,
  651. ),
  652. contentPadding: EdgeInsets.only(top: 10),
  653. actions: actions,
  654. );
  655. });
  656. }
  657. Widget idItem = new InkWell(
  658. highlightColor: Colors.transparent,
  659. radius: 0.0,
  660. onTap: () {},
  661. child: Container(
  662. height: 53,
  663. margin: EdgeInsets.only(left: BorderLeft, bottom: 0),
  664. child: new Row(
  665. children: <Widget>[
  666. Container(
  667. width: 90,
  668. margin: EdgeInsets.only(right: 10),
  669. child: Text(
  670. 'ID',
  671. textScaleFactor: 1.0,
  672. style: LetfTextStyle,
  673. )),
  674. Text(
  675. UserData().basicInfo.userId.toString(),
  676. textScaleFactor: 1.0,
  677. style: TextStyle(fontSize: 14, color: Constants.GreyTextColor),
  678. )
  679. ],
  680. ),
  681. ));
  682. List<Widget> basicList = [
  683. widget.isEditPage ? idItem : Container(),
  684. _buildDivider(),
  685. _bottomBorderBox(I18n.of(context).nickname, I18n.of(context).fill_out,
  686. true, nickNameController, true, (str) => nickname = str.trim(),
  687. inputFormatters: [
  688. LengthLimitingTextInputFormatter(Constants.NameLength)
  689. ]),
  690. _buildDivider(),
  691. _bottomBorderBox(I18n.of(context).country, country, false, null,
  692. countryId.length != 0, selectCountry),
  693. _buildDivider(),
  694. _bottomBorderBox(
  695. I18n.of(context).Resident_city,
  696. !UserData().hasLocationPermission
  697. ? I18n.of(context).unknown
  698. : dateRange,
  699. false,
  700. null,
  701. dateRangeId.length != 0,
  702. UserData().hasLocationPermission ? selectDateRange : null),
  703. _buildDivider(),
  704. _bottomBorderBox(I18n.of(context).birthday, birthday, false, null,
  705. birthdayId != null, selectDate),
  706. _buildDivider(),
  707. _bottomBorderBox(I18n.of(context).job, profession, false, null,
  708. professionId.length != 0, selectProfession),
  709. // _bottomBorderBox(I18n.of(context).country, dateItem, false, null,
  710. // dateItemId.length != 0, selectCountry),
  711. _buildDivider(),
  712. _bottomBorderBox(I18n.of(context).expect_lover, lovePeople, false, null,
  713. lovePeopleId.length != 0, selectLovePeople),
  714. ];
  715. Widget basicCard = new Container(
  716. color: Colors.white,
  717. child: new Column(
  718. children: basicList,
  719. ),
  720. );
  721. return new Column(
  722. children: <Widget>[
  723. tip,
  724. basicCard,
  725. ],
  726. );
  727. }
  728. //社交账号
  729. Widget _buildSocialContact() {
  730. Widget tip = CustomUI.buildTopTip(
  731. BorderLeft, I18n.of(context).social_account,
  732. showStar: !UserData().isMan());
  733. List<Widget> basicList = [
  734. _bottomBorderBox(
  735. I18n.of(context).wechat_number,
  736. I18n.of(context).fill_out,
  737. true,
  738. wechatController,
  739. true,
  740. (str) => wechat = str.trim(),
  741. inputFormatters: [
  742. WhitelistingTextInputFormatter(RegExp("^[A-Za-z0-9]+\$")),
  743. LengthLimitingTextInputFormatter(20)
  744. ]),
  745. _buildDivider(),
  746. _bottomBorderBox(I18n.of(context).facebook, I18n.of(context).fill_out,
  747. true, fbController, true, (str) => facebook = str.trm(),
  748. inputFormatters: [
  749. WhitelistingTextInputFormatter(RegExp("^[A-Za-z0-9]+\$")),
  750. LengthLimitingTextInputFormatter(20)
  751. ]),
  752. ];
  753. Widget socialCard = new Container(
  754. color: Colors.white,
  755. child: new Column(
  756. children: basicList,
  757. ),
  758. );
  759. return new Column(
  760. children: <Widget>[tip, socialCard],
  761. );
  762. }
  763. Widget _buildHeadUrl() {
  764. double width = 95;
  765. return Container(
  766. color: Colors.white,
  767. padding: EdgeInsets.only(top: 20, bottom: 10),
  768. child: Column(
  769. children: <Widget>[
  770. InkWell(
  771. onTap: () {
  772. _sendPicture();
  773. },
  774. child: Container(
  775. width: width,
  776. height: width,
  777. child: ClipRRect(
  778. borderRadius: BorderRadius.circular(6.0),
  779. child: uploadImageUrl == null
  780. ? Image.asset(Constants.DefaultHeadImgUrl,
  781. height: width, width: width)
  782. // : Image.file(headFile, height: width, width: width),
  783. : CachedNetworkImage(
  784. imageUrl: uploadImageUrl,
  785. placeholder: CustomUI.buildImgLoding,
  786. width: width,
  787. height: width,
  788. ),
  789. ),
  790. ),
  791. ),
  792. Padding(
  793. padding: EdgeInsets.only(top: 5),
  794. child: InkWell(
  795. onTap: () {
  796. _sendPicture();
  797. },
  798. child: fixedText(
  799. I18n.of(context).upload_avatar,
  800. color: Constants.BlackTextColor,
  801. ),
  802. )),
  803. ],
  804. ),
  805. );
  806. }
  807. void _sendPicture() async {
  808. if (await CustomUI.showPhotoPermissionSetting(context)) {
  809. var tempFile = await ImagePicker.pickImage(source: ImageSource.gallery);
  810. if (tempFile != null) {
  811. //裁剪图片
  812. _cropPicture(tempFile);
  813. }
  814. }
  815. }
  816. String uploadImageUrl;
  817. void _cropPicture(tempFile) async {
  818. File croppedFile = await ImageCropper.cropImage(
  819. sourcePath: tempFile.path,
  820. aspectRatio: CropAspectRatio(ratioX: 1, ratioY: 1),
  821. );
  822. uploadImageUrl = null;
  823. if (croppedFile != null) {
  824. headFile = croppedFile;
  825. Map data = {"type": 1, "userId": UserData().basicInfo.userId};
  826. data['sign'] = TokenMgr().getSign(data);
  827. Response response = await HttpUtil()
  828. .uploadFile(headFile, data, 'upload/file/postflie', 'image');
  829. var resData = response.data;
  830. if (resData['code'] == 0 && resData['msg'] != null) {
  831. setState(() {
  832. uploadImageUrl = resData['msg'];
  833. });
  834. } else {
  835. showToast(I18n.of(context).fail);
  836. }
  837. setState(() {});
  838. } else {
  839. print('裁剪失败---');
  840. }
  841. }
  842. //是否隐藏社交账号
  843. Widget _buildHiddenButtom() {
  844. Widget left = Text(
  845. I18n.of(context).hide_account1,
  846. textScaleFactor: 1.0,
  847. style: TextStyle(fontSize: LeftTextFontSize, fontWeight: FontWeight.w500),
  848. );
  849. Widget right = new Expanded(
  850. child: Container(
  851. margin: EdgeInsets.only(right: 20),
  852. alignment: Alignment.centerRight,
  853. child: new Switch(
  854. activeTrackColor: Constants.ConfrimButtonColor.withOpacity(0.3),
  855. value: isHiddenSocialAccount,
  856. onChanged: (bool val) {
  857. setState(() {
  858. isHiddenSocialAccount = !isHiddenSocialAccount;
  859. });
  860. },
  861. )));
  862. return new Container(
  863. decoration: _getCardDecoration(),
  864. margin: EdgeInsets.only(top: 15, bottom: 0),
  865. padding: EdgeInsets.only(left: BorderLeft),
  866. height: 53,
  867. child: new Row(
  868. children: <Widget>[left, right],
  869. ),
  870. );
  871. }
  872. //更多信息
  873. Widget _buildMoreInfo() {
  874. Widget tip =
  875. CustomUI.buildTopTip(BorderLeft, I18n.of(context).more_information);
  876. //选择升高
  877. void selectHeight() async {
  878. Result temp = await CityPickers.showCityPicker(
  879. context: context,
  880. showType: ShowType.p,
  881. provincesData: WebData().heightData,
  882. citiesData: WebData().heightListData,
  883. height: 280,
  884. );
  885. setState(() {
  886. if (temp == null) return;
  887. heightStr = "${temp.provinceName}";
  888. heightId = temp.provinceId;
  889. });
  890. }
  891. //选择升高
  892. void selectWeight() async {
  893. Result temp = await CityPickers.showCityPicker(
  894. context: context,
  895. showType: ShowType.p,
  896. provincesData: WebData().weightData,
  897. citiesData: WebData().weightListData,
  898. height: 280,
  899. );
  900. setState(() {
  901. if (temp == null) return;
  902. weightStr = "${temp.provinceName}";
  903. weightId = temp.provinceId;
  904. });
  905. }
  906. //个人介绍框
  907. var myselfBox = Container(
  908. margin: EdgeInsets.only(left: BorderLeft, bottom: 0),
  909. child: Row(
  910. crossAxisAlignment: CrossAxisAlignment.start,
  911. children: <Widget>[
  912. Container(
  913. width: 90,
  914. margin: EdgeInsets.only(top: 14),
  915. child: Text(
  916. I18n.of(context).self_introduction,
  917. textScaleFactor: 1.0,
  918. style: LetfTextStyle,
  919. )),
  920. Expanded(
  921. child: TextField(
  922. keyboardAppearance: Brightness.light,
  923. controller: mymsgController,
  924. style: TextStyle(
  925. fontSize: 14,
  926. color: Constants.BlackTextColor,
  927. textBaseline: TextBaseline.alphabetic),
  928. decoration: InputDecoration(
  929. contentPadding:
  930. EdgeInsets.only(top: 14, right: 10, bottom: 10, left: 10),
  931. hintText: I18n.of(context).introduce_yourself,
  932. hintStyle: TextStyle(fontSize: 14, color: Colors.grey),
  933. border: InputBorder.none,
  934. ),
  935. maxLines: 5,
  936. inputFormatters: [LengthLimitingTextInputFormatter(50)],
  937. ),
  938. )
  939. ],
  940. ),
  941. );
  942. List<Widget> basicList = [
  943. _bottomBorderBox(I18n.of(context).height, heightStr, false, null,
  944. heightId != '0', selectHeight),
  945. _buildDivider(),
  946. _bottomBorderBox(I18n.of(context).weight, weightStr, false, null,
  947. weightId != '0', selectWeight),
  948. _buildDivider(),
  949. myselfBox,
  950. ];
  951. Widget socialCard = new Container(
  952. color: Colors.white,
  953. child: new Column(
  954. children: basicList,
  955. ),
  956. );
  957. return new Column(
  958. children: <Widget>[tip, socialCard],
  959. );
  960. }
  961. }