Hibok
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

245 wiersze
7.6 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. //震动通知
  36. bool shockNotic = false;
  37. bool isLoadingFish = false;
  38. BoxDecoration _getCardDecoration() {
  39. return new BoxDecoration(
  40. color: Colors.white,
  41. );
  42. }
  43. getSettingInfo() async {
  44. Map data = {
  45. "userId": UserData().basicInfo.userId,
  46. "sex": UserData().basicInfo.sex,
  47. };
  48. data['sign'] = TokenMgr().getSign(data);
  49. try {
  50. Response res = await HttpUtil().post('message/push/message',
  51. data: data, failback: () => Navigator.of(context).pop());
  52. Map resData = res.data;
  53. if (resData['code'] == 0) {
  54. privatyMsg = resData['data']['PrivacyChat'] == 1;
  55. newDate = resData['data']['NewBroadcast'] == 1;
  56. shockNotic = resData['data']['VibrationReminder'] == 1;
  57. if (isMan) {
  58. womenAgree = resData['data']['AcceptCheck'] == 1;
  59. codeSucess = resData['data']['ApplySuccess'] == 1;
  60. } else {
  61. watchMyData = resData['data']['ApplyCheck'] == 1;
  62. watchMyPicture = resData['data']['CheckPhoto'] == 1;
  63. }
  64. Future.delayed(Duration(milliseconds: Constants.CloseLoaindTime), () {
  65. isLoadingFish = true;
  66. setState(() {});
  67. });
  68. setState(() {});
  69. }
  70. } catch (e) {}
  71. }
  72. @override
  73. void initState() {
  74. super.initState();
  75. isMan = UserData().isMan();
  76. getSettingInfo();
  77. }
  78. @override
  79. Widget build(BuildContext context) {
  80. Widget appBar = new AppBar(
  81. backgroundColor: AppColors.NewAppbarBgColor,
  82. title: new Text(
  83. I18n.of(context).push_setting2,
  84. textScaleFactor: 1.0,
  85. style: TextStyle(color: AppColors.NewAppbarTextColor),
  86. ),
  87. leading: CustomUI.buildCustomLeading(context),
  88. actions: <Widget>[
  89. Container(
  90. alignment: Alignment.center,
  91. child: new InkWell(
  92. child: new Padding(
  93. padding:
  94. EdgeInsets.only(right: 15, left: 15, top: 10, bottom: 10),
  95. child: new Text(I18n.of(context).save,
  96. textScaleFactor: 1.0, style: Constants.AppBarActionTextStyle),
  97. ),
  98. onTap: () async {
  99. Map data = {
  100. "userId": UserData().basicInfo.userId,
  101. "sex": UserData().basicInfo.sex,
  102. };
  103. data['sign'] = TokenMgr().getSign(data);
  104. data['privacyChat'] = privatyMsg ? 1 : 0;
  105. data['newBroadcast'] = newDate ? 1 : 0;
  106. data['vibrationReminder'] = shockNotic ? 1 : 0;
  107. if (isMan) {
  108. data['acceptCheck'] = womenAgree ? 1 : 0;
  109. data['applySuccess'] = codeSucess ? 1 : 0;
  110. } else {
  111. data['applyCheck'] = watchMyData ? 1 : 0;
  112. data['checkPhoto'] = watchMyPicture ? 1 : 0;
  113. data['checkAccount'] = 1;
  114. data['sendAccount'] = 1;
  115. }
  116. try {
  117. Response res = await HttpUtil()
  118. .post('message/setting/message', data: data);
  119. Map resData = res.data;
  120. showToast('${resData['msg']}');
  121. if (resData['code'] == 0) {
  122. UserData().privatyMsgPushSwitch = privatyMsg;
  123. UserData().newDateSwitch = newDate;
  124. UserData().applyCheckSwitch = watchMyData;
  125. UserData().acceptCheckSwitch = womenAgree;
  126. UserData().checkPhotoSwitch = watchMyPicture;
  127. UserData().codeSucessSwitch = codeSucess;
  128. UserData().shockNoticSwitch = shockNotic;
  129. }
  130. } catch (e) {}
  131. },
  132. ),
  133. )
  134. ],
  135. centerTitle: true,
  136. );
  137. Widget content = Scaffold(
  138. body: SafeArea(
  139. child: Center(
  140. child: Container(
  141. height: MediaQuery.of(context).size.height,
  142. width: MediaQuery.of(context).size.width,
  143. child: _buildBody(),
  144. ),
  145. )),
  146. appBar: appBar,
  147. );
  148. return CustomUI.buildPageLoading(context, content, !isLoadingFish);
  149. }
  150. Widget _buildBody() {
  151. List<Widget> man = [
  152. _buildHiddenButtom(I18n.of(context).private_chat2, privatyMsg, () {
  153. setState(() {
  154. privatyMsg = !privatyMsg;
  155. });
  156. }),
  157. _buildHiddenButtom(I18n.of(context).new_date, newDate, () {
  158. setState(() {
  159. newDate = !newDate;
  160. });
  161. }),
  162. _buildHiddenButtom(I18n.of(context).passed_request2, womenAgree, () {
  163. setState(() {
  164. womenAgree = !womenAgree;
  165. });
  166. }),
  167. _buildHiddenButtom(I18n.of(context).shock_notice, shockNotic, () {
  168. setState(() {
  169. shockNotic = !shockNotic;
  170. });
  171. }),
  172. ];
  173. List<Widget> women = [
  174. _buildHiddenButtom(I18n.of(context).private_chat2, privatyMsg, () {
  175. setState(() {
  176. privatyMsg = !privatyMsg;
  177. });
  178. }),
  179. _buildHiddenButtom(I18n.of(context).new_date, newDate, () {
  180. setState(() {
  181. newDate = !newDate;
  182. });
  183. }),
  184. _buildHiddenButtom(I18n.of(context).men_view, watchMyData, () {
  185. setState(() {
  186. watchMyData = !watchMyData;
  187. });
  188. }),
  189. _buildHiddenButtom(I18n.of(context).men_view3, watchMyPicture, () {
  190. setState(() {
  191. watchMyPicture = !watchMyPicture;
  192. });
  193. }),
  194. _buildHiddenButtom(I18n.of(context).shock_notice, shockNotic, () {
  195. setState(() {
  196. shockNotic = !shockNotic;
  197. });
  198. }),
  199. ];
  200. return new ListView(
  201. children: isMan ? man : women,
  202. );
  203. }
  204. //是否隐藏社交账号
  205. Widget _buildHiddenButtom(str, value, callback) {
  206. Widget left = new Text(
  207. str,
  208. textScaleFactor: 1.0,
  209. style: TextStyle(fontSize: 14, fontWeight: FontWeight.normal),
  210. );
  211. Widget right = new Expanded(
  212. child: new Align(
  213. alignment: Alignment.centerRight,
  214. child: new Switch(
  215. value: value,
  216. activeTrackColor: Constants.ConfrimButtonColor.withOpacity(0.3),
  217. onChanged: (bool val) {
  218. callback();
  219. },
  220. )));
  221. return new Container(
  222. decoration: _getCardDecoration(),
  223. margin: EdgeInsets.only(top: 15, bottom: 0),
  224. padding: EdgeInsets.only(left: 15),
  225. height: 53,
  226. child: new Row(
  227. children: <Widget>[left, right],
  228. ),
  229. );
  230. }
  231. }