@@ -30,25 +30,20 @@ class UserPage extends StatefulWidget {
30
30
}
31
31
32
32
class _UserPageState extends State <UserPage > {
33
- late String _appVersion;
34
- late SettingConfig config = SettingConfig ();
33
+ String ? _appVersion;
34
+ SettingConfig config = SettingConfig ();
35
35
User ? _me;
36
- late String _baseUrl;
36
+ String _baseUrl = "" ;
37
37
final FocusNode _proxyUrlFocusNode = FocusNode ();
38
38
final TextEditingController _proxyUrlController = TextEditingController ();
39
39
String _filePath = "" ;
40
- double _updateDownloadProgress = 0 ;
40
+ final ValueNotifier < double > _updateDownloadProgress = ValueNotifier ( 0 ) ;
41
41
42
42
Future <void > _fetchAppVersion () async {
43
43
PackageInfo packageInfo = await PackageInfo .fromPlatform ();
44
44
_appVersion = packageInfo.version;
45
45
}
46
46
47
- Future <String > _getAppVersion () async {
48
- await _fetchAppVersion ();
49
- return _appVersion;
50
- }
51
-
52
47
Future <void > _loadSettingConfig () async {
53
48
config = await SharedPrefsUtils .getSettingConfig ();
54
49
if (config.proxyUrl != "" ) {
@@ -75,6 +70,7 @@ class _UserPageState extends State<UserPage> {
75
70
_fetchAppVersion ();
76
71
_loadSettingConfig ();
77
72
_fetchMe ();
73
+ _fetchAppVersion ();
78
74
}
79
75
80
76
Future <void > _fetchMe () async {
@@ -83,10 +79,10 @@ class _UserPageState extends State<UserPage> {
83
79
setState (() {});
84
80
}
85
81
86
- Future <String > _fetchBaseUrl () async {
82
+ Future <void > _fetchBaseUrl () async {
87
83
AuthParams authParams = await AuthApi ().getAuthParams ();
88
84
_baseUrl = authParams.baseUrl;
89
- return _baseUrl ;
85
+ setState (() {}) ;
90
86
}
91
87
92
88
String getAvatarTitle (User ? user) {
@@ -98,13 +94,13 @@ class _UserPageState extends State<UserPage> {
98
94
}
99
95
100
96
Widget _buildAppbarUser () {
101
- if (_me == null ) return const CircularProgressIndicator ();
97
+ if (_me == null || _baseUrl == "" ) return const CircularProgressIndicator ();
102
98
return Row (
103
99
children: [
104
100
CircleAvatar (
105
101
radius: 28 , // 半径控制头像的大小
106
- backgroundImage: NetworkImage (
107
- UrlUtils .getCoverUrl (_baseUrl, _me? .avatar ?? "" )),
102
+ backgroundImage:
103
+ NetworkImage ( UrlUtils .getCoverUrl (_baseUrl, _me? .avatar ?? "" )),
108
104
),
109
105
const SizedBox (
110
106
width: 10 ,
@@ -131,7 +127,8 @@ class _UserPageState extends State<UserPage> {
131
127
],
132
128
),
133
129
],
134
- );;
130
+ );
131
+ ;
135
132
}
136
133
137
134
@override
@@ -140,10 +137,6 @@ class _UserPageState extends State<UserPage> {
140
137
appBar: AppBar (
141
138
backgroundColor: Colors .white,
142
139
title: _buildAppbarUser (),
143
- // title: const CircleAvatar(
144
- // radius: 32.5, // 半径控制头像的大小
145
- // backgroundImage: NetworkImage('https://ikaros.run/img/favicon.ico'),
146
- // ),
147
140
actionsIconTheme: const IconThemeData (
148
141
color: Colors .black,
149
142
size: 35 ,
@@ -168,79 +161,59 @@ class _UserPageState extends State<UserPage> {
168
161
),
169
162
],
170
163
),
171
- // appBar: PreferredSize(
172
- // preferredSize: const DartUi.Size.fromHeight(70.0),
173
- // child: AppBar(
174
- // backgroundColor: Colors.white,
175
- // title: const CircleAvatar(
176
- // radius: 32.5, // 半径控制头像的大小
177
- // backgroundImage: NetworkImage('https://ikaros.run/img/favicon.ico'),
178
- // ),
179
- // actionsIconTheme: const IconThemeData(
180
- // color: Colors.black,
181
- // size: 35,
182
- // ),
183
- // actions: <Widget>[
184
- // PopupMenuButton<String>(
185
- // itemBuilder: (BuildContext context) => <PopupMenuItem<String>>[
186
- // _selectView(Icons.update, "更新", "app_update"),
187
- // _selectView(Icons.exit_to_app_rounded, '退出', 'user_logout'),
188
- // ],
189
- // onSelected: (String action) {
190
- // // 点击选项的时候
191
- // switch (action) {
192
- // case 'user_logout':
193
- // _userLogout();
194
- // break;
195
- // case 'app_update':
196
- // _checkAppUpdate();
197
- // break;
198
- // }
199
- // },
200
- // ),
201
- // ],
202
- // ),
203
- // ),
204
164
body: ListView (
205
165
children: [
206
166
Setting (
207
167
title: "版本号" ,
208
168
subtitle: "这是APP当前的版本号" ,
209
- rightWidget: FutureBuilder (
210
- future: _getAppVersion (),
211
- builder: (context, snapshot) {
212
- if (snapshot.connectionState == ConnectionState .done) {
213
- if (snapshot.hasError) {
214
- return Text (
215
- "Load app version error: ${snapshot .error ?? "" }" );
216
- } else {
217
- if (_updateDownloadProgress > 0 &&
218
- _updateDownloadProgress < 100 ) {
219
- return Center (
169
+ rightWidget: ValueListenableBuilder <double >(
170
+ valueListenable: _updateDownloadProgress,
171
+ builder: (context, progress, child) {
172
+ if (_updateDownloadProgress.value > 0 &&
173
+ _updateDownloadProgress.value < 100 ) {
174
+ return Stack (
175
+ alignment: Alignment .center,
176
+ children: [
177
+ Center (
220
178
child: CircularProgressIndicator (
221
- value: _updateDownloadProgress / 100 , // 设置进度
222
- strokeWidth: 6 .0 , // 设置圆圈的宽度
179
+ value: _updateDownloadProgress.value / 100 , // 设置进度
180
+ strokeWidth: 12 .0 , // 设置圆圈的宽度
223
181
valueColor: const AlwaysStoppedAnimation <Color >(
224
- Colors .pink ), // 设置颜色
182
+ Colors .blueAccent ), // 设置颜色
225
183
),
226
- );
227
- } else if (_updateDownloadProgress == 100 ) {
228
- return OutlinedButton (
229
- onPressed: () {
230
- _installPackage ();
231
- },
232
- child: const Text ("点击安装" ));
233
- }
234
- return Text (
235
- "v${snapshot .data ?? "0.0.0" }" ,
236
- style: const TextStyle (fontSize: 20 ),
237
- );
238
- }
239
- } else {
240
- return const Center (
241
- child: CircularProgressIndicator (),
184
+ ),
185
+ Text (
186
+ '${_updateDownloadProgress .value .toInt ()}%' , // 显示百分比
187
+ style: const TextStyle (
188
+ fontSize: 16.0 , fontWeight: FontWeight .bold),
189
+ ),
190
+ ],
191
+ );
192
+ return Center (
193
+ child: CircularProgressIndicator (
194
+ value: _updateDownloadProgress.value / 100 ,
195
+ // 设置进度
196
+ strokeWidth: 12.0 ,
197
+ // 设置圆圈的宽度
198
+ semanticsLabel: '安装包下载中' ,
199
+ semanticsValue: '已完成 ${_updateDownloadProgress .value }%' ,
200
+ valueColor: const AlwaysStoppedAnimation <Color >(
201
+ Colors .blueAccent), // 设置颜色
202
+ ),
242
203
);
204
+ } else if (_updateDownloadProgress.value == 100 ) {
205
+ return OutlinedButton (
206
+ onPressed: () {
207
+ _installPackage ();
208
+ },
209
+ child: const Text ("点击安装" ));
243
210
}
211
+ return _appVersion != null
212
+ ? Text (
213
+ "v$_appVersion " ,
214
+ style: const TextStyle (fontSize: 20 ),
215
+ )
216
+ : const CircularProgressIndicator ();
244
217
}),
245
218
),
246
219
Setting (
@@ -443,14 +416,11 @@ class _UserPageState extends State<UserPage> {
443
416
if (! tmpUpdateFile.existsSync ()) {
444
417
_configProxy (Dio ()).download (downloadUrl, _filePath,
445
418
onReceiveProgress: (received, total) {
446
- double progress = (received / total) * 100 ;
447
- setState (() {
448
- _updateDownloadProgress = progress;
449
- });
419
+ _updateDownloadProgress.value = (received / total) * 100 ;
450
420
});
451
421
} else {
452
422
setState (() {
453
- _updateDownloadProgress = 100 ;
423
+ _updateDownloadProgress.value = 100 ;
454
424
});
455
425
}
456
426
}
@@ -471,9 +441,7 @@ class _UserPageState extends State<UserPage> {
471
441
if (Platform .isWindows) {
472
442
_startUpdateProcess (_filePath);
473
443
}
474
- setState (() {
475
- _updateDownloadProgress = 0 ;
476
- });
444
+ _updateDownloadProgress.value = 0 ;
477
445
}
478
446
479
447
void _startUpdateProcess (String zipPath) async {
0 commit comments