From a20c2598fcb773c3f5959b85c79c5b4edbab75e2 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 3 Jul 2025 00:49:11 +0800 Subject: [PATCH] :bug: Fixes render errors of unauthorized --- assets/i18n/zh-CN.json | 2 +- lib/main.dart | 2 +- lib/pods/userinfo.dart | 9 +- lib/screens/account.dart | 25 ++++-- lib/screens/account/event_calendar.dart | 4 +- lib/screens/account/profile.dart | 104 +++++++++++++---------- lib/screens/explore.dart | 2 +- lib/widgets/account/status_creation.dart | 2 +- lib/widgets/app_scaffold.dart | 4 +- lib/widgets/post/post_item.dart | 2 +- 10 files changed, 91 insertions(+), 65 deletions(-) diff --git a/assets/i18n/zh-CN.json b/assets/i18n/zh-CN.json index 553cb6c..49357d3 100644 --- a/assets/i18n/zh-CN.json +++ b/assets/i18n/zh-CN.json @@ -532,7 +532,7 @@ "aboutScreenContactUsTitle": "联系我们", "aboutScreenLicenseTitle": "许可证", "aboutScreenLicenseContent": "GNU Affero General Public License v3.0", - "aboutScreenCopyright": "版权所有 © Solsynth {}", + "aboutScreenCopyright": "版权所有 © 索尔辛茨 {}", "aboutScreenMadeWith": "由 Solar Network Team 用 ❤︎️ 制作", "aboutScreenFailedToLoadPackageInfo": "加载包信息失败:{error}", "copiedToClipboard": "已复制到剪贴板", diff --git a/lib/main.dart b/lib/main.dart index 0caad72..85714e9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -221,7 +221,7 @@ class IslandApp extends HookConsumerWidget { Future(() { userNotifier.fetchUser().then((_) { final user = ref.watch(userInfoProvider); - if (user.hasValue) { + if (user.value != null) { final apiClient = ref.read(apiClientProvider); subscribePushNotification(apiClient); final wsNotifier = ref.read(websocketStateProvider.notifier); diff --git a/lib/pods/userinfo.dart b/lib/pods/userinfo.dart index 2296ebd..41530d5 100644 --- a/lib/pods/userinfo.dart +++ b/lib/pods/userinfo.dart @@ -18,8 +18,13 @@ class UserInfoNotifier extends StateNotifier> { final user = SnAccount.fromJson(response.data); state = AsyncValue.data(user); } catch (error, stackTrace) { - log("[UserInfo] Failed to fetch user info: $error"); - state = AsyncValue.error(error, stackTrace); + log( + "[UserInfo] Failed to fetch user info...", + name: 'UserInfoNotifier', + error: error, + stackTrace: stackTrace, + ); + state = AsyncValue.data(null); } } diff --git a/lib/screens/account.dart b/lib/screens/account.dart index 5d08c10..87de77c 100644 --- a/lib/screens/account.dart +++ b/lib/screens/account.dart @@ -59,7 +59,7 @@ class AccountScreen extends HookConsumerWidget { notificationUnreadCountNotifierProvider, ); - if (!user.hasValue || user.value == null) { + if (user.value == null || user.value == null) { return _UnauthorizedAccountScreen(); } @@ -367,12 +367,23 @@ class _UnauthorizedAccountScreen extends StatelessWidget { ), ), const Gap(8), - TextButton( - onPressed: () { - context.push('/settings'); - }, - child: Text('appSettings').tr(), - ).center(), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + TextButton( + onPressed: () { + context.push('/about'); + }, + child: Text('about').tr(), + ), + TextButton( + onPressed: () { + context.push('/settings'); + }, + child: Text('appSettings').tr(), + ), + ], + ), ], ), ).center(), diff --git a/lib/screens/account/event_calendar.dart b/lib/screens/account/event_calendar.dart index 0a91747..6cf8bae 100644 --- a/lib/screens/account/event_calendar.dart +++ b/lib/screens/account/event_calendar.dart @@ -82,7 +82,7 @@ class EventCalanderScreen extends HookConsumerWidget { ), // Show user profile if viewing someone else's calendar - if (name != 'me' && user.hasValue) + if (name != 'me' && user.value != null) AccountNameplate(name: name), ], ), @@ -106,7 +106,7 @@ class EventCalanderScreen extends HookConsumerWidget { ).padding(horizontal: 8, vertical: 4), // Show user profile if viewing someone else's calendar - if (name != 'me' && user.hasValue) + if (name != 'me' && user.value != null) AccountNameplate(name: name), Gap(MediaQuery.of(context).padding.bottom + 16), ], diff --git a/lib/screens/account/profile.dart b/lib/screens/account/profile.dart index 956ec7d..51c8e1d 100644 --- a/lib/screens/account/profile.dart +++ b/lib/screens/account/profile.dart @@ -72,6 +72,8 @@ Future accountAppbarForcegroundColor(Ref ref, String uname) async { @riverpod Future accountDirectChat(Ref ref, String uname) async { + final userInfo = ref.watch(userInfoProvider); + if (userInfo.value == null) return null; final account = await ref.watch(accountProvider(uname).future); final apiClient = ref.watch(apiClientProvider); try { @@ -87,6 +89,8 @@ Future accountDirectChat(Ref ref, String uname) async { @riverpod Future accountRelationship(Ref ref, String uname) async { + final userInfo = ref.watch(userInfoProvider); + if (userInfo.value == null) return null; final account = await ref.watch(accountProvider(uname).future); final apiClient = ref.watch(apiClientProvider); try { @@ -219,6 +223,8 @@ class AccountProfileScreen extends HookConsumerWidget { ]; } + final user = ref.watch(userInfoProvider); + return account.when( data: (data) => AppScaffold( @@ -379,56 +385,60 @@ class AccountProfileScreen extends HookConsumerWidget { ).padding(horizontal: 24), ), - SliverToBoxAdapter( - child: const Divider(height: 1).padding(top: 24, bottom: 12), - ), - SliverToBoxAdapter( - child: Row( - spacing: 8, - children: [ - Expanded( - child: FilledButton.icon( - style: ButtonStyle( - backgroundColor: WidgetStatePropertyAll( - accountRelationship.value == null - ? null - : Theme.of(context).colorScheme.secondary, - ), - foregroundColor: WidgetStatePropertyAll( - accountRelationship.value == null - ? null - : Theme.of(context).colorScheme.onSecondary, - ), - ), - onPressed: relationshipAction, - label: - Text( + if (user.value != null) + SliverToBoxAdapter( + child: const Divider( + height: 1, + ).padding(top: 24, bottom: 12), + ), + if (user.value != null) + SliverToBoxAdapter( + child: Row( + spacing: 8, + children: [ + Expanded( + child: FilledButton.icon( + style: ButtonStyle( + backgroundColor: WidgetStatePropertyAll( accountRelationship.value == null - ? 'addFriendShort' - : 'added', - ).tr(), - icon: - accountRelationship.value == null - ? const Icon(Symbols.person_add) - : const Icon(Symbols.person_check), + ? null + : Theme.of(context).colorScheme.secondary, + ), + foregroundColor: WidgetStatePropertyAll( + accountRelationship.value == null + ? null + : Theme.of(context).colorScheme.onSecondary, + ), + ), + onPressed: relationshipAction, + label: + Text( + accountRelationship.value == null + ? 'addFriendShort' + : 'added', + ).tr(), + icon: + accountRelationship.value == null + ? const Icon(Symbols.person_add) + : const Icon(Symbols.person_check), + ), ), - ), - Expanded( - child: FilledButton.icon( - onPressed: directMessageAction, - icon: const Icon(Symbols.message), - label: - Text( - accountChat.value == null - ? 'createDirectMessage' - : 'gotoDirectMessage', - maxLines: 1, - ).tr(), + Expanded( + child: FilledButton.icon( + onPressed: directMessageAction, + icon: const Icon(Symbols.message), + label: + Text( + accountChat.value == null + ? 'createDirectMessage' + : 'gotoDirectMessage', + maxLines: 1, + ).tr(), + ), ), - ), - ], - ).padding(horizontal: 16), - ), + ], + ).padding(horizontal: 16), + ), SliverToBoxAdapter( child: const Divider(height: 1).padding(top: 12), ), diff --git a/lib/screens/explore.dart b/lib/screens/explore.dart index 91e3d71..dfefc88 100644 --- a/lib/screens/explore.dart +++ b/lib/screens/explore.dart @@ -307,7 +307,7 @@ class _ActivityListView extends HookConsumerWidget { return CustomScrollView( slivers: [ - if (user.hasValue && !contentOnly) + if (user.value != null && !contentOnly) SliverToBoxAdapter(child: CheckInWidget()), SliverList.builder( itemCount: widgetCount, diff --git a/lib/widgets/account/status_creation.dart b/lib/widgets/account/status_creation.dart index 58f0502..06d5e5a 100644 --- a/lib/widgets/account/status_creation.dart +++ b/lib/widgets/account/status_creation.dart @@ -59,7 +59,7 @@ class AccountStatusCreationSheet extends HookConsumerWidget { }, options: Options(method: initialStatus == null ? 'POST' : 'PATCH'), ); - if (user.hasValue) { + if (user.value != null) { ref.invalidate(accountStatusProvider(user.value!.name)); } if (!context.mounted) return; diff --git a/lib/widgets/app_scaffold.dart b/lib/widgets/app_scaffold.dart index 29973c3..577bfdc 100644 --- a/lib/widgets/app_scaffold.dart +++ b/lib/widgets/app_scaffold.dart @@ -350,7 +350,7 @@ class _WebSocketIndicator extends HookConsumerWidget { return AnimatedPositioned( duration: Duration(milliseconds: 1850), top: - !user.hasValue || + user.value == null || user.value == null || websocketState == WebSocketState.connected() ? -indicatorHeight @@ -362,7 +362,7 @@ class _WebSocketIndicator extends HookConsumerWidget { child: IgnorePointer( child: Material( elevation: - !user.hasValue || websocketState == WebSocketState.connected() + user.value == null || websocketState == WebSocketState.connected() ? 0 : 4, child: AnimatedContainer( diff --git a/lib/widgets/post/post_item.dart b/lib/widgets/post/post_item.dart index 7faf6c1..8ef7e6e 100644 --- a/lib/widgets/post/post_item.dart +++ b/lib/widgets/post/post_item.dart @@ -56,7 +56,7 @@ class PostItem extends HookConsumerWidget { final user = ref.watch(userInfoProvider); final isAuthor = useMemoized( - () => user.hasValue && user.value?.id == item.publisher.accountId, + () => user.value != null && user.value?.id == item.publisher.accountId, [user], );