修复webdav重新登录后,userID位置错位与页面跳转逻辑错误的重大bug

This commit is contained in:
2026-08-27 22:04:59 +08:00
parent bca1288bd1
commit ad6617592e
2 changed files with 37 additions and 35 deletions
+30 -29
View File
@@ -208,7 +208,7 @@ class _HomePageState extends BaseState<HomePage> {
if (renderBox != null) {
final height = renderBox.size.height;
if (height > 0 && height != _mediaLibraryHeight) {
setState(() {
safeSetState(() {
_mediaLibraryHeight = height;
_heightMeasureRetryCount = 0;
});
@@ -221,7 +221,7 @@ class _HomePageState extends BaseState<HomePage> {
const Duration(milliseconds: 200), _measureMediaLibraryHeight);
} else {
print('⚠️ 媒体库高度测量失败,使用默认值 280px');
setState(() {
safeSetState(() {
_mediaLibraryHeight = 280.0;
});
}
@@ -229,18 +229,18 @@ class _HomePageState extends BaseState<HomePage> {
}
void _onScroll() {
if (mounted) setState(() {});
if (mounted) safeSetState(() {});
}
Future<void> _initWebDAV() async {
setState(() => _isLoading = true);
safeSetState(() => _isLoading = true);
try {
await WebDAVService.instance.loadCredentials();
_favorites = [];
} catch (e) {
_favorites = [];
} finally {
if (mounted) setState(() => _isLoading = false);
if (mounted) safeSetState(() => _isLoading = false);
}
}
@@ -306,12 +306,13 @@ class _HomePageState extends BaseState<HomePage> {
onPressed: () async {
Navigator.pop(context);
await WebDAVService.instance.clearCredentials();
setState(() {
safeSetState(() {
_favorites = [];
_isLoading = false;
});
if (mounted) {
Navigator.pushReplacement(
// ⭐ 修复:用 push 保留 HomePage 在栈底
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => const WebDAVSetupPage(),
@@ -333,7 +334,7 @@ class _HomePageState extends BaseState<HomePage> {
if (_scrollController.hasClients) {
_scrollController.jumpTo(0.0);
}
setState(() {});
safeSetState(() {});
}
@override
@@ -406,7 +407,7 @@ class _HomePageState extends BaseState<HomePage> {
),
);
_resetSnapState();
setState(() {});
safeSetState(() {});
} else {
final result = await Navigator.push(
context,
@@ -414,17 +415,18 @@ class _HomePageState extends BaseState<HomePage> {
builder: (_) => const WebDAVSetupPage(),
),
);
setState(() {});
safeSetState(() {});
if (result == true) {
await WebDAVService.instance
.loadCredentials();
setState(() {});
safeSetState(() {});
}
}
},
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 左侧云朵图标(固定 56px
const Padding(
padding: EdgeInsets.only(left: 8.0),
child: Icon(
@@ -434,11 +436,14 @@ class _HomePageState extends BaseState<HomePage> {
),
),
const SizedBox(width: 16),
// 右侧所有内容
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
// 第一行:WebDAV + 状态 + 退出按钮
Row(
children: [
const Text(
@@ -460,28 +465,24 @@ class _HomePageState extends BaseState<HomePage> {
fontWeight: FontWeight.w400,
),
),
// ⭐ 退出按钮(已连接时显示)
if (isConnected) ...[
const Spacer(),
IconButton(
icon: const Icon(
Icons.logout,
color: Colors.grey,
size: 18,
),
tooltip: '重新登录',
onPressed: _showReauthDialog,
padding: EdgeInsets.zero,
constraints: const BoxConstraints(
minWidth: 32,
minHeight: 32,
const Spacer(),
if (isConnected)
Padding(
padding:
const EdgeInsets.only(top: 2),
child: GestureDetector(
onTap: _showReauthDialog,
child: const Icon(
Icons.logout,
color: Colors.grey,
size: 18,
),
),
),
const SizedBox(width: 4),
],
],
),
const SizedBox(height: 4),
// 第二行:用户名
Text(
isConnected ? username : '点击连接',
style: TextStyle(
@@ -706,7 +707,7 @@ class _HomePageState extends BaseState<HomePage> {
size: 20,
),
onPressed: () {
setState(() {
safeSetState(() {
_favorites.removeAt(index);
});
},
+7 -6
View File
@@ -35,7 +35,7 @@ class _WebDAVSetupPageState extends BaseState<WebDAVSetupPage> {
Future<void> _loadSavedCredentials() async {
final hasCred = await WebDAVService.instance.loadCredentials();
setState(() {
safeSetState(() {
_isConnected = hasCred;
_statusText = hasCred ? '已连接' : '未连接';
if (hasCred) {
@@ -47,7 +47,7 @@ class _WebDAVSetupPageState extends BaseState<WebDAVSetupPage> {
Future<void> _connect() async {
if (!_formKey.currentState!.validate()) return;
setState(() => _isLoading = true);
safeSetState(() => _isLoading = true);
try {
await WebDAVService.instance.saveCredentials(
@@ -59,7 +59,7 @@ class _WebDAVSetupPageState extends BaseState<WebDAVSetupPage> {
// 验证连接
await WebDAVService.instance.getMusicFiles();
setState(() {
safeSetState(() {
_isConnected = true;
_statusText = '已连接';
_isLoading = false;
@@ -72,7 +72,8 @@ class _WebDAVSetupPageState extends BaseState<WebDAVSetupPage> {
backgroundColor: Color(0xFF4CAF50),
),
);
// ✅ 登录成功 → 直接跳转到文件列表页
// ⭐ 用 pushReplacement 替换当前页面(WebDAVSetupPage
// 此时栈底是 HomePage,替换后栈变为 [HomePage, WebDAVFileListPage]
Navigator.pushReplacement(
context,
MaterialPageRoute(
@@ -81,7 +82,7 @@ class _WebDAVSetupPageState extends BaseState<WebDAVSetupPage> {
);
}
} catch (e) {
setState(() {
safeSetState(() {
_isConnected = false;
_statusText = '连接失败';
_isLoading = false;
@@ -99,7 +100,7 @@ class _WebDAVSetupPageState extends BaseState<WebDAVSetupPage> {
Future<void> _disconnect() async {
await WebDAVService.instance.clearCredentials();
setState(() {
safeSetState(() {
_isConnected = false;
_statusText = '未连接';
});