Skip to content

Commit eeb904a

Browse files
committed
修复更新时头像闪动的问题
1 parent 4a91be5 commit eeb904a

File tree

2 files changed

+39
-47
lines changed

2 files changed

+39
-47
lines changed

CHANGELOG.MD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
# 20.2.12
66

7+
- 修复更新时头像闪动的问题
8+
79
# 20.2.11
810

911
- 修正R2上的目录名

lib/user/user.dart

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class UserPage extends StatefulWidget {
3232
class _UserPageState extends State<UserPage> {
3333
late String _appVersion;
3434
late SettingConfig config = SettingConfig();
35-
late User? _me;
35+
User? _me;
3636
late String _baseUrl;
3737
final FocusNode _proxyUrlFocusNode = FocusNode();
3838
final TextEditingController _proxyUrlController = TextEditingController();
@@ -74,12 +74,13 @@ class _UserPageState extends State<UserPage> {
7474
super.initState();
7575
_fetchAppVersion();
7676
_loadSettingConfig();
77+
_fetchMe();
7778
}
7879

79-
Future<User?> _fetchMe() async {
80+
Future<void> _fetchMe() async {
8081
await _fetchBaseUrl();
8182
_me = await UserApi().getMe();
82-
return _me;
83+
setState(() {});
8384
}
8485

8586
Future<String> _fetchBaseUrl() async {
@@ -97,51 +98,40 @@ class _UserPageState extends State<UserPage> {
9798
}
9899

99100
Widget _buildAppbarUser() {
100-
return FutureBuilder(
101-
future: _fetchMe(),
102-
builder: (BuildContext context, AsyncSnapshot snapshot) {
103-
if (snapshot.connectionState == ConnectionState.done) {
104-
if (snapshot.hasError) {
105-
return Text("Load api base url error: ${snapshot.error}");
106-
} else {
107-
return Row(
108-
children: [
109-
CircleAvatar(
110-
radius: 28, // 半径控制头像的大小
111-
backgroundImage: NetworkImage(
112-
UrlUtils.getCoverUrl(_baseUrl, _me?.avatar ?? "")),
113-
),
114-
const SizedBox(
115-
width: 10,
116-
),
117-
Column(
118-
crossAxisAlignment: CrossAxisAlignment.start,
119-
children: [
120-
Text(
121-
getAvatarTitle(_me),
122-
style: const TextStyle(fontSize: 28),
123-
),
124-
if (_me?.introduce != null)
125-
Align(
126-
alignment: Alignment.bottomCenter,
127-
child: Text(
128-
_me?.introduce ?? "",
129-
style: const TextStyle(
130-
fontSize: 15, // 字体大小
131-
fontWeight: FontWeight.w500, // 字体粗细
132-
color: Colors.grey, // 字体颜色
133-
),
134-
),
135-
),
136-
],
101+
if (_me == null) return const CircularProgressIndicator();
102+
return Row(
103+
children: [
104+
CircleAvatar(
105+
radius: 28, // 半径控制头像的大小
106+
backgroundImage: NetworkImage(
107+
UrlUtils.getCoverUrl(_baseUrl, _me?.avatar ?? "")),
108+
),
109+
const SizedBox(
110+
width: 10,
111+
),
112+
Column(
113+
crossAxisAlignment: CrossAxisAlignment.start,
114+
children: [
115+
Text(
116+
getAvatarTitle(_me),
117+
style: const TextStyle(fontSize: 28),
118+
),
119+
if (_me?.introduce != null)
120+
Align(
121+
alignment: Alignment.bottomCenter,
122+
child: Text(
123+
_me?.introduce ?? "",
124+
style: const TextStyle(
125+
fontSize: 15, // 字体大小
126+
fontWeight: FontWeight.w500, // 字体粗细
127+
color: Colors.grey, // 字体颜色
137128
),
138-
],
139-
);
140-
}
141-
} else {
142-
return const CircularProgressIndicator();
143-
}
144-
});
129+
),
130+
),
131+
],
132+
),
133+
],
134+
);;
145135
}
146136

147137
@override

0 commit comments

Comments
 (0)