📱 Dashboard supports mobile

This commit is contained in:
2025-12-20 22:19:36 +08:00
parent 53137aed3f
commit 18c81503f1

View File

@@ -9,6 +9,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:island/pods/chat/chat_room.dart'; import 'package:island/pods/chat/chat_room.dart';
import 'package:island/pods/event_calendar.dart'; import 'package:island/pods/event_calendar.dart';
import 'package:island/screens/chat/chat.dart'; import 'package:island/screens/chat/chat.dart';
import 'package:island/services/responsive.dart';
import 'package:island/widgets/account/fortune_graph.dart'; import 'package:island/widgets/account/fortune_graph.dart';
import 'package:island/widgets/account/friends_overview.dart'; import 'package:island/widgets/account/friends_overview.dart';
import 'package:island/widgets/app_scaffold.dart'; import 'package:island/widgets/app_scaffold.dart';
@@ -36,10 +37,15 @@ class DashboardGrid extends HookConsumerWidget {
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final isWide = isWideScreen(context);
return Container( return Container(
constraints: BoxConstraints( constraints: BoxConstraints(
maxHeight: math.min(640, MediaQuery.sizeOf(context).height * 0.65), maxHeight: isWide
? math.min(640, MediaQuery.sizeOf(context).height * 0.65)
: MediaQuery.sizeOf(context).height,
), ),
padding: isWide ? null : EdgeInsets.only(top: 24),
child: Column( child: Column(
spacing: 16, spacing: 16,
children: [ children: [
@@ -56,12 +62,26 @@ class DashboardGrid extends HookConsumerWidget {
), ),
), ),
Expanded( Expanded(
child: Align(
alignment: Alignment.centerLeft,
child: SingleChildScrollView( child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 24), padding: isWide
scrollDirection: Axis.horizontal, ? const EdgeInsets.symmetric(horizontal: 24)
child: Row( : const EdgeInsets.only(bottom: 64),
scrollDirection: isWide ? Axis.horizontal : Axis.vertical,
child: isWide ? _DashboardGridWide() : _DashboardGridNarrow(),
).clipRRect(topLeft: 12, topRight: 12).padding(horizontal: 24),
),
],
),
);
}
}
class _DashboardGridWide extends HookConsumerWidget {
const _DashboardGridWide();
@override
Widget build(BuildContext context, WidgetRef ref) {
return Row(
spacing: 16, spacing: 16,
children: [ children: [
SizedBox( SizedBox(
@@ -69,10 +89,7 @@ class DashboardGrid extends HookConsumerWidget {
child: Column( child: Column(
spacing: 16, spacing: 16,
children: [ children: [
CheckInWidget( CheckInWidget(margin: EdgeInsets.zero, checkInOnly: true),
margin: EdgeInsets.zero,
checkInOnly: true,
),
Card( Card(
margin: EdgeInsets.zero, margin: EdgeInsets.zero,
child: FortuneGraphWidget( child: FortuneGraphWidget(
@@ -110,12 +127,39 @@ class DashboardGrid extends HookConsumerWidget {
), ),
), ),
], ],
);
}
}
class _DashboardGridNarrow extends HookConsumerWidget {
const _DashboardGridNarrow();
@override
Widget build(BuildContext context, WidgetRef ref) {
return Column(
spacing: 16,
children: [
CheckInWidget(margin: EdgeInsets.zero, checkInOnly: true),
FortuneCard(),
SizedBox(height: 400, child: FeaturedPostCard()),
FriendsOverviewWidget(),
NotificationsCard(),
ChatListCard(),
Card(
margin: EdgeInsets.zero,
child: FortuneGraphWidget(
events: ref.watch(
eventCalendarProvider(
EventCalendarQuery(
uname: 'me',
year: DateTime.now().year,
month: DateTime.now().month,
),
), ),
), ),
), ),
), ),
], ],
),
); );
} }
} }
@@ -344,8 +388,7 @@ class NotificationsCard extends HookConsumerWidget {
), ),
], ],
).padding(horizontal: 16, vertical: 12), ).padding(horizontal: 16, vertical: 12),
Expanded( notifications.when(
child: notifications.when(
loading: () => const SkeletonNotificationTile(), loading: () => const SkeletonNotificationTile(),
error: (error, stack) => Center(child: Text('Error: $error')), error: (error, stack) => Center(child: Text('Error: $error')),
data: (notificationList) { data: (notificationList) {
@@ -375,7 +418,6 @@ class NotificationsCard extends HookConsumerWidget {
); );
}, },
), ),
),
Text( Text(
'Tap to view all notifications', 'Tap to view all notifications',
style: Theme.of(context).textTheme.bodySmall?.copyWith( style: Theme.of(context).textTheme.bodySmall?.copyWith(
@@ -424,8 +466,7 @@ class ChatListCard extends HookConsumerWidget {
), ),
], ],
).padding(horizontal: 16, vertical: 16), ).padding(horizontal: 16, vertical: 16),
Expanded( chatRooms.when(
child: chatRooms.when(
loading: () => const Center(child: CircularProgressIndicator()), loading: () => const Center(child: CircularProgressIndicator()),
error: (error, stack) => Center(child: Text('Error: $error')), error: (error, stack) => Center(child: Text('Error: $error')),
data: (rooms) { data: (rooms) {
@@ -435,6 +476,7 @@ class ChatListCard extends HookConsumerWidget {
// Take only the first 5 rooms // Take only the first 5 rooms
final recentRooms = rooms.take(5).toList(); final recentRooms = rooms.take(5).toList();
return ListView.builder( return ListView.builder(
shrinkWrap: true,
itemCount: recentRooms.length, itemCount: recentRooms.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final room = recentRooms[index]; final room = recentRooms[index];
@@ -452,7 +494,6 @@ class ChatListCard extends HookConsumerWidget {
); );
}, },
), ),
),
], ],
), ),
); );
@@ -514,6 +555,6 @@ class FortuneCard extends HookWidget {
Text(fortune['author']!).bold(), Text(fortune['author']!).bold(),
], ],
).padding(horizontal: 24), ).padding(horizontal: 24),
); ).height(48);
} }
} }