import 'package:flutter/material.dart'; import 'package:get_it/get_it.dart'; import 'package:provider/provider.dart'; import 'package:sport/bean/bind_info.dart'; import 'package:sport/pages/setting/bind_phone_page.dart'; import 'package:sport/pages/setting/reset_password.dart'; import 'package:sport/provider/user_model.dart'; import 'package:sport/router/navigator_util.dart'; import 'package:sport/services/api/inject_api.dart'; import 'package:sport/services/api/login_api.dart'; import 'package:sport/sharesdk/tencent.dart'; import 'package:sport/sharesdk/tencent_api_resp.dart'; import 'package:sport/sharesdk/wechat.dart'; import 'package:sport/utils/toast.dart'; import 'package:sport/widgets/appbar.dart'; import 'package:sport/widgets/button_cancel.dart'; import 'package:sport/widgets/button_primary.dart'; import 'package:sport/widgets/dialog/alert_dialog.dart'; import 'package:sport/widgets/dialog/request_dialog.dart'; import 'package:sport/widgets/image.dart'; import 'package:sport/widgets/list_tile.dart'; import 'package:sport/widgets/loading.dart'; import 'package:sport/widgets/space.dart'; import 'package:tencent_kit/tencent_kit.dart'; import 'package:wechat_kit/wechat_kit.dart'; class AccountPage extends StatefulWidget { @override State createState() => _PageState(); } class _PageState extends State with InjectLoginApi, TencentMixin, WechatMixin { BindInfoData? _data; bool _loading = true; @override listenWechatLoginMsg(AuthResp resp) async{ await request(context, () async { var data = await loginApi.bindWx(resp.code??""); if (data["code"] == 0) { ToastUtil.show("绑定成功"); setState(() { _data?.weixin = true; }); } }); } @override listenTencentLoginMsg(LoginResp loginResp, TencentUserInfoResp resp) async{ await request(context, () async { String? openid = loginResp.openid; if (openid == null) return; var data = await loginApi.bindQQ(openid); if (data["code"] == 0) { ToastUtil.show("绑定成功"); setState(() { _data?.qq = true; }); } }); } @override void initState() { super.initState(); initData(); } initData() async { BindInfo bindInfo = await loginApi.getBindInfo(); setState(() { _loading = false; _data = bindInfo.data; }); } @override Widget build(BuildContext context) { const contentPadding = EdgeInsets.symmetric(horizontal: 0.0); return Scaffold( backgroundColor: Colors.white, body: LoadingWidget( loading: _loading, child: Column( children: [ Expanded( child: CustomScrollView( slivers: [ buildSliverAppBar(context, "帐号管理"), _data == null ? SliverToBoxAdapter( child: Container(), ) : SliverPadding( padding: const EdgeInsets.symmetric(horizontal: 12), sliver: SliverToBoxAdapter( child: Column( children: [ ListView( padding: EdgeInsets.zero, physics: NeverScrollableScrollPhysics(), shrinkWrap: true, children: divideTiles( includeLast: true, context: context, tiles: [ if (_data?.phone?.isNotEmpty == true) ListTile( title: Text('重置密码'), trailing: arrowRight5(), contentPadding: contentPadding, onTap: () { Navigator.push(context, MaterialPageRoute(builder: (context) { return RestPasswordWidget(_data?.password ?? false); })); }, ), ListTile( title: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text("绑定手机号"), Text( _data?.phone != null ? "${_data?.phone}" : " ", style: Theme.of(context).textTheme.bodyText2, ) ], ), contentPadding: contentPadding, trailing: arrowRight5(), onTap: () async { var result = await NavigatorUtil.goPage(context, (context) => BindPhonePage(change: true,)); if (result == true) { await initData(); ToastUtil.show("绑定成功"); } }, ), ListTile( title: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text("绑定微信"), _data?.weixin == true ? Text( "已绑定", style: Theme.of(context).textTheme.bodyText2, ) : Text( "未绑定", style: Theme.of(context).textTheme.bodyText2, ), ], ), contentPadding: contentPadding, trailing: arrowRight5(), onTap: () { wechatLogin(); }, ), ListTile( title: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text("绑定QQ"), _data?.qq == true ? Text( "已绑定", style: Theme.of(context).textTheme.bodyText2, ) : Text( "未绑定", style: Theme.of(context).textTheme.bodyText2, ), ], ), contentPadding: contentPadding, trailing: arrowRight5(), onTap: () { tencentLogin(); }, ), ], ).toList(), ), ], ), ), ), // SliverToBoxAdapter(child: Center( // child: GestureDetector( // onTap: () async { // if (await showDialog( // context: context, // builder: (context) => CustomAlertDialog(title: '是否注销帐号', ok: () => Navigator.of(context).pop(true)), // ) == // true) { // Provider.of(context, listen: false).logout(context); // } // }, // child: Padding( // padding: const EdgeInsets.symmetric(vertical: 50.0), // child: Text("- 注销帐号 -"), // ), // ), // ),) SliverPadding( padding: const EdgeInsets.symmetric(horizontal: 12), sliver: SliverToBoxAdapter( child: Column( children: [ Space( height: 50, ), InkWell( borderRadius: BorderRadius.all(Radius.circular(50.0)), child: Container( width: double.infinity, height: 44.0, alignment: Alignment.center, decoration: BoxDecoration( color: const Color(0xffFF5B1D), shape: BoxShape.rectangle, borderRadius: BorderRadius.all(Radius.circular(50.0)), ), child: Text( "注销帐号", style: Theme.of(context).textTheme.subtitle1!.copyWith(fontSize: 16.0, color: Colors.white), ), ), onTap: () async { if (await showDialog( context: context, builder: (context) => CustomAlertDialog( title: '是否注销帐号', child: Padding( padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 20.0), child: Text( "所有与该帐户相关的个人数据将被永久删除,不可恢复", style: Theme.of(context).textTheme.subtitle1?.copyWith(height: 1.5), ), ), ok: () => Navigator.of(context).pop(true)), ) == true) { if (await showDialog( context: context, barrierDismissible: false, builder: (context) => SimpleDialog( shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)), children: [_DeleteAccountWidget()], )) == true) {} } }, ), ], ), ), ), ], ), ), ], ), )); } } class _DeleteAccountWidget extends StatefulWidget { @override State createState() { return _DeleteAccountState(); } } class _DeleteAccountState extends State<_DeleteAccountWidget> { bool _agree = false; @override Widget build(BuildContext context) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: const EdgeInsets.all( 16.0), child: Center( child: Text( "是否注销帐号确认", style: Theme.of(context).textTheme.headline3, ), ), ), Padding( padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 20.0), child: Text( "该操作将会删除与该帐户相关的个人数据,请勾选同意按钮并继续", style: Theme.of(context).textTheme.subtitle1?.copyWith(height: 1.5, color: const Color(0xffFF5B1D)), ), ), Row( children: [ InkWell( onTap: () { setState(() { _agree = !_agree; }); }, child: Padding( padding: const EdgeInsets.fromLTRB(20.0, 10, 10, 10), child: Image.asset("lib/assets/img/${_agree ? "pop_icon_conneted" : "pop_icon_choose_normal"}.png"), ), ), Text( "同意注销帐号", style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1), fontSize: 12.0), ), ], ), Padding( padding: const EdgeInsets.fromLTRB(16.0, 20.0, 16.0, 16.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Expanded( child: CancelButton( height: 35, callback: () { Navigator.of(context).pop(false); }, content: "取消"), ), SizedBox( width: 16, ), Expanded(child: PrimaryButton(height: 35, callback: _agree ? () { request(context,() async { await GetIt.I().deleteUser(); }).then((value) => Provider.of(context, listen: false).logout(context)); } : null, content: "确定注销")) ], ), ) ], ); } }