Hibok
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

590 рядки
18 KiB

  1. import 'package:chat/data/WebData.dart';
  2. import 'package:chat/data/constants.dart';
  3. import 'package:chat/generated/i18n.dart';
  4. import 'package:chat/home/BindCode.dart';
  5. import 'package:chat/home/UserAgreement.dart';
  6. import 'package:chat/utils/CustomUI.dart';
  7. import 'package:chat/utils/TokenMgr.dart';
  8. import 'package:chat/utils/app_navigator.dart';
  9. import 'package:chat/utils/local_notification_util.dart';
  10. import 'package:chat/utils/receive_share_file.dart';
  11. import 'package:chat/utils/screen.dart';
  12. import 'package:chat/utils/sound_util.dart';
  13. import 'package:chat/utils/sp_utils.dart';
  14. import 'package:dio/dio.dart';
  15. import 'package:flutter/material.dart';
  16. import 'package:oktoast/oktoast.dart';
  17. import 'package:shared_preferences/shared_preferences.dart';
  18. import '../utils/FullWithButton.dart';
  19. import '../data/UserData.dart';
  20. import '../utils/HttpUtil.dart';
  21. import '../home/Registerpage.dart';
  22. import '../home/MessagePushPage.dart';
  23. import 'package:flutter_cache_manager/flutter_cache_manager.dart';
  24. import 'PravicySettingPage.dart';
  25. var cardWidth;
  26. Map<String, String> language = {
  27. "0": "English",
  28. "1": "Tiếng việt",
  29. "2": "繁體中文",
  30. "3": "简体中文",
  31. "4": "한국어",
  32. "5": "日本語"
  33. };
  34. BoxDecoration getCardDecoration() {
  35. return new BoxDecoration(
  36. color: Colors.white,
  37. );
  38. }
  39. class SystemEditPage extends StatefulWidget {
  40. SystemEditPage({Key key}) : super(key: key);
  41. SystemEditPageState createState() => SystemEditPageState();
  42. }
  43. class SystemEditPageState extends State<SystemEditPage> {
  44. static const Separate_Size = 15.0;
  45. String _selectType = UserData().language.toString();
  46. bool soundPlayMode = false;
  47. @override
  48. void initState() {
  49. super.initState();
  50. getDefaultSetting();
  51. }
  52. void getDefaultSetting() async {
  53. bool soundPlayMode =
  54. (await SPUtils.getBool(Constants.SOUND_PLAY_MODE)) ?? false;
  55. setState(() {
  56. this.soundPlayMode = soundPlayMode;
  57. });
  58. }
  59. @override
  60. Widget build(BuildContext context) {
  61. Size screenSize = MediaQuery.of(context).size;
  62. cardWidth = screenSize.width;
  63. return Scaffold(
  64. appBar: AppBar(
  65. backgroundColor: AppColors.NewAppbarBgColor,
  66. title: Text(
  67. I18n.of(context).setting2,
  68. style: TextStyle(color: AppColors.NewAppbarTextColor),
  69. textScaleFactor: 1.0,
  70. ),
  71. centerTitle: true,
  72. elevation: 1,
  73. leading: CustomUI.buildCustomLeading(context),
  74. ),
  75. body: SafeArea(
  76. child: Container(
  77. color: AppColors.BackgroundColor,
  78. height: MediaQuery.of(context).size.height,
  79. child: SingleChildScrollView(
  80. child: _buildBody(),
  81. ))));
  82. }
  83. Widget _buildBody() {
  84. return Column(
  85. children: <Widget>[
  86. SizedBox(height: Separate_Size),
  87. _buildPravice(),
  88. SizedBox(height: Separate_Size),
  89. _buildMsgSetting(),
  90. SizedBox(height: Separate_Size),
  91. _buildBasicSetting(),
  92. SizedBox(height: Separate_Size),
  93. _clearPictureSetting(),
  94. _soundPlayModeSetting(),
  95. SizedBox(height: Separate_Size),
  96. _buildUserAgreement(),
  97. _buildBindCode(),
  98. _buildMyEvaluation(),
  99. _buildVersion(),
  100. _buildHelp(),
  101. _buildHistory(),
  102. _buildRset(),
  103. SizedBox(height: Separate_Size),
  104. _buildLogout(),
  105. SizedBox(height: Separate_Size),
  106. ],
  107. );
  108. }
  109. //恢复焚阅照片
  110. Widget _buildRset() {
  111. //历史访客
  112. return Container(
  113. margin: EdgeInsets.only(top: Separate_Size),
  114. padding: EdgeInsets.symmetric(horizontal: 10),
  115. child: FullWidthButton(
  116. title: I18n.of(context)
  117. .visit_photo
  118. .replaceFirst('/s1', UserData().basicInfo.burnNum.toString()),
  119. description: I18n.of(context).recovery_photo,
  120. showDivider: false,
  121. showRightIcon: false,
  122. onPressed: () async {
  123. CustomUI.buildOneConfirm(context, I18n.of(context).confrim_recovery,
  124. I18n.of(context).determine, () async {
  125. HttpUtil().resetPhoto(() {
  126. Navigator.of(context).pop();
  127. UserData().basicInfo.burnNum = 0;
  128. setState(() {});
  129. });
  130. });
  131. },
  132. ),
  133. decoration: BoxDecoration(
  134. color: Colors.white, border: Border(top: Constants.GreyBorderSide)),
  135. );
  136. }
  137. Widget _buildHistory() {
  138. //历史访客
  139. return Container(
  140. margin: EdgeInsets.only(top: Separate_Size),
  141. padding: EdgeInsets.symmetric(horizontal: 10),
  142. child: FullWidthButton(
  143. title: I18n.of(context).historical_visitor,
  144. description: I18n.of(context)
  145. .visit_you
  146. .replaceFirst('/s1', UserData().basicInfo.accessNum.toString()),
  147. showDivider: false,
  148. showRightIcon: false,
  149. onPressed: () {},
  150. ),
  151. decoration: BoxDecoration(
  152. color: Colors.white,
  153. border: Border(
  154. top: Constants.GreyBorderSide, bottom: Constants.GreyBorderSide)),
  155. );
  156. }
  157. //有问题需要帮助
  158. Widget _buildHelp() {
  159. return Container(
  160. margin: EdgeInsets.only(top: Separate_Size),
  161. padding: EdgeInsets.symmetric(horizontal: 10),
  162. child: FullWidthButton(
  163. showRightIcon: false,
  164. title: I18n.of(context).need_help,
  165. description: I18n.of(context).need_help2,
  166. showDivider: false,
  167. onPressed: () {
  168. AppNavigator.pushServicePage(context);
  169. },
  170. ),
  171. decoration: BoxDecoration(
  172. color: Colors.white,
  173. border: Border(
  174. top: Constants.GreyBorderSide, bottom: Constants.GreyBorderSide)),
  175. );
  176. }
  177. Widget _buildVersion() {
  178. //版本
  179. return Container(
  180. margin: EdgeInsets.only(top: Separate_Size),
  181. padding: EdgeInsets.symmetric(horizontal: 10),
  182. child: FullWidthButton(
  183. showRightIcon: false,
  184. title: '${I18n.of(context).current_version} ',
  185. description: Constants.versionName,
  186. showDivider: false,
  187. onPressed: () {
  188. // VersionUtils.versionUpdate(context, fromProfileNeedShow: true);
  189. },
  190. ),
  191. decoration: BoxDecoration(
  192. color: Colors.white,
  193. border: Border(
  194. top: Constants.GreyBorderSide, bottom: Constants.GreyBorderSide)),
  195. );
  196. }
  197. Widget _buildMyEvaluation() {
  198. //版本
  199. return Container(
  200. margin: EdgeInsets.only(top: Separate_Size),
  201. padding: EdgeInsets.symmetric(horizontal: 10),
  202. child: FullWidthButton(
  203. showRightIcon: true,
  204. title: I18n.of(context).my_evaluation,
  205. showDivider: false,
  206. onPressed: () async {
  207. Map data = {
  208. "userid": UserData().basicInfo.userId,
  209. "evaluateuserid": UserData().basicInfo.userId,
  210. };
  211. data['sign'] = TokenMgr().getSign(data);
  212. Response res = await HttpUtil()
  213. .post('evaluate/user/info', data: data, isShowLoading: true);
  214. Map resData = res.data;
  215. if (resData['code'] == 0) {
  216. _buildMyEvaluate(resData['data']);
  217. }
  218. },
  219. ),
  220. decoration: BoxDecoration(
  221. color: Colors.white,
  222. border: Border(
  223. top: Constants.GreyBorderSide, bottom: Constants.GreyBorderSide)),
  224. );
  225. }
  226. void _buildMyEvaluate(data) {
  227. bool isMan = UserData().isMan();
  228. var content = Container(
  229. margin: EdgeInsets.only(top: 10.5),
  230. child: Column(
  231. children: <Widget>[
  232. Row(
  233. mainAxisAlignment: MainAxisAlignment.center,
  234. children: <Widget>[
  235. CustomUI.buildBox(
  236. data['Friendly'],
  237. isMan
  238. ? I18n.of(context).courtesy
  239. : I18n.of(context).friendly),
  240. CustomUI.buildBox(
  241. data['Interesting'], I18n.of(context).interesting),
  242. CustomUI.buildBox(data['Refreshing'], I18n.of(context).readily),
  243. ],
  244. ),
  245. SizedBox(
  246. height: 5,
  247. ),
  248. Row(
  249. mainAxisAlignment: MainAxisAlignment.center,
  250. children: <Widget>[
  251. CustomUI.buildBox(data['Patience'],
  252. isMan ? I18n.of(context).generous : I18n.of(context).patient),
  253. CustomUI.buildBox(data['Hello'],
  254. isMan ? I18n.of(context).lie : I18n.of(context).indifferent),
  255. CustomUI.buildBox(
  256. data['Unfriendly'],
  257. isMan
  258. ? I18n.of(context).unfriendly
  259. : I18n.of(context).bad_temper),
  260. ],
  261. )
  262. ],
  263. ),
  264. );
  265. CustomUI.buildTip(context, I18n.of(context).your_evaluation, content);
  266. }
  267. Widget _buildPravice() {
  268. return Container(
  269. padding: EdgeInsets.symmetric(horizontal: 10),
  270. width: cardWidth,
  271. child: FullWidthButton(
  272. title: I18n.of(context).setting,
  273. showDivider: false,
  274. onPressed: () {
  275. Navigator.of(context).push(
  276. new MaterialPageRoute(
  277. builder: (context) {
  278. return PravicySettingPage();
  279. },
  280. ),
  281. );
  282. },
  283. ),
  284. decoration: getCardDecoration(),
  285. );
  286. }
  287. //消息通知设置
  288. Widget _buildMsgSetting() {
  289. return Container(
  290. padding: EdgeInsets.symmetric(horizontal: 10),
  291. width: cardWidth,
  292. child: FullWidthButton(
  293. title: I18n.of(context).push_setting2,
  294. showDivider: false,
  295. onPressed: () {
  296. Navigator.of(context).push(
  297. new MaterialPageRoute(
  298. builder: (context) {
  299. return MessagePushPage();
  300. },
  301. ),
  302. );
  303. },
  304. ),
  305. decoration: getCardDecoration(),
  306. );
  307. }
  308. //手机号码·修改密码
  309. Widget _buildBasicSetting() {
  310. Widget telePhoneSetting = FullWidthButton(
  311. title: I18n.of(context).phone_number,
  312. description: (UserData().mobile == 0 || UserData().mobile == null)
  313. ? ''
  314. : UserData().mobile.toString(),
  315. showDivider: true,
  316. onPressed: () {
  317. if (UserData().mobile != null && UserData().mobile != 0) {
  318. CustomUI.buildOneConfirm(context, I18n.of(context).modify_choose,
  319. I18n.of(context).determine, () {
  320. Navigator.of(context).pop();
  321. Navigator.of(context).push(
  322. new MaterialPageRoute(
  323. builder: (context) {
  324. return RegisterPage(
  325. type: PageType.bindPhone.index,
  326. );
  327. },
  328. ),
  329. );
  330. });
  331. return;
  332. }
  333. Navigator.of(context).push(
  334. new MaterialPageRoute(
  335. builder: (context) {
  336. return RegisterPage(
  337. type: PageType.bindPhone.index,
  338. );
  339. },
  340. ),
  341. );
  342. },
  343. );
  344. Widget changePwd = FullWidthButton(
  345. title: I18n.of(context).change_password,
  346. showDivider: true,
  347. onPressed: () {
  348. if (UserData().mobile == null || UserData().mobile == 0) {
  349. showToast(I18n.of(context).first_bind);
  350. return;
  351. }
  352. Navigator.of(context).push(
  353. new MaterialPageRoute(
  354. builder: (context) {
  355. return RegisterPage(
  356. type: PageType.changePWD.index,
  357. );
  358. },
  359. ),
  360. );
  361. },
  362. );
  363. Widget changeLang = Container(
  364. padding: EdgeInsets.only(left: 10),
  365. height: 50,
  366. child: Row(
  367. children: <Widget>[
  368. Text(I18n.of(context).language_set,
  369. textScaleFactor: 1.0,
  370. style: TextStyle(fontSize: 14, fontWeight: FontWeight.normal)),
  371. Expanded(
  372. child: Container(),
  373. ),
  374. Container(
  375. padding: EdgeInsets.all(0),
  376. margin: EdgeInsets.all(0),
  377. child: new DropdownButtonHideUnderline(
  378. child: new DropdownButton(
  379. items: language.keys.map((key) {
  380. return DropdownMenuItem(
  381. child: new Text(language[key], textScaleFactor: 1.0),
  382. value: key,
  383. );
  384. }).toList(),
  385. onChanged: (value) {
  386. setState(() {
  387. _selectType = value;
  388. changeLanguage();
  389. });
  390. },
  391. value: _selectType,
  392. elevation: 24, //设置阴影的高度
  393. style: new TextStyle(
  394. //设置文本框里面文字的样式
  395. color: Constants.BlackTextColor,
  396. fontSize: 12,
  397. ),
  398. iconSize: 25.0,
  399. )),
  400. )
  401. ],
  402. ));
  403. return Container(
  404. padding: EdgeInsets.symmetric(horizontal: 10),
  405. width: cardWidth,
  406. child: Column(
  407. children: <Widget>[
  408. telePhoneSetting,
  409. changePwd,
  410. changeLang,
  411. ],
  412. ),
  413. decoration: getCardDecoration(),
  414. );
  415. }
  416. //修改语言
  417. void changeLanguage() async {
  418. HttpUtil().changeLanguage(context, _selectType, () async {
  419. UserData().language = int.parse(_selectType);
  420. WebData().changeLoaction(UserData().language);
  421. //将用户信息存到本地
  422. SharedPreferences prefs = await SharedPreferences.getInstance();
  423. prefs.setInt(Constants.Language, int.parse(_selectType));
  424. WebData().getAllData();
  425. Navigator.of(context)
  426. .pushNamedAndRemoveUntil('/main', (route) => route == null);
  427. }, true);
  428. setStatusBar();
  429. }
  430. //清楚图片缓存
  431. Widget _clearPictureSetting() {
  432. return Container(
  433. padding: EdgeInsets.symmetric(horizontal: 10),
  434. width: cardWidth,
  435. child: FullWidthButton(
  436. title: I18n.of(context).clear_cache,
  437. showDivider: false,
  438. onPressed: () {
  439. DefaultCacheManager().emptyCache();
  440. showToast(I18n.of(context).success);
  441. },
  442. ),
  443. decoration: getCardDecoration(),
  444. );
  445. }
  446. ///切换听筒模式-或外放
  447. Widget _soundPlayModeSetting() {
  448. Widget left = new Text(
  449. I18n.of(context).play_model,
  450. textScaleFactor: 1.0,
  451. style: TextStyle(fontSize: 14, fontWeight: FontWeight.normal),
  452. );
  453. Widget right = new Expanded(
  454. child: new Align(
  455. alignment: Alignment.centerRight,
  456. child: new Switch(
  457. value: soundPlayMode,
  458. activeTrackColor: Colors.blue.withOpacity(0.3),
  459. onChanged: (bool val) {
  460. setState(() {
  461. soundPlayMode = val;
  462. });
  463. SoundUtils.instance.savePlayModeConfig(soundPlayMode);
  464. print('目前: soundPlayMode $soundPlayMode');
  465. // setDisableScreenshots();
  466. },
  467. )));
  468. return new Container(
  469. decoration: BoxDecoration(
  470. color: Colors.white,
  471. ),
  472. margin: EdgeInsets.only(top: 15, bottom: 0),
  473. padding: EdgeInsets.only(left: 20),
  474. height: 53,
  475. child: new Row(
  476. children: <Widget>[left, right],
  477. ),
  478. );
  479. }
  480. //用户协议
  481. Widget _buildUserAgreement() {
  482. return Container(
  483. padding: EdgeInsets.symmetric(horizontal: 10),
  484. width: cardWidth,
  485. child: FullWidthButton(
  486. title: I18n.of(context).user_agreement,
  487. showDivider: false,
  488. showRightIcon: false,
  489. onPressed: () async {
  490. Navigator.of(context).push(
  491. new MaterialPageRoute(
  492. builder: (context) {
  493. return UserAgreement();
  494. },
  495. ),
  496. );
  497. },
  498. ),
  499. decoration: getCardDecoration(),
  500. );
  501. }
  502. //绑定邀请码
  503. Widget _buildBindCode() {
  504. return Container(
  505. margin: EdgeInsets.only(top: Separate_Size),
  506. padding: EdgeInsets.symmetric(horizontal: 10),
  507. width: cardWidth,
  508. child: FullWidthButton(
  509. title: I18n.of(context).bind_code,
  510. description:
  511. UserData().agentId == 0 ? '' : UserData().agentId.toString(),
  512. showDivider: false,
  513. onPressed: UserData().agentId == 0
  514. ? () {
  515. if (!UserData().basicInfo.isAttestation) {
  516. CustomUI.buildNotTrue(context);
  517. return;
  518. }
  519. Navigator.of(context).push(
  520. new MaterialPageRoute(
  521. builder: (context) {
  522. return BindCodePage();
  523. },
  524. ),
  525. );
  526. }
  527. : () {},
  528. ),
  529. decoration: getCardDecoration(),
  530. );
  531. }
  532. void _buildConfirmLogout() {
  533. CustomUI.buildOneConfirm(
  534. context, I18n.of(context).exit, I18n.of(context).determine, () {
  535. userLogout();
  536. HttpUtil().postLoginOut(context);
  537. });
  538. }
  539. static userLogout() {
  540. LocalNotificationUtil().removeAlias();
  541. ReceiveShareFile.dispose();
  542. }
  543. //退出登陆
  544. Widget _buildLogout() {
  545. return Container(
  546. padding: EdgeInsets.symmetric(horizontal: 10),
  547. width: cardWidth,
  548. child: FullWidthButton(
  549. showRightIcon: false,
  550. title: I18n.of(context).sign_out,
  551. showDivider: false,
  552. onPressed: _buildConfirmLogout,
  553. ),
  554. decoration: getCardDecoration(),
  555. );
  556. }
  557. }