account_page.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. import 'package:flutter/material.dart';
  2. import 'package:get_it/get_it.dart';
  3. import 'package:provider/provider.dart';
  4. import 'package:sport/bean/bind_info.dart';
  5. import 'package:sport/pages/setting/bind_phone_page.dart';
  6. import 'package:sport/pages/setting/reset_password.dart';
  7. import 'package:sport/provider/user_model.dart';
  8. import 'package:sport/router/navigator_util.dart';
  9. import 'package:sport/services/api/inject_api.dart';
  10. import 'package:sport/services/api/login_api.dart';
  11. import 'package:sport/sharesdk/tencent.dart';
  12. import 'package:sport/sharesdk/tencent_api_resp.dart';
  13. import 'package:sport/sharesdk/wechat.dart';
  14. import 'package:sport/utils/toast.dart';
  15. import 'package:sport/widgets/appbar.dart';
  16. import 'package:sport/widgets/button_cancel.dart';
  17. import 'package:sport/widgets/button_primary.dart';
  18. import 'package:sport/widgets/dialog/alert_dialog.dart';
  19. import 'package:sport/widgets/dialog/request_dialog.dart';
  20. import 'package:sport/widgets/image.dart';
  21. import 'package:sport/widgets/list_tile.dart';
  22. import 'package:sport/widgets/loading.dart';
  23. import 'package:sport/widgets/space.dart';
  24. import 'package:tencent_kit/tencent_kit.dart';
  25. import 'package:wechat_kit/wechat_kit.dart';
  26. class AccountPage extends StatefulWidget {
  27. @override
  28. State<StatefulWidget> createState() => _PageState();
  29. }
  30. class _PageState extends State<AccountPage> with InjectLoginApi, TencentMixin, WechatMixin {
  31. BindInfoData? _data;
  32. bool _loading = true;
  33. @override
  34. listenWechatLoginMsg(AuthResp resp) async{
  35. await request(context, () async {
  36. var data = await loginApi.bindWx(resp.code??"");
  37. if (data["code"] == 0) {
  38. ToastUtil.show("绑定成功");
  39. setState(() {
  40. _data?.weixin = true;
  41. });
  42. }
  43. });
  44. }
  45. @override
  46. listenTencentLoginMsg(LoginResp loginResp, TencentUserInfoResp resp) async{
  47. await request(context, () async {
  48. String? openid = loginResp.openid;
  49. if (openid == null) return;
  50. var data = await loginApi.bindQQ(openid);
  51. if (data["code"] == 0) {
  52. ToastUtil.show("绑定成功");
  53. setState(() {
  54. _data?.qq = true;
  55. });
  56. }
  57. });
  58. }
  59. @override
  60. void initState() {
  61. super.initState();
  62. initData();
  63. }
  64. initData() async {
  65. BindInfo bindInfo = await loginApi.getBindInfo();
  66. setState(() {
  67. _loading = false;
  68. _data = bindInfo.data;
  69. });
  70. }
  71. @override
  72. Widget build(BuildContext context) {
  73. const contentPadding = EdgeInsets.symmetric(horizontal: 0.0);
  74. return Scaffold(
  75. backgroundColor: Colors.white,
  76. body: LoadingWidget(
  77. loading: _loading,
  78. child: Column(
  79. children: [
  80. Expanded(
  81. child: CustomScrollView(
  82. slivers: <Widget>[
  83. buildSliverAppBar(context, "帐号管理"),
  84. _data == null
  85. ? SliverToBoxAdapter(
  86. child: Container(),
  87. )
  88. : SliverPadding(
  89. padding: const EdgeInsets.symmetric(horizontal: 12),
  90. sliver: SliverToBoxAdapter(
  91. child: Column(
  92. children: <Widget>[
  93. ListView(
  94. padding: EdgeInsets.zero,
  95. physics: NeverScrollableScrollPhysics(),
  96. shrinkWrap: true,
  97. children: divideTiles(
  98. includeLast: true,
  99. context: context,
  100. tiles: [
  101. if (_data?.phone?.isNotEmpty == true)
  102. ListTile(
  103. title: Text('重置密码'),
  104. trailing: arrowRight5(),
  105. contentPadding: contentPadding,
  106. onTap: () {
  107. Navigator.push(context, MaterialPageRoute(builder: (context) {
  108. return RestPasswordWidget(_data?.password ?? false);
  109. }));
  110. },
  111. ),
  112. ListTile(
  113. title: Row(
  114. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  115. children: <Widget>[
  116. Text("绑定手机号"),
  117. Text(
  118. _data?.phone != null ? "${_data?.phone}" : " ",
  119. style: Theme.of(context).textTheme.bodyText2,
  120. )
  121. ],
  122. ),
  123. contentPadding: contentPadding,
  124. trailing: arrowRight5(),
  125. onTap: () async {
  126. var result = await NavigatorUtil.goPage(context, (context) => BindPhonePage(change: true,));
  127. if (result == true) {
  128. await initData();
  129. ToastUtil.show("绑定成功");
  130. }
  131. },
  132. ),
  133. ListTile(
  134. title: Row(
  135. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  136. children: <Widget>[
  137. Text("绑定微信"),
  138. _data?.weixin == true
  139. ? Text(
  140. "已绑定",
  141. style: Theme.of(context).textTheme.bodyText2,
  142. )
  143. : Text(
  144. "未绑定",
  145. style: Theme.of(context).textTheme.bodyText2,
  146. ),
  147. ],
  148. ),
  149. contentPadding: contentPadding,
  150. trailing: arrowRight5(),
  151. onTap: () {
  152. wechatLogin();
  153. },
  154. ),
  155. ListTile(
  156. title: Row(
  157. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  158. children: <Widget>[
  159. Text("绑定QQ"),
  160. _data?.qq == true
  161. ? Text(
  162. "已绑定",
  163. style: Theme.of(context).textTheme.bodyText2,
  164. )
  165. : Text(
  166. "未绑定",
  167. style: Theme.of(context).textTheme.bodyText2,
  168. ),
  169. ],
  170. ),
  171. contentPadding: contentPadding,
  172. trailing: arrowRight5(),
  173. onTap: () {
  174. tencentLogin();
  175. },
  176. ),
  177. ],
  178. ).toList(),
  179. ),
  180. ],
  181. ),
  182. ),
  183. ),
  184. // SliverToBoxAdapter(child: Center(
  185. // child: GestureDetector(
  186. // onTap: () async {
  187. // if (await showDialog(
  188. // context: context,
  189. // builder: (context) => CustomAlertDialog(title: '是否注销帐号', ok: () => Navigator.of(context).pop(true)),
  190. // ) ==
  191. // true) {
  192. // Provider.of<UserModel>(context, listen: false).logout(context);
  193. // }
  194. // },
  195. // child: Padding(
  196. // padding: const EdgeInsets.symmetric(vertical: 50.0),
  197. // child: Text("- 注销帐号 -"),
  198. // ),
  199. // ),
  200. // ),)
  201. SliverPadding(
  202. padding: const EdgeInsets.symmetric(horizontal: 12),
  203. sliver: SliverToBoxAdapter(
  204. child: Column(
  205. children: <Widget>[
  206. Space(
  207. height: 50,
  208. ),
  209. InkWell(
  210. borderRadius: BorderRadius.all(Radius.circular(50.0)),
  211. child: Container(
  212. width: double.infinity,
  213. height: 44.0,
  214. alignment: Alignment.center,
  215. decoration: BoxDecoration(
  216. color: const Color(0xffFF5B1D),
  217. shape: BoxShape.rectangle,
  218. borderRadius: BorderRadius.all(Radius.circular(50.0)),
  219. ),
  220. child: Text(
  221. "注销帐号",
  222. style: Theme.of(context).textTheme.subtitle1!.copyWith(fontSize: 16.0, color: Colors.white),
  223. ),
  224. ),
  225. onTap: () async {
  226. if (await showDialog(
  227. context: context,
  228. builder: (context) => CustomAlertDialog(
  229. title: '是否注销帐号',
  230. child: Padding(
  231. padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 20.0),
  232. child: Text(
  233. "所有与该帐户相关的个人数据将被永久删除,不可恢复",
  234. style: Theme.of(context).textTheme.subtitle1?.copyWith(height: 1.5),
  235. ),
  236. ),
  237. ok: () => Navigator.of(context).pop(true)),
  238. ) ==
  239. true) {
  240. if (await showDialog(
  241. context: context,
  242. barrierDismissible: false,
  243. builder: (context) => SimpleDialog(
  244. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
  245. children: [_DeleteAccountWidget()],
  246. )) ==
  247. true) {}
  248. }
  249. },
  250. ),
  251. ],
  252. ),
  253. ),
  254. ),
  255. ],
  256. ),
  257. ),
  258. ],
  259. ),
  260. ));
  261. }
  262. }
  263. class _DeleteAccountWidget extends StatefulWidget {
  264. @override
  265. State<StatefulWidget> createState() {
  266. return _DeleteAccountState();
  267. }
  268. }
  269. class _DeleteAccountState extends State<_DeleteAccountWidget> {
  270. bool _agree = false;
  271. @override
  272. Widget build(BuildContext context) {
  273. return Column(
  274. crossAxisAlignment: CrossAxisAlignment.start,
  275. children: [
  276. Padding(
  277. padding: const EdgeInsets.all( 16.0),
  278. child: Center(
  279. child: Text(
  280. "是否注销帐号确认",
  281. style: Theme.of(context).textTheme.headline3,
  282. ),
  283. ),
  284. ),
  285. Padding(
  286. padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 20.0),
  287. child: Text(
  288. "该操作将会删除与该帐户相关的个人数据,请勾选同意按钮并继续",
  289. style: Theme.of(context).textTheme.subtitle1?.copyWith(height: 1.5, color: const Color(0xffFF5B1D)),
  290. ),
  291. ),
  292. Row(
  293. children: <Widget>[
  294. InkWell(
  295. onTap: () {
  296. setState(() {
  297. _agree = !_agree;
  298. });
  299. },
  300. child: Padding(
  301. padding: const EdgeInsets.fromLTRB(20.0, 10, 10, 10),
  302. child: Image.asset("lib/assets/img/${_agree ? "pop_icon_conneted" : "pop_icon_choose_normal"}.png"),
  303. ),
  304. ),
  305. Text(
  306. "同意注销帐号",
  307. style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1), fontSize: 12.0),
  308. ),
  309. ],
  310. ),
  311. Padding(
  312. padding: const EdgeInsets.fromLTRB(16.0, 20.0, 16.0, 16.0),
  313. child: Row(
  314. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  315. children: <Widget>[
  316. Expanded(
  317. child: CancelButton(
  318. height: 35,
  319. callback: () {
  320. Navigator.of(context).pop(false);
  321. },
  322. content: "取消"),
  323. ),
  324. SizedBox(
  325. width: 16,
  326. ),
  327. Expanded(child: PrimaryButton(height: 35, callback: _agree ? () {
  328. request(context,() async {
  329. await GetIt.I<LoginApi>().deleteUser();
  330. }).then((value) =>
  331. Provider.of<UserModel>(context, listen: false).logout(context));
  332. } : null, content: "确定注销"))
  333. ],
  334. ),
  335. )
  336. ],
  337. );
  338. }
  339. }