Hibok
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

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