import 'dart:io'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_modular/flutter_modular.dart'; import 'package:peach/config/Colors.dart'; import 'package:peach/config/Index.dart'; import 'package:peach/utils/_.dart'; import 'package:peach/widget/CellWidget.dart'; import 'package:toast/toast.dart'; class Setting extends StatefulWidget { @override _Setting createState() => _Setting(); } class _Setting extends State { String cacheSize = "0.00B"; @override void initState() { ComputeCache(); } Future ComputeCache() async { String size = await ClearCache.loadCache(); setState(() { cacheSize = size; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( elevation: 0.0, title: Text("设置", style: TextStyle(color: ColorConfig.BlackBackColor),), centerTitle: true, backgroundColor: ColorConfig.WhiteBackColor, leading: GestureDetector( onTap: () { Navigator.of(context).pop(); }, child: Icon( Icons.arrow_back, color: ColorConfig.BlackBackColor, ), ), ), body: SingleChildScrollView( scrollDirection: Axis.vertical, physics: BouncingScrollPhysics(), child: Container( color: ColorConfig.LineColor, child: Column( children: [ CellWidget( leftText: Text("账号设置", style: TextStyle(fontSize: Screen.setFontSize(14),color: ColorConfig.TextColor)), onTap: () { // Modular.to.pushNamed(''); }, ), Divider(height: 1), CellWidget( leftText: Text("个人资料", style: TextStyle(fontSize: Screen.setFontSize(14),color: ColorConfig.TextColor)), onTap: () { // Modular.to.pushNamed(''); }, ), Divider(height: 1), CellWidget( leftText: Text("安全隐私", style: TextStyle(fontSize: Screen.setFontSize(14),color: ColorConfig.TextColor)), onTap: () { // Modular.to.pushNamed(''); }, ), Container( height: 18, ), Divider(height: 1), CellWidget( leftText: Text("推送设置", style: TextStyle(fontSize: Screen.setFontSize(14),color: ColorConfig.TextColor)), onTap: () { // Modular.to.pushNamed(''); }, ), Divider(height: 1), CellWidget( leftText: Text("消息设置", style: TextStyle(fontSize: Screen.setFontSize(14),color: ColorConfig.TextColor)), onTap: () { // Modular.to.pushNamed(''); }, ), Divider(height: 1), CellWidget( leftText: Text("屏蔽设置", style: TextStyle(fontSize: Screen.setFontSize(14),color: ColorConfig.TextColor)), onTap: () { // Modular.to.pushNamed(''); }, ), Divider(height: 1), CellWidget( leftText: Text("清理缓存", style: TextStyle(fontSize: Screen.setFontSize(14),color: ColorConfig.TextColor)), rightText: Text(cacheSize,style: TextStyle(fontSize: Screen.setFontSize(12),color: Color.fromARGB(87, 0, 0, 0))), onTap: () async { await showDialog( context: context, barrierDismissible: false, builder: (context) => WillPopScope( onWillPop: () async => false, child: AlertDialog( title: Row( children: [ Icon(Icons.delete), Text("清除缓存") ], ), content: Container( height: Screen.setHeight(50), child: Column( children: [ Text("此操作将删除您的App的所有缓存数据"), ], ), ), actions: [ FlatButton( child: Text('取消', style: TextStyle(color: ColorConfig.ThemeColor),), onPressed: () { Navigator.of(context).pop(); } ), FlatButton( child: Text("清除", style: TextStyle(color: ColorConfig.NoActiveColor),), onPressed: () async { Navigator.of(context).pop(); bool status = await ClearCache.clearCache(); await ComputeCache(); if (status) { Toast.show("清除成功", context, duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM); } } ), ], ), ) ); }, ), Divider(height: 1), CellWidget( leftText: Text("其他设置", style: TextStyle(fontSize: Screen.setFontSize(14),color: ColorConfig.TextColor)), onTap: () { // Modular.to.pushNamed(''); }, ), Container( height: 18, ), Divider(height: 1), CellWidget( leftText: Text("意见反馈", style: TextStyle(fontSize: Screen.setFontSize(14),color: ColorConfig.TextColor)), onTap: () { // Modular.to.pushNamed(''); }, ), Divider(height: 1), CellWidget( leftText: Text("检查更新", style: TextStyle(fontSize: Screen.setFontSize(14),color: ColorConfig.TextColor)), rightText: Text("v"+Config.packageInfo.version,style: TextStyle(fontSize: Screen.setFontSize(12),color: Color.fromARGB(87, 0, 0, 0))), onTap: () async { bool status = await CheckUpdate().check(context); if (!status) { Toast.show("已是最新版", context, duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM); } // Modular.to.pushNamed(''); }, ), Container( height: 18, ), InkWell( onTap: () async { await showDialog( context: context, barrierDismissible: false, builder: (context) => WillPopScope( onWillPop: () async => false, child: AlertDialog( title: Text("退出登录"), content: Container( height: Screen.setHeight(40), child: Column( children: [ Text("退出后无法再接受到好友消息,您确定退出此次登录吗?"), ], ), ), actions: [ FlatButton( child: Text('取消', style: TextStyle(color: ColorConfig.ThemeColor),), onPressed: () { Navigator.of(context).pop(); } ), FlatButton( child: Text("确定", style: TextStyle(color: ColorConfig.NoActiveColor),), onPressed: () async { await SPreferences().setBool("isLogin", false); Modular.to.pushReplacementNamed('/signUp'); } ), ], ), ) ); }, child: Container( height: 48, alignment: Alignment.center, color: ColorConfig.WhiteBackColor, width: Screen.width(context), child: Text("退出登录", style: TextStyle(fontSize: Screen.setFontSize(15)),), ), ) ], ), ), ) ); } }