Hibok
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

415 rader
13 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/FullWithButton.dart';
  6. import 'package:chat/utils/HttpUtil.dart';
  7. import 'package:dio/dio.dart';
  8. import 'package:flutter/material.dart';
  9. import 'package:flutter/services.dart';
  10. import 'package:oktoast/oktoast.dart';
  11. import '../data/UserData.dart';
  12. import '../utils/TokenMgr.dart';
  13. import 'WhiteAndBlackList.dart';
  14. enum userDetail {
  15. open,
  16. pay,
  17. apply,
  18. }
  19. class PravicySettingPage extends StatefulWidget {
  20. PravicySettingPage({Key key}) : super(key: key);
  21. _PravicySettingPageState createState() => _PravicySettingPageState();
  22. }
  23. class _PravicySettingPageState extends State<PravicySettingPage> {
  24. int _socialType = 0;
  25. bool parkHidden = false;
  26. bool distanceHidden = false;
  27. bool msgHidden = false;
  28. bool strangerHidden = false;
  29. String money;
  30. bool isLoadingFish = false;
  31. setUserDetailData(type, statu, mon, callback) async {
  32. var data = {
  33. "userid": UserData().basicInfo.userId,
  34. "type": type,
  35. "statu": statu,
  36. };
  37. data['sign'] = TokenMgr().getSign(data);
  38. data["price"] = mon;
  39. try {
  40. Response res =
  41. await HttpUtil().post('user/setting/userprivacy', data: data);
  42. Map resData = res.data;
  43. if (resData['code'] == 0) {
  44. callback();
  45. } else {
  46. showToast(resData['msg']);
  47. }
  48. } catch (e) {}
  49. }
  50. @override
  51. void initState() {
  52. super.initState();
  53. print('PravicySettingPage initState');
  54. getSettingInfo();
  55. }
  56. void getSettingInfo() async {
  57. Map data = {
  58. "userId": UserData().basicInfo.userId,
  59. };
  60. data['sign'] = TokenMgr().getSign(data);
  61. Response res = await HttpUtil().post('user/get/privacy',
  62. data: data, failback: () => Navigator.of(context).pop());
  63. Map resData = res.data;
  64. print(resData);
  65. if (resData['code'] == 0 && resData['data'] != null) {
  66. _socialType = resData['data']['Details'];
  67. parkHidden = resData['data']['Invisible'] == 1;
  68. distanceHidden = resData['data']['Distance'] == 1;
  69. msgHidden = resData['data']['Chat'] == 1;
  70. strangerHidden = resData['data']['StrangerNews'] == 1;
  71. Future.delayed(Duration(milliseconds: Constants.CloseLoaindTime), () {
  72. isLoadingFish = true;
  73. setState(() {});
  74. });
  75. setState(() {});
  76. }
  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).setting,
  84. textScaleFactor: 1.0,
  85. style: TextStyle(color: AppColors.NewAppbarTextColor),
  86. ),
  87. centerTitle: true,
  88. leading: CustomUI.buildCustomLeading(context),
  89. );
  90. Widget content = Scaffold(
  91. body: SafeArea(
  92. child: Center(
  93. child: Container(
  94. height: MediaQuery.of(context).size.height,
  95. width: MediaQuery.of(context).size.width,
  96. child: _buildBody(),
  97. ),
  98. )),
  99. appBar: appBar,
  100. );
  101. return CustomUI.buildPageLoading(context, content, !isLoadingFish);
  102. }
  103. Widget _buildBody() {
  104. return new ListView(
  105. children: <Widget>[
  106. _userDetail(),
  107. _buildSwitchButtom(
  108. I18n.of(context).hide_me, I18n.of(context).hide_me, parkHidden, () {
  109. setUserDetailData(4, !parkHidden ? 1 : 0, 0, () {
  110. setState(() {
  111. parkHidden = !parkHidden;
  112. });
  113. });
  114. }),
  115. _buildSwitchButtom(I18n.of(context).hide_distance,
  116. I18n.of(context).hide_distance, distanceHidden, () {
  117. setUserDetailData(5, !distanceHidden ? 1 : 0, 0, () {
  118. setState(() {
  119. distanceHidden = !distanceHidden;
  120. });
  121. });
  122. }),
  123. _buildSwitchButtom(
  124. I18n.of(context).chat_setting, I18n.of(context).chat_me, msgHidden,
  125. () {
  126. setUserDetailData(7, !msgHidden ? 1 : 0, 0, () {
  127. setState(() {
  128. msgHidden = !msgHidden;
  129. });
  130. });
  131. }),
  132. _buildSwitchButtom(I18n.of(context).stranger,
  133. I18n.of(context).receive_stranger, strangerHidden, () {
  134. setUserDetailData(8, !strangerHidden ? 1 : 0, 0, () {
  135. setState(() {
  136. strangerHidden = !strangerHidden;
  137. });
  138. });
  139. }),
  140. _buildBlackList(),
  141. ],
  142. );
  143. }
  144. Widget _buildBlackList() {
  145. //版本
  146. return Container(
  147. margin: EdgeInsets.only(top: 20, bottom: 20),
  148. padding: EdgeInsets.symmetric(horizontal: 5),
  149. child: FullWidthButton(
  150. showRightIcon: true,
  151. title: I18n.of(context).blacklist2,
  152. showDivider: false,
  153. onPressed: () {
  154. Navigator.of(context).push(
  155. new MaterialPageRoute(
  156. builder: (context) {
  157. return WhiteAndBlackPage(
  158. isWhite: false,
  159. );
  160. },
  161. ),
  162. );
  163. },
  164. ),
  165. decoration: BoxDecoration(
  166. color: Colors.white,
  167. border: Border(
  168. top: Constants.GreyBorderSide, bottom: Constants.GreyBorderSide)),
  169. );
  170. }
  171. //下划线
  172. Widget _buildDivider() {
  173. return new Container(
  174. margin: EdgeInsets.zero,
  175. padding: EdgeInsets.zero,
  176. decoration:
  177. BoxDecoration(border: Border(bottom: Constants.GreyBorderSide)),
  178. height: 1,
  179. width: MediaQuery.of(context).size.width,
  180. );
  181. }
  182. Widget _buildRadioButtom(str, radio, callback) {
  183. Widget left = new Text(
  184. str,
  185. textScaleFactor: 1.0,
  186. style: TextStyle(fontSize: 13, color: Constants.BlackTextColor),
  187. );
  188. Widget right = new Expanded(
  189. child: new Align(
  190. alignment: Alignment.centerRight,
  191. child: radio,
  192. ));
  193. return InkWell(
  194. onTap: () {
  195. callback();
  196. },
  197. child: Container(
  198. padding: EdgeInsets.only(left: 15),
  199. child: new Row(
  200. children: <Widget>[left, right],
  201. ),
  202. ),
  203. );
  204. }
  205. //个人详情
  206. Widget _userDetail() {
  207. Widget tip = CustomUI.buildTopTip(15, I18n.of(context).personal_details);
  208. openCallback() {
  209. setUserDetailData(1, 1, 0, () {
  210. setState(() {
  211. _socialType = userDetail.open.index;
  212. });
  213. });
  214. }
  215. payCallback() {
  216. if (UserData().picNum == 0) {
  217. showToast(UserData().haveReview
  218. ? I18n.of(context).have_picture_view
  219. : I18n.of(context).first_upload);
  220. return;
  221. }
  222. var callback = () {
  223. Navigator.of(context).pop();
  224. int minMoney = 10;
  225. var confirm =
  226. CustomUI.buildConfirmBotton(I18n.of(context).determine, () {
  227. if (money == null || money == "" || int.parse(money) < minMoney) {
  228. showToast(I18n.of(context)
  229. .little_min
  230. .replaceFirst('/s1', minMoney.toString()));
  231. return;
  232. }
  233. setUserDetailData(2, 1, money, () {
  234. Navigator.of(context).pop();
  235. money = '';
  236. setState(() {
  237. _socialType = userDetail.pay.index;
  238. });
  239. });
  240. });
  241. var tip = Column(
  242. children: <Widget>[
  243. Container(
  244. margin: EdgeInsets.only(top: 20),
  245. child: Text(
  246. I18n.of(context).set_amount1,
  247. style: TextStyle(color: Constants.BlackTextColor, fontSize: 16),
  248. ),
  249. ),
  250. Container(
  251. margin: EdgeInsets.only(top: 23, bottom: 25),
  252. decoration: BoxDecoration(
  253. color: Colors.grey[200],
  254. borderRadius: BorderRadius.all(Radius.circular(8))),
  255. child: TextField(
  256. keyboardAppearance: Brightness.light,
  257. textAlign: TextAlign.center,
  258. textInputAction: TextInputAction.search,
  259. style: TextStyle(
  260. textBaseline: TextBaseline.alphabetic, fontSize: 14),
  261. decoration: InputDecoration(
  262. hintText: I18n.of(context).enter_amount,
  263. filled: true,
  264. contentPadding: EdgeInsets.only(top: 10, bottom: 10),
  265. fillColor: Colors.transparent,
  266. border: InputBorder.none,
  267. ),
  268. keyboardType: TextInputType.phone,
  269. maxLines: 1,
  270. inputFormatters: [
  271. WhitelistingTextInputFormatter(RegExp("^([1-9][0-9]*)\$")),
  272. WhitelistingTextInputFormatter.digitsOnly,
  273. LengthLimitingTextInputFormatter(3)
  274. ],
  275. onChanged: (str) {
  276. money = str;
  277. },
  278. ),
  279. )
  280. ],
  281. );
  282. // var tip = Container(
  283. // margin: EdgeInsets.only(top: 20, bottom: 10),
  284. // child: TextField(
  285. // textAlign: TextAlign.center,
  286. // style: TextStyle(
  287. // textBaseline: TextBaseline.alphabetic, fontSize: 14),
  288. // decoration: InputDecoration(
  289. // hintText: I18n.of(context).enter_amount,
  290. // hintStyle: TextStyle(fontSize: 14),
  291. // contentPadding: EdgeInsets.all(10.0),
  292. // border: OutlineInputBorder(
  293. // borderRadius: BorderRadius.circular(5.0),
  294. // ),
  295. // ),
  296. // keyboardType: TextInputType.phone,
  297. // maxLines: 1,
  298. // inputFormatters: [
  299. // WhitelistingTextInputFormatter(RegExp("^([1-9][0-9]*)\$")),
  300. // WhitelistingTextInputFormatter.digitsOnly,
  301. // LengthLimitingTextInputFormatter(3)
  302. // ],
  303. // onChanged: (str) {
  304. // money = str;
  305. // },
  306. // ));
  307. var content = CustomUI.buildConfirmContent(tip, confirm);
  308. CustomUI.buildTip(context, '', content);
  309. };
  310. CustomUI.buildOneConfirm(context, I18n.of(context).must_pay,
  311. I18n.of(context).determine, callback);
  312. }
  313. applyCallback() {
  314. var callback = () {
  315. setUserDetailData(3, 1, 0, () {
  316. Navigator.of(context).pop();
  317. setState(() {
  318. _socialType = userDetail.apply.index;
  319. });
  320. });
  321. };
  322. CustomUI.buildOneConfirm(context, I18n.of(context).permission_choose,
  323. I18n.of(context).determine, callback);
  324. }
  325. Widget radio1 = new Radio(
  326. value: userDetail.open.index,
  327. groupValue: _socialType, //当value和groupValue一致的时候则选中
  328. onChanged: (T) {
  329. openCallback();
  330. });
  331. Widget radio2 = new Radio(
  332. value: userDetail.pay.index,
  333. groupValue: _socialType, //当value和groupValue一致的时候则选中
  334. onChanged: (T) {
  335. payCallback();
  336. });
  337. Widget radio3 = new Radio(
  338. value: userDetail.apply.index,
  339. groupValue: _socialType, //当value和groupValue一致的时候则选中
  340. onChanged: (T) {
  341. applyCallback();
  342. });
  343. List<Widget> basicList = [
  344. _buildRadioButtom(I18n.of(context).public, radio1, openCallback),
  345. _buildDivider(),
  346. _buildRadioButtom(I18n.of(context).paid_album, radio2, payCallback),
  347. _buildDivider(),
  348. _buildRadioButtom(
  349. I18n.of(context).need_permission, radio3, applyCallback),
  350. ];
  351. var socialCard = new Container(
  352. color: Colors.white,
  353. child: new Column(
  354. children: basicList,
  355. ),
  356. );
  357. return new Column(
  358. children: <Widget>[tip, socialCard],
  359. );
  360. }
  361. Widget _buildSwitchButtom(title, str, value, callback) {
  362. Widget tip = CustomUI.buildTopTip(15, title);
  363. Widget left = Expanded(
  364. child: Text(
  365. str,
  366. textScaleFactor: 1.0,
  367. style: TextStyle(fontSize: 13, color: Constants.BlackTextColor),
  368. ));
  369. Widget right = Container(
  370. child: new Align(
  371. alignment: Alignment.centerRight,
  372. child: new Switch(
  373. value: value,
  374. activeTrackColor: Constants.ConfrimButtonColor.withOpacity(0.3),
  375. onChanged: (bool val) {
  376. callback();
  377. },
  378. )));
  379. var socialCard = new Container(
  380. color: Colors.white,
  381. padding: EdgeInsets.only(left: 15),
  382. height: 53,
  383. child: new Row(
  384. children: <Widget>[left, right],
  385. ),
  386. );
  387. return new Column(
  388. children: <Widget>[tip, socialCard],
  389. );
  390. }
  391. }