123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- 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<StatefulWidget> createState() => _PageState();
- }
- class _PageState extends State<AccountPage> 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: <Widget>[
- buildSliverAppBar(context, "帐号管理"),
- _data == null
- ? SliverToBoxAdapter(
- child: Container(),
- )
- : SliverPadding(
- padding: const EdgeInsets.symmetric(horizontal: 12),
- sliver: SliverToBoxAdapter(
- child: Column(
- children: <Widget>[
- 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: <Widget>[
- 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: <Widget>[
- 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: <Widget>[
- 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<UserModel>(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: <Widget>[
- 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<StatefulWidget> 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: <Widget>[
- 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: <Widget>[
- 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<LoginApi>().deleteUser();
- }).then((value) =>
- Provider.of<UserModel>(context, listen: false).logout(context));
- } : null, content: "确定注销"))
- ],
- ),
- )
- ],
- );
- }
- }
|