Hibok
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

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