| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- import 'package:filesize/filesize.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:go_router/go_router.dart';
- import 'package:news_app/constant/size_res.dart';
- import 'package:news_app/extension/base.dart';
- import 'package:news_app/util/toast_util.dart';
- import '../../constant/api_const.dart';
- import '../../constant/color_res.dart';
- import '../../constant/config.dart';
- import '../../event/logout_event.dart';
- import '../../http/http_util.dart';
- import '../../main.dart';
- import '../../model/base_response.dart';
- import '../../model/user_model.dart';
- import '../../util/cache_util.dart';
- import '../../widget/my_txt.dart';
- /// @author: bo.zeng
- /// @email: cnhbwds@gmail.com
- /// @date: 2025 2025/4/9 16:00
- /// @description:
- class SettingPage extends ConsumerStatefulWidget {
- const SettingPage({super.key});
- @override
- ConsumerState<SettingPage> createState() => _SettingPageState();
- }
- class _SettingPageState extends ConsumerState<SettingPage> {
- final ValueNotifier<int> _cacheSize = ValueNotifier<int>(0);
- @override
- void initState() {
- super.initState();
- _loadCacheSize();
- }
- // 加载缓存大小
- Future<void> _loadCacheSize() async {
- final size = await CacheUtil.getCacheSize();
- _cacheSize.value = size;
- }
- // 清理缓存
- Future<void> _clearCache() async {
- try {
- await CacheUtil.clearCache();
- await _loadCacheSize();
- showToast('缓存已清除');
- } catch (e) {
- showToast('清理失败: $e');
- }
- }
- void logOutUserAction() async {
- final result = await HttpUtil().post(apiLogout, data: {});
- BaseResponse response = BaseResponse.fromJson(result);
- if (response.isSuccess) {
- showToast('注销成功');
- context.go('/main');
- eventBus.fire(LogoutEvent());
- } else {
- showToast("${response.msg}");
- }
- }
- void logOutUserAlertAction() {
- UserModel user = ref.watch(globalUserProvider);
- showDialog(
- context: context,
- builder: (BuildContext context) {
- return AlertDialog(
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(20),
- ),
- title: Text(
- '重要提醒',
- textAlign: TextAlign.center,
- style: TextStyle(
- fontSize: 18.sp,
- fontWeight: FontWeight.bold,
- color: Colors.red,
- ),
- ),
- content: SizedBox(
- width: MediaQuery.of(context).size.width * 0.8,
- height: 230.h,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- myTxt(
- text: '注销前请认真阅读以下重要提醒。账号注销后,您将无法再使用该账号,包括但不限于:',
- fontSize: 14.sp,
- fontWeight: FontWeight.bold,
- textAlign: TextAlign.left,
- maxLines: 10,
- ),
- myTxt(
- text:
- '1.无法登录、使用新消费传媒账号,并移除该账号下所有登录方式\n2.该账号下的个人资料和历史信息都将无法找回\n3.取消新消费传媒会员身份且无法恢复\n4.账号中所有的资产及权益被清除',
- fontSize: 14.sp,
- fontWeight: FontWeight.normal,
- textAlign: TextAlign.left,
- maxLines: 10,
- ),
- if (user.isShow == 1)
- myTxt(
- text: '5.无法继续在商城的交易、售后等流程',
- fontSize: 14.sp,
- fontWeight: FontWeight.normal,
- textAlign: TextAlign.left,
- maxLines: 10,
- ),
- ],
- ),
- ),
- actionsAlignment: MainAxisAlignment.center,
- actions: [
- GestureDetector(
- onTap: () {
- Navigator.of(context).pop();
- logOutUserAction();
- },
- child: Container(
- margin: EdgeInsets.symmetric(horizontal: 28.w),
- height: 42.h,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(20.r),
- gradient: LinearGradient(
- colors: [color5F59F7, color6592FD],
- begin: Alignment.centerLeft,
- end: Alignment.centerRight,
- ),
- ),
- alignment: Alignment.center,
- child: myTxt(text: "下一步", color: Colors.white, fontSize: 15.sp),
- ),
- ),
- ],
- );
- },
- );
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- backgroundColor: Colors.grey[200],
- appBar: AppBar(
- title: myTxt(text: '设置', fontSize: 18.sp, fontWeight: FontWeight.bold),
- centerTitle: true,
- ),
- body: Padding(
- padding: EdgeInsets.only(top: 10.h),
- child: Column(
- spacing: 10.h,
- children: [
- /* Switch(
- value: themeProvider.themeMode == ThemeMode.dark,
- onChanged: (value) {
- themeProvider.toggleTheme(value);
- },
- ),*/
- Container(
- color: Colors.white,
- child: Column(
- children: [
- // ListTile(
- // title: myTxt(text: "帐户管理", fontSize: 16.sp),
- // trailing: Icon(
- // Icons.arrow_forward_ios,
- // size: 16.sp,
- // color: Colors.grey,
- // ),
- // ),
- // Divider(
- // height: 0.1.h,
- // color: Colors.grey[200],
- // indent: horizontalPadding,
- // endIndent: horizontalPadding,
- // ),
- GestureDetector(
- onTap: () {
- context.push("/user/changePassword");
- },
- child: ListTile(
- title: myTxt(text: "密码管理", fontSize: 16.sp),
- trailing: Icon(
- Icons.arrow_forward_ios,
- size: 16.sp,
- color: Colors.grey,
- ),
- ),
- ),
- ],
- ),
- ),
- Container(
- color: Colors.white,
- child: Column(
- children: [
- GestureDetector(
- onTap: () {
- context.push("/user/privacy");
- },
- child: ListTile(
- title: myTxt(text: "隐私政策", fontSize: 16.sp),
- trailing: Icon(
- Icons.arrow_forward_ios,
- size: 16.sp,
- color: Colors.grey,
- ),
- ),
- ),
- Divider(
- height: 0.1.h,
- color: Colors.grey[200],
- indent: horizontalPadding,
- endIndent: horizontalPadding,
- ),
- ListTile(
- title: myTxt(text: "当前版本", fontSize: 16.sp),
- trailing: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- myTxt(text: "V1.0.0", color: Colors.grey),
- Icon(
- Icons.arrow_forward_ios,
- size: 16.sp,
- color: Colors.grey,
- ),
- ],
- ),
- ),
- Divider(
- height: 0.1.h,
- color: Colors.grey[200],
- indent: horizontalPadding,
- endIndent: horizontalPadding,
- ),
- GestureDetector(
- onTap: () {
- _clearCache();
- },
- child: ListTile(
- title: myTxt(text: "清除缓存", fontSize: 16.sp),
- trailing: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- // myTxt(text: "${filesize(size)}", color: Colors.grey),
- ValueListenableBuilder<int>(
- valueListenable: _cacheSize,
- builder: (context, size, _) {
- return myTxt(
- text: filesize(size),
- color: Colors.grey,
- );
- },
- ),
- Icon(
- Icons.arrow_forward_ios,
- size: 16.sp,
- color: Colors.grey,
- ),
- ],
- ),
- ),
- ),
- ],
- ),
- ),
- GestureDetector(
- onTap: () {
- // logOutUserAction();
- logOutUserAlertAction();
- },
- child: Container(
- color: Colors.white,
- alignment: Alignment.center,
- padding: EdgeInsets.symmetric(vertical: 12.h),
- child: myTxt(text: "注销帐户", color: Colors.red),
- ),
- ),
- GestureDetector(
- onTap: () {
- context.go('/main');
- eventBus.fire(LogoutEvent());
- },
- child: Container(
- color: Colors.white,
- alignment: Alignment.center,
- padding: EdgeInsets.symmetric(vertical: 12.h),
- child: myTxt(text: "退出登录", color: Colors.black),
- ),
- ),
- ],
- ),
- ),
- );
- }
- }
|