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.
 
 
 
 
 
 

235 line
7.3 KiB

  1. import 'package:chat/data/UserData.dart';
  2. import 'package:chat/data/constants.dart';
  3. import 'package:chat/generated/i18n.dart';
  4. import 'package:chat/utils/CustomUI.dart';
  5. import 'package:chat/utils/HttpUtil.dart';
  6. import 'package:dio/dio.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:oktoast/oktoast.dart';
  9. import '../data/UserData.dart';
  10. import '../utils/TokenMgr.dart';
  11. class MessagePushPage extends StatefulWidget {
  12. MessagePushPage({Key key}) : super(key: key);
  13. _MessagePushPageState createState() => _MessagePushPageState();
  14. }
  15. class _MessagePushPageState extends State<MessagePushPage> {
  16. bool isMan = true;
  17. //私聊信息
  18. bool privatyMsg = false;
  19. //消息推送
  20. bool msgPush = false;
  21. //男士申请查看资料页
  22. bool watchMyData = false;
  23. //男士查看社交账号
  24. bool watchSocialAccount = false;
  25. //查看红包照片
  26. bool watchMyPicture = false;
  27. //男士给我发送社交账号
  28. bool sendSocialAccount = false;
  29. //新约会
  30. bool newDate = false;
  31. //女士通过我的查看请求
  32. bool womenAgree = false;
  33. //邀请码申请成功
  34. bool codeSucess = false;
  35. bool isLoadingFish = false;
  36. BoxDecoration _getCardDecoration() {
  37. return new BoxDecoration(
  38. color: Colors.white,
  39. );
  40. }
  41. getSettingInfo() async {
  42. Map data = {
  43. "userId": UserData().basicInfo.userId,
  44. "sex": UserData().basicInfo.sex,
  45. };
  46. data['sign'] = TokenMgr().getSign(data);
  47. try {
  48. Response res = await HttpUtil().post('message/push/message',
  49. data: data, failback: () => Navigator.of(context).pop());
  50. Map resData = res.data;
  51. if (resData['code'] == 0) {
  52. privatyMsg = resData['data']['PrivacyChat'] == 1;
  53. newDate = resData['data']['NewBroadcast'] == 1;
  54. if (isMan) {
  55. womenAgree = resData['data']['AcceptCheck'] == 1;
  56. codeSucess = resData['data']['ApplySuccess'] == 1;
  57. } else {
  58. watchMyData = resData['data']['ApplyCheck'] == 1;
  59. watchMyPicture = resData['data']['CheckPhoto'] == 1;
  60. }
  61. Future.delayed(Duration(milliseconds: Constants.CloseLoaindTime), () {
  62. isLoadingFish = true;
  63. setState(() {});
  64. });
  65. setState(() {});
  66. }
  67. } catch (e) {}
  68. }
  69. @override
  70. void initState() {
  71. super.initState();
  72. isMan = UserData().isMan();
  73. getSettingInfo();
  74. }
  75. @override
  76. Widget build(BuildContext context) {
  77. Widget appBar = new AppBar(
  78. backgroundColor: AppColors.NewAppbarBgColor,
  79. title: new Text(
  80. I18n.of(context).push_setting2,
  81. textScaleFactor: 1.0,
  82. style: TextStyle(color: AppColors.NewAppbarTextColor),
  83. ),
  84. leading: CustomUI.buildCustomLeading(context),
  85. actions: <Widget>[
  86. Container(
  87. alignment: Alignment.center,
  88. child: new InkWell(
  89. child: new Padding(
  90. padding:
  91. EdgeInsets.only(right: 15, left: 15, top: 10, bottom: 10),
  92. child: new Text(I18n.of(context).save,
  93. textScaleFactor: 1.0, style: Constants.AppBarActionTextStyle),
  94. ),
  95. onTap: () async {
  96. Map data = {
  97. "userId": UserData().basicInfo.userId,
  98. "sex": UserData().basicInfo.sex,
  99. };
  100. data['sign'] = TokenMgr().getSign(data);
  101. data['privacyChat'] = privatyMsg ? 1 : 0;
  102. data['newBroadcast'] = newDate ? 1 : 0;
  103. if (isMan) {
  104. data['acceptCheck'] = womenAgree ? 1 : 0;
  105. data['applySuccess'] = codeSucess ? 1 : 0;
  106. } else {
  107. data['applyCheck'] = watchMyData ? 1 : 0;
  108. data['checkPhoto'] = watchMyPicture ? 1 : 0;
  109. data['checkAccount'] = 1;
  110. data['sendAccount'] = 1;
  111. }
  112. try {
  113. Response res = await HttpUtil()
  114. .post('message/setting/message', data: data);
  115. Map resData = res.data;
  116. showToast('${resData['msg']}');
  117. if (resData['code'] == 0) {
  118. UserData().privatyMsgPushSwitch = privatyMsg;
  119. UserData().newDateSwitch = newDate;
  120. UserData().applyCheckSwitch = watchMyData;
  121. UserData().acceptCheckSwitch = womenAgree;
  122. UserData().checkPhotoSwitch = watchMyPicture;
  123. UserData().codeSucessSwitch = codeSucess;
  124. }
  125. } catch (e) {}
  126. },
  127. ),
  128. )
  129. ],
  130. centerTitle: true,
  131. );
  132. Widget content = Scaffold(
  133. body: SafeArea(
  134. child: Center(
  135. child: Container(
  136. height: MediaQuery.of(context).size.height,
  137. width: MediaQuery.of(context).size.width,
  138. child: _buildBody(),
  139. ),
  140. )),
  141. appBar: appBar,
  142. );
  143. return CustomUI.buildPageLoading(context, content, !isLoadingFish);
  144. }
  145. Widget _buildBody() {
  146. List<Widget> man = [
  147. _buildHiddenButtom(I18n.of(context).private_chat2, privatyMsg, () {
  148. setState(() {
  149. privatyMsg = !privatyMsg;
  150. });
  151. }),
  152. _buildHiddenButtom(I18n.of(context).new_date, newDate, () {
  153. setState(() {
  154. newDate = !newDate;
  155. });
  156. }),
  157. _buildHiddenButtom(I18n.of(context).passed_request2, womenAgree, () {
  158. setState(() {
  159. womenAgree = !womenAgree;
  160. });
  161. }),
  162. // _buildHiddenButtom(I18n.of(context).applied_successfully, codeSucess, () {
  163. // setState(() {
  164. // codeSucess = !codeSucess;
  165. // });
  166. // }),
  167. ];
  168. List<Widget> women = [
  169. _buildHiddenButtom(I18n.of(context).private_chat2, privatyMsg, () {
  170. setState(() {
  171. privatyMsg = !privatyMsg;
  172. });
  173. }),
  174. _buildHiddenButtom(I18n.of(context).new_date, newDate, () {
  175. setState(() {
  176. newDate = !newDate;
  177. });
  178. }),
  179. _buildHiddenButtom(I18n.of(context).men_view, watchMyData, () {
  180. setState(() {
  181. watchMyData = !watchMyData;
  182. });
  183. }),
  184. _buildHiddenButtom(I18n.of(context).men_view3, watchMyPicture, () {
  185. setState(() {
  186. watchMyPicture = !watchMyPicture;
  187. });
  188. }),
  189. ];
  190. return new ListView(
  191. children: isMan ? man : women,
  192. );
  193. }
  194. //是否隐藏社交账号
  195. Widget _buildHiddenButtom(str, value, callback) {
  196. Widget left = new Text(
  197. str,
  198. textScaleFactor: 1.0,
  199. style: TextStyle(fontSize: 14, fontWeight: FontWeight.normal),
  200. );
  201. Widget right = new Expanded(
  202. child: new Align(
  203. alignment: Alignment.centerRight,
  204. child: new Switch(
  205. value: value,
  206. activeTrackColor: Constants.ConfrimButtonColor.withOpacity(0.3),
  207. onChanged: (bool val) {
  208. callback();
  209. },
  210. )));
  211. return new Container(
  212. decoration: _getCardDecoration(),
  213. margin: EdgeInsets.only(top: 15, bottom: 0),
  214. padding: EdgeInsets.only(left: 15),
  215. height: 53,
  216. child: new Row(
  217. children: <Widget>[left, right],
  218. ),
  219. );
  220. }
  221. }