Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
ChatGPT
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
关振斌
ChatGPT
Commits
4164aeb6
Commit
4164aeb6
authored
Jul 18, 2023
by
netyouli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加计算缓存大小和清理缓存功能
parent
025c75fa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
7 deletions
+42
-7
lib/main.dart
lib/main.dart
+2
-0
lib/pages/my/controller.dart
lib/pages/my/controller.dart
+35
-4
lib/pages/my/view.dart
lib/pages/my/view.dart
+5
-3
No files found.
lib/main.dart
View file @
4164aeb6
...
...
@@ -23,6 +23,8 @@ void main() async {
// WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
// FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
await
Global
.
init
();
PaintingBinding
.
instance
.
imageCache
.
maximumSize
=
1000000
;
PaintingBinding
.
instance
.
imageCache
.
maximumSizeBytes
=
300
<<
20
;
Glassy
().
setConfig
(
GlassyConfig
(
radius:
16
,
backgroundColor:
Color
.
fromARGB
(
255
,
217
,
217
,
217
),
...
...
lib/pages/my/controller.dart
View file @
4164aeb6
...
...
@@ -4,19 +4,21 @@ import 'dart:io';
import
'package:chart/common/apis/apis.dart'
;
import
'package:chart/common/store/user.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_easyloading/flutter_easyloading.dart'
;
import
'package:get/get.dart'
;
import
'package:intl/intl.dart'
;
import
'package:share_plus/share_plus.dart'
;
import
'package:in_app_review/in_app_review.dart'
;
import
'../../common/routers/names.dart'
;
import
'models.dart'
;
class
MyController
extends
GetxController
{
var
cacheSize
=
16.43
.
obs
;
var
cacheSize
=
"0 B"
.
obs
;
var
userInfo
=
Rx
<
UserInfoData
>(
UserInfoData
(
username:
"未登录"
));
var
expireInfo
=
"--"
.
obs
;
@override
void
onInit
()
{
// TODO: implement onInit
...
...
@@ -26,8 +28,31 @@ class MyController extends GetxController {
ever
(
UserStore
.
to
.
loginDidChange
,
(
didChange
)
{
requestUserInfo
();
});
cacheSize
.
value
=
getAllSizeOfCacheImages
();
}
//读取图片缓存大小
String
getAllSizeOfCacheImages
(){
ImageCache
?
imageCache
=
PaintingBinding
.
instance
.
imageCache
;
String
cacheSizeStr
=
'0 kb'
;
int
byte
=
imageCache
.
currentSizeBytes
;
if
(
byte
>=
0
&&
byte
<
1024
)
{
cacheSizeStr
=
'
$byte
B'
;
}
else
if
(
byte
>=
1024
&&
byte
<
1024
*
1024
)
{
double
size
=
(
byte
*
1.0
/
1024
);
String
sizeStr
=
size
.
toStringAsFixed
(
2
);
cacheSizeStr
=
'
$sizeStr
KB'
;
}
else
{
double
size
=
(
byte
*
1.0
/
1024
)
/
1024
;
String
sizeStr
=
size
.
toStringAsFixed
(
2
);
cacheSizeStr
=
'
$sizeStr
MB'
;
}
return
cacheSizeStr
;
}
refreshCacheShow
()
{
cacheSize
.
value
=
getAllSizeOfCacheImages
();
}
goShare
()
async
{
await
Share
.
shareWithResult
(
...
...
@@ -44,8 +69,14 @@ class MyController extends GetxController {
}
goClearCache
()
{
cacheSize
.
value
=
0.0
;
EasyLoading
.
showSuccess
(
"清理成功"
);
if
(
cacheSize
.
value
==
"0 B"
)
{
EasyLoading
.
showToast
(
"已经清理"
);
}
else
{
ImageCache
imageCache
=
PaintingBinding
.
instance
.
imageCache
;
imageCache
.
clear
();
cacheSize
.
value
=
getAllSizeOfCacheImages
();
EasyLoading
.
showSuccess
(
"清理成功"
);
}
}
void
goPay
()
{
...
...
lib/pages/my/view.dart
View file @
4164aeb6
...
...
@@ -76,7 +76,8 @@ class MyPage extends GetView<MyController> {
Expanded
(
child:
InkWell
(
onTap:
()
{
Get
.
toNamed
(
AppRoutes
.
MY_WORK
,
arguments:
{
"operator"
:
"work"
});
Get
.
toNamed
(
AppRoutes
.
MY_WORK
,
arguments:
{
"operator"
:
"work"
})
?.
then
((
value
)
=>
controller
.
refreshCacheShow
());
},
child:
Column
(
children:
[
...
...
@@ -107,7 +108,8 @@ class MyPage extends GetView<MyController> {
Expanded
(
child:
InkWell
(
onTap:
()
{
Get
.
toNamed
(
AppRoutes
.
MY_WORK
,
arguments:
{
"operator"
:
"collect"
});
Get
.
toNamed
(
AppRoutes
.
MY_WORK
,
arguments:
{
"operator"
:
"collect"
})
?.
then
((
value
)
=>
controller
.
refreshCacheShow
());
},
child:
Column
(
children:
[
...
...
@@ -306,7 +308,7 @@ class MyPage extends GetView<MyController> {
hasBottomLine:
false
,
rightItem:
Container
(
padding:
const
EdgeInsets
.
fromLTRB
(
0
,
0
,
10
,
0
),
child:
Obx
(()
=>
Text
(
"
${controller.cacheSize.value}
MB"
)),
child:
Obx
(()
=>
Text
(
controller
.
cacheSize
.
value
)),
),
onClick:
()
{
controller
.
goClearCache
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment