account_page.dart 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import 'package:flutter/material.dart';
  2. import 'package:sport/bean/bind_info.dart';
  3. import 'package:sport/pages/setting/bind_phone_page.dart';
  4. import 'package:sport/pages/setting/reset_password.dart';
  5. import 'package:sport/router/navigator_util.dart';
  6. import 'package:sport/services/api/inject_api.dart';
  7. import 'package:sport/sharesdk/tencent.dart';
  8. import 'package:sport/sharesdk/wechat.dart';
  9. import 'package:sport/utils/toast.dart';
  10. import 'package:sport/widgets/appbar.dart';
  11. import 'package:sport/widgets/dialog/request_dialog.dart';
  12. import 'package:sport/widgets/image.dart';
  13. import 'package:sport/widgets/list_tile.dart';
  14. import 'package:sport/widgets/loading.dart';
  15. class AccountPage extends StatefulWidget {
  16. @override
  17. State<StatefulWidget> createState() => _PageState();
  18. }
  19. class _PageState extends State<AccountPage> with InjectLoginApi, TencentMixin, WechatMixin {
  20. BindInfoData _data;
  21. bool _loading = true;
  22. @override
  23. void initState() {
  24. super.initState();
  25. initData();
  26. }
  27. initData() async {
  28. BindInfo bindInfo = await loginApi.getBindInfo();
  29. setState(() {
  30. _loading = false;
  31. _data = bindInfo.data;
  32. });
  33. }
  34. @override
  35. Widget build(BuildContext context) {
  36. const contentPadding = EdgeInsets.symmetric(horizontal: 0.0);
  37. return Scaffold(
  38. backgroundColor: Colors.white,
  39. body: LoadingWidget(
  40. loading: _loading,
  41. child: CustomScrollView(
  42. slivers: <Widget>[
  43. buildSliverAppBar(context, "帐号管理"),
  44. _data == null
  45. ? SliverToBoxAdapter(
  46. child: Container(),
  47. )
  48. : SliverPadding(
  49. padding: const EdgeInsets.symmetric(horizontal: 12),
  50. sliver: SliverToBoxAdapter(
  51. child: Column(
  52. children: <Widget>[
  53. ListView(
  54. padding: EdgeInsets.zero,
  55. physics: NeverScrollableScrollPhysics(),
  56. shrinkWrap: true,
  57. children: divideTiles(
  58. includeLast: true,
  59. context: context,
  60. tiles: [
  61. if (_data?.phone?.isNotEmpty == true)
  62. ListTile(
  63. title: Text('重置密码'),
  64. trailing: arrowRight5(),
  65. contentPadding: contentPadding,
  66. onTap: () {
  67. Navigator.push(context, MaterialPageRoute(builder: (context) {
  68. return RestPasswordWidget(_data.password);
  69. }));
  70. },
  71. ),
  72. ListTile(
  73. title: Row(
  74. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  75. children: <Widget>[
  76. Text("绑定手机号"),
  77. Text(
  78. _data.phone != null ? "${_data.phone}" : " ",
  79. style: Theme.of(context).textTheme.bodyText2,
  80. )
  81. ],
  82. ),
  83. contentPadding: contentPadding,
  84. trailing: arrowRight5(),
  85. onTap: () async {
  86. var result = await NavigatorUtil.goPage(context, (context) => BindPhonePage());
  87. if (result == true) {
  88. await initData();
  89. ToastUtil.show("绑定成功");
  90. }
  91. },
  92. ),
  93. ListTile(
  94. title: Row(
  95. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  96. children: <Widget>[
  97. Text("绑定微信"),
  98. _data.weixin
  99. ? Text(
  100. "已绑定",
  101. style: Theme.of(context).textTheme.bodyText2,
  102. )
  103. : Text(
  104. "未绑定",
  105. style: Theme.of(context).textTheme.bodyText2,
  106. ),
  107. ],
  108. ),
  109. contentPadding: contentPadding,
  110. trailing: arrowRight5(),
  111. onTap: () {
  112. wechatLogin((code) async {
  113. if (code == null) {
  114. ToastUtil.show("请先安装最新版的微信客户端");
  115. return;
  116. }
  117. await request(context, () async {
  118. var data = await loginApi.bindWx(code);
  119. if (data["code"] == 0) {
  120. ToastUtil.show("绑定成功");
  121. setState(() {
  122. _data.weixin = true;
  123. });
  124. }
  125. });
  126. });
  127. },
  128. ),
  129. ListTile(
  130. title: Row(
  131. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  132. children: <Widget>[
  133. Text("绑定QQ"),
  134. _data.qq
  135. ? Text(
  136. "已绑定",
  137. style: Theme.of(context).textTheme.bodyText2,
  138. )
  139. : Text(
  140. "未绑定",
  141. style: Theme.of(context).textTheme.bodyText2,
  142. ),
  143. ],
  144. ),
  145. contentPadding: contentPadding,
  146. trailing: arrowRight5(),
  147. onTap: () {
  148. qqlogin((login, userInfo) async {
  149. if (userInfo == null) {
  150. return;
  151. }
  152. await request(context, () async {
  153. String openid = login.openid;
  154. var data = await loginApi.bindQQ(openid);
  155. if (data["code"] == 0) {
  156. ToastUtil.show("绑定成功");
  157. setState(() {
  158. _data.qq = true;
  159. });
  160. }
  161. });
  162. });
  163. },
  164. ),
  165. ],
  166. ).toList(),
  167. ),
  168. ],
  169. ),
  170. ),
  171. ),
  172. ],
  173. ),
  174. ));
  175. }
  176. }