123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- import 'dart:io';
- import 'package:flutter/material.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:jpush_flutter/jpush_flutter.dart';
- import 'package:path_provider/path_provider.dart';
- import 'package:ysairplane2/base/YSBase.dart';
- import 'package:ysairplane2/code/YSChangePayPass.dart';
- import 'package:ysairplane2/code/YSLogin.dart';
- import 'package:ysairplane2/code/YSSetPayPass.dart';
- import 'package:ysairplane2/tools/YSNetWorking.dart';
- import 'package:ysairplane2/tools/YSTools.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- class YSSetting extends StatefulWidget {
- @override
- _YSSettingState createState() => _YSSettingState();
- }
- class _YSSettingState extends State<YSSetting> {
- String cacheSizeStr = '0.0B';
- bool _isOpen = false;
- @override
- void initState() {
- Future.delayed(Duration(seconds: 0)).then((value){
- loadCache();
- });
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return YSBase(
- ystitle: '系统设置',
- yschild: Container(
- height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-44,
- width: MediaQuery.of(context).size.width,
- color: Color(0xFFF5F6F8),
- child: Column(
- children: [
- Container(
- margin: EdgeInsets.only(top: 10,bottom: 0.5),
- padding: EdgeInsets.only(left: 15,right: 15),
- height: 50,
- color: Colors.white,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text('消息通知',style: TextStyle(fontSize: 16,color: Color(0xFF000000)),),
- GestureDetector(
- onTap: (){
- setState(() {
- _isOpen = !_isOpen;
- });
- },
- child: Container(
- height: hsp(60),
- width: hsp(100),
- child: Image.asset(_isOpen==false?'lib/images/kaiguankai.png':'lib/images/kaiguanguan.png'),
- ),
- )
- ],
- ),
- ),
- GestureDetector(
- onTap: (){
- showDialog(
- context:context,
- builder:(context){
- return AlertDialog(
- title: Text('提示',style: TextStyle(fontSize: 16,color: Color(0xFF292929),decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
- content: Text('确认清除缓存?',style: TextStyle(fontSize: 13,color: Color(0xFF292929),decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
- actions: [
- CupertinoButton(
- padding: EdgeInsets.all(0),
- child: Text('取消',style: TextStyle(fontSize: 13,color: Color(0xFF292929),decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
- onPressed: (){
- Navigator.pop(context);
- },
- ),
- CupertinoButton(
- padding: EdgeInsets.all(0),
- child: Text('确认',style: TextStyle(fontSize: 13,color: Color(0xFF292929),decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
- onPressed: (){
- Navigator.pop(context);
- _clearCache();
- },
- ),
- ],
- );
- }
- );
- },
- child: Container(
- padding: EdgeInsets.only(left: 15,right: 15),
- height: 50,
- color: Colors.white,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text('清理缓存',style: TextStyle(fontSize: 16,color: Color(0xFF000000)),),
- Row(
- children: [
- Text(cacheSizeStr!=null?cacheSizeStr:'',style: TextStyle(color: Color(0xFF9A9A9A),fontSize: 16),),
- Icon(Icons.keyboard_arrow_right,size: 20,color: Color(0xFF9A9A9A),)
- ],
- )
- ],
- ),
- ),
- ),
- ListView.separated(
- itemBuilder: (context,index){
- return GestureDetector(
- onTap: (){
- Navigator.of(context).push(
- CupertinoPageRoute(
- builder: (context){
- return index==0?YSSetPayPass():YSChangeOldPayPass();
- }
- )
- );
- },
- child: Container(
- padding: EdgeInsets.only(left: 15,right: 15),
- height: 50,
- color: Colors.white,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(index==0?'设置支付密码':'修改支付密码',style: TextStyle(fontSize: 16,color: Color(0xFF000000)),),
- Icon(Icons.keyboard_arrow_right,size: 20,color: Color(0xFF9A9A9A),)
- ],
- ),
- ),
- );
- },
- separatorBuilder: (context,index){
- return Divider(color: Color(0xFFF5F6F8),height: 0.5,thickness: 0.5,);
- },
- itemCount: 2,
- padding: EdgeInsets.only(top: hsp(20)),
- shrinkWrap: true,
- physics: NeverScrollableScrollPhysics(),
- ),
- GestureDetector(
- child: Container(
- margin: EdgeInsets.only(top: 35),
- height: 45,
- width: MediaQuery.of(context).size.width-40,
- alignment: Alignment.center,
- decoration: BoxDecoration(
- color: Color(0xFF007AFF),
- borderRadius: BorderRadius.all(Radius.circular(6))
- ),
- child: Text('退出当前账号',style: TextStyle(fontSize: 17,color: Colors.white,fontWeight: FontWeight.bold),),
- ),
- onTap: (){
- Navigator.of(context).pushAndRemoveUntil(
- CupertinoPageRoute(
- builder: (context){
- Future<SharedPreferences> _prefer = SharedPreferences.getInstance();
- _prefer.then((value){
- value.remove('token');
- });
- return YSLogin(isOut: true,);
- }
- ), (route) => false);
- final JPush jpush = new JPush();
- jpush.deleteAlias();
- },
- )
- ],
- ),
- ),
- );
- }
- void _clearCache() async {
- Directory tempDir = await getTemporaryDirectory();
- //删除缓存目录
- await delDir(tempDir);
- await loadCache();
- ysFlutterToast(context, '清除缓存成功');
- }
- Future<Null> delDir(FileSystemEntity file) async {
- if (file is Directory) {
- final List<FileSystemEntity> children = file.listSync();
- for (final FileSystemEntity child in children) {
- var isHave =await child.exists(); //返回真假
- if(isHave){
- await delDir(child);
- }
- }
- }
- await file.delete();
- }
- Future<Null> loadCache() async {
- Directory tempDir = await getTemporaryDirectory();
- double value = await _getTotalSizeOfFilesInDir(tempDir);
- /*tempDir.list(followLinks: false,recursive: true).listen((file){
- //打印每个缓存文件的路径
- print(file.path);
- });*/
- print('临时目录大小: ' + value.toString());
- setState(() {
- cacheSizeStr = _renderSize(value); // _cacheSizeStr用来存储大小的值
- });
- }
- Future<double> _getTotalSizeOfFilesInDir(final FileSystemEntity file) async {
- if (file is File) {
- int length = await file.length();
- return double.parse(length.toString());
- }
- if (file is Directory) {
- final List<FileSystemEntity> children = file.listSync();
- double total = 0;
- if (children != null)
- for (final FileSystemEntity child in children)
- total += await _getTotalSizeOfFilesInDir(child);
- return total;
- }
- return 0;
- }
- _renderSize(double value) {
- if (null == value) {
- return 0;
- }
- List<String> unitArr = List()
- ..add('B')
- ..add('K')
- ..add('M')
- ..add('G');
- int index = 0;
- while (value > 1024) {
- index++;
- value = value / 1024;
- }
- String size = value.toStringAsFixed(2);
- return size + unitArr[index];
- }
- }
|