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.
 
 
 
 
 
 

541 regels
16 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. leading: CustomUI.buildCustomLeading(context),
  73. ),
  74. body: SafeArea(
  75. child: Container(
  76. color: AppColors.BackgroundColor,
  77. height: MediaQuery.of(context).size.height,
  78. child: SingleChildScrollView(
  79. child: _buildBody(),
  80. ))));
  81. }
  82. Widget _buildBody() {
  83. return Column(
  84. children: <Widget>[
  85. SizedBox(height: Separate_Size),
  86. _buildPravice(),
  87. SizedBox(height: Separate_Size),
  88. _buildMsgSetting(),
  89. SizedBox(height: Separate_Size),
  90. _buildBasicSetting(),
  91. SizedBox(height: Separate_Size),
  92. _clearPictureSetting(),
  93. _soundPlayModeSetting(),
  94. SizedBox(height: Separate_Size),
  95. _buildUserAgreement(),
  96. _buildBindCode(),
  97. _buildMyEvaluation(),
  98. _buildVersion(),
  99. _buildHelp(),
  100. SizedBox(height: Separate_Size),
  101. _buildLogout(),
  102. SizedBox(height: Separate_Size),
  103. ],
  104. );
  105. }
  106. //有问题需要帮助
  107. Widget _buildHelp() {
  108. return Container(
  109. margin: EdgeInsets.only(top: Separate_Size),
  110. padding: EdgeInsets.symmetric(horizontal: 10),
  111. child: FullWidthButton(
  112. showRightIcon: false,
  113. title: I18n.of(context).need_help,
  114. description: I18n.of(context).need_help2,
  115. showDivider: false,
  116. onPressed: () {
  117. AppNavigator.pushServicePage(context);
  118. },
  119. ),
  120. decoration: BoxDecoration(
  121. color: Colors.white,
  122. border: Border(
  123. top: Constants.GreyBorderSide, bottom: Constants.GreyBorderSide)),
  124. );
  125. }
  126. Widget _buildVersion() {
  127. //版本
  128. return Container(
  129. margin: EdgeInsets.only(top: Separate_Size),
  130. padding: EdgeInsets.symmetric(horizontal: 10),
  131. child: FullWidthButton(
  132. showRightIcon: false,
  133. title: '${I18n.of(context).current_version} ',
  134. description: Constants.versionName,
  135. showDivider: false,
  136. onPressed: () {
  137. // VersionUtils.versionUpdate(context, fromProfileNeedShow: true);
  138. },
  139. ),
  140. decoration: BoxDecoration(
  141. color: Colors.white,
  142. border: Border(
  143. top: Constants.GreyBorderSide, bottom: Constants.GreyBorderSide)),
  144. );
  145. }
  146. Widget _buildMyEvaluation() {
  147. //版本
  148. return Container(
  149. margin: EdgeInsets.only(top: Separate_Size),
  150. padding: EdgeInsets.symmetric(horizontal: 10),
  151. child: FullWidthButton(
  152. showRightIcon: true,
  153. title: I18n.of(context).my_evaluation,
  154. showDivider: false,
  155. onPressed: () async {
  156. Map data = {
  157. "userid": UserData().basicInfo.userId,
  158. "evaluateuserid": UserData().basicInfo.userId,
  159. };
  160. data['sign'] = TokenMgr().getSign(data);
  161. Response res = await HttpUtil()
  162. .post('evaluate/user/info', data: data, isShowLoading: true);
  163. Map resData = res.data;
  164. if (resData['code'] == 0) {
  165. _buildMyEvaluate(resData['data']);
  166. }
  167. },
  168. ),
  169. decoration: BoxDecoration(
  170. color: Colors.white,
  171. border: Border(
  172. top: Constants.GreyBorderSide, bottom: Constants.GreyBorderSide)),
  173. );
  174. }
  175. void _buildMyEvaluate(data) {
  176. bool isMan = UserData().isMan();
  177. var content = Container(
  178. margin: EdgeInsets.only(top: 10.5),
  179. child: Column(
  180. children: <Widget>[
  181. Row(
  182. mainAxisAlignment: MainAxisAlignment.center,
  183. children: <Widget>[
  184. CustomUI.buildBox(
  185. data['Friendly'],
  186. isMan
  187. ? I18n.of(context).courtesy
  188. : I18n.of(context).friendly),
  189. CustomUI.buildBox(
  190. data['Interesting'], I18n.of(context).interesting),
  191. CustomUI.buildBox(data['Refreshing'], I18n.of(context).readily),
  192. ],
  193. ),
  194. SizedBox(
  195. height: 5,
  196. ),
  197. Row(
  198. mainAxisAlignment: MainAxisAlignment.center,
  199. children: <Widget>[
  200. CustomUI.buildBox(data['Patience'],
  201. isMan ? I18n.of(context).generous : I18n.of(context).patient),
  202. CustomUI.buildBox(data['Hello'],
  203. isMan ? I18n.of(context).lie : I18n.of(context).indifferent),
  204. CustomUI.buildBox(
  205. data['Unfriendly'],
  206. isMan
  207. ? I18n.of(context).unfriendly
  208. : I18n.of(context).bad_temper),
  209. ],
  210. )
  211. ],
  212. ),
  213. );
  214. CustomUI.buildTip(context, I18n.of(context).your_evaluation, content);
  215. }
  216. Widget _buildPravice() {
  217. return Container(
  218. padding: EdgeInsets.symmetric(horizontal: 10),
  219. width: cardWidth,
  220. child: FullWidthButton(
  221. title: I18n.of(context).setting,
  222. showDivider: false,
  223. onPressed: () {
  224. Navigator.of(context).push(
  225. new MaterialPageRoute(
  226. builder: (context) {
  227. return PravicySettingPage();
  228. },
  229. ),
  230. );
  231. },
  232. ),
  233. decoration: getCardDecoration(),
  234. );
  235. }
  236. //消息通知设置
  237. Widget _buildMsgSetting() {
  238. return Container(
  239. padding: EdgeInsets.symmetric(horizontal: 10),
  240. width: cardWidth,
  241. child: FullWidthButton(
  242. title: I18n.of(context).push_setting2,
  243. showDivider: false,
  244. onPressed: () {
  245. Navigator.of(context).push(
  246. new MaterialPageRoute(
  247. builder: (context) {
  248. return MessagePushPage();
  249. },
  250. ),
  251. );
  252. },
  253. ),
  254. decoration: getCardDecoration(),
  255. );
  256. }
  257. //手机号码·修改密码
  258. Widget _buildBasicSetting() {
  259. Widget telePhoneSetting = FullWidthButton(
  260. title: I18n.of(context).phone_number,
  261. description: (UserData().mobile == 0 || UserData().mobile == null)
  262. ? ''
  263. : UserData().mobile.toString(),
  264. showDivider: true,
  265. onPressed: () {
  266. if (UserData().mobile != null && UserData().mobile != 0) {
  267. CustomUI.buildOneConfirm(context, I18n.of(context).modify_choose,
  268. I18n.of(context).determine, () {
  269. Navigator.of(context).pop();
  270. Navigator.of(context).push(
  271. new MaterialPageRoute(
  272. builder: (context) {
  273. return RegisterPage(
  274. type: PageType.bindPhone.index,
  275. );
  276. },
  277. ),
  278. );
  279. });
  280. return;
  281. }
  282. Navigator.of(context).push(
  283. new MaterialPageRoute(
  284. builder: (context) {
  285. return RegisterPage(
  286. type: PageType.bindPhone.index,
  287. );
  288. },
  289. ),
  290. );
  291. },
  292. );
  293. Widget changePwd = FullWidthButton(
  294. title: I18n.of(context).change_password,
  295. showDivider: true,
  296. onPressed: () {
  297. if (UserData().mobile == null || UserData().mobile == 0) {
  298. showToast(I18n.of(context).first_bind);
  299. return;
  300. }
  301. Navigator.of(context).push(
  302. new MaterialPageRoute(
  303. builder: (context) {
  304. return RegisterPage(
  305. type: PageType.changePWD.index,
  306. );
  307. },
  308. ),
  309. );
  310. },
  311. );
  312. Widget changeLang = Container(
  313. padding: EdgeInsets.only(left: 10),
  314. height: 50,
  315. child: Row(
  316. children: <Widget>[
  317. Text(I18n.of(context).language_set,
  318. textScaleFactor: 1.0,
  319. style: TextStyle(fontSize: 14, fontWeight: FontWeight.normal)),
  320. Expanded(
  321. child: Container(),
  322. ),
  323. Container(
  324. padding: EdgeInsets.all(0),
  325. margin: EdgeInsets.all(0),
  326. child: new DropdownButtonHideUnderline(
  327. child: new DropdownButton(
  328. items: language.keys.map((key) {
  329. return DropdownMenuItem(
  330. child: new Text(language[key], textScaleFactor: 1.0),
  331. value: key,
  332. );
  333. }).toList(),
  334. onChanged: (value) {
  335. setState(() {
  336. _selectType = value;
  337. changeLanguage();
  338. });
  339. },
  340. value: _selectType,
  341. elevation: 24, //设置阴影的高度
  342. style: new TextStyle(
  343. //设置文本框里面文字的样式
  344. color: Constants.BlackTextColor,
  345. fontSize: 12,
  346. ),
  347. iconSize: 25.0,
  348. )),
  349. )
  350. ],
  351. ));
  352. return Container(
  353. padding: EdgeInsets.symmetric(horizontal: 10),
  354. width: cardWidth,
  355. child: Column(
  356. children: <Widget>[
  357. telePhoneSetting,
  358. changePwd,
  359. changeLang,
  360. ],
  361. ),
  362. decoration: getCardDecoration(),
  363. );
  364. }
  365. //修改语言
  366. void changeLanguage() async {
  367. HttpUtil().changeLanguage(context, _selectType, () async {
  368. UserData().language = int.parse(_selectType);
  369. WebData().changeLoaction(UserData().language);
  370. //将用户信息存到本地
  371. SharedPreferences prefs = await SharedPreferences.getInstance();
  372. prefs.setInt(Constants.Language, int.parse(_selectType));
  373. WebData().getAllData();
  374. Navigator.of(context)
  375. .pushNamedAndRemoveUntil('/main', (route) => route == null);
  376. }, true);
  377. setStatusBar();
  378. }
  379. //清楚图片缓存
  380. Widget _clearPictureSetting() {
  381. return Container(
  382. padding: EdgeInsets.symmetric(horizontal: 10),
  383. width: cardWidth,
  384. child: FullWidthButton(
  385. title: I18n.of(context).clear_cache,
  386. showDivider: false,
  387. onPressed: () {
  388. DefaultCacheManager().emptyCache();
  389. showToast(I18n.of(context).success);
  390. },
  391. ),
  392. decoration: getCardDecoration(),
  393. );
  394. }
  395. ///切换听筒模式-或外放
  396. Widget _soundPlayModeSetting() {
  397. Widget left = new Text(
  398. I18n.of(context).play_model,
  399. textScaleFactor: 1.0,
  400. style: TextStyle(fontSize: 14, fontWeight: FontWeight.normal),
  401. );
  402. Widget right = new Expanded(
  403. child: new Align(
  404. alignment: Alignment.centerRight,
  405. child: new Switch(
  406. value: soundPlayMode,
  407. activeTrackColor: Colors.blue.withOpacity(0.3),
  408. onChanged: (bool val) {
  409. setState(() {
  410. soundPlayMode = val;
  411. });
  412. SoundUtils.instance.savePlayModeConfig(soundPlayMode);
  413. print('目前: soundPlayMode $soundPlayMode');
  414. // setDisableScreenshots();
  415. },
  416. )));
  417. return new Container(
  418. decoration: BoxDecoration(
  419. color: Colors.white,
  420. ),
  421. margin: EdgeInsets.only(top: 15, bottom: 0),
  422. padding: EdgeInsets.only(left: 20),
  423. height: 53,
  424. child: new Row(
  425. children: <Widget>[left, right],
  426. ),
  427. );
  428. }
  429. //用户协议
  430. Widget _buildUserAgreement() {
  431. return Container(
  432. padding: EdgeInsets.symmetric(horizontal: 10),
  433. width: cardWidth,
  434. child: FullWidthButton(
  435. title: I18n.of(context).user_agreement,
  436. showDivider: false,
  437. showRightIcon: false,
  438. onPressed: () async {
  439. Navigator.of(context).push(
  440. new MaterialPageRoute(
  441. builder: (context) {
  442. return UserAgreement();
  443. },
  444. ),
  445. );
  446. },
  447. ),
  448. decoration: getCardDecoration(),
  449. );
  450. }
  451. //绑定邀请码
  452. Widget _buildBindCode() {
  453. return Container(
  454. margin: EdgeInsets.only(top: Separate_Size),
  455. padding: EdgeInsets.symmetric(horizontal: 10),
  456. width: cardWidth,
  457. child: FullWidthButton(
  458. title: I18n.of(context).bind_code,
  459. description:
  460. UserData().agentId == 0 ? '' : UserData().agentId.toString(),
  461. showDivider: false,
  462. onPressed: UserData().agentId == 0
  463. ? () {
  464. if (!UserData().basicInfo.isAttestation) {
  465. CustomUI.buildNotTrue(context);
  466. return;
  467. }
  468. Navigator.of(context).push(
  469. new MaterialPageRoute(
  470. builder: (context) {
  471. return BindCodePage();
  472. },
  473. ),
  474. );
  475. }
  476. : () {},
  477. ),
  478. decoration: getCardDecoration(),
  479. );
  480. }
  481. void _buildConfirmLogout() {
  482. CustomUI.buildOneConfirm(
  483. context, I18n.of(context).exit, I18n.of(context).determine, () {
  484. userLogout();
  485. HttpUtil().postLoginOut(context);
  486. });
  487. }
  488. static userLogout(){
  489. LocalNotificationUtil().removeAlias();
  490. ReceiveShareFile.dispose();
  491. }
  492. //退出登陆
  493. Widget _buildLogout() {
  494. return Container(
  495. padding: EdgeInsets.symmetric(horizontal: 10),
  496. width: cardWidth,
  497. child: FullWidthButton(
  498. showRightIcon: false,
  499. title: I18n.of(context).sign_out,
  500. showDivider: false,
  501. onPressed: _buildConfirmLogout,
  502. ),
  503. decoration: getCardDecoration(),
  504. );
  505. }
  506. }