Files
m8chat-app2/lib/features/rooms/presentation/rooms_screen.dart
help4bis 8f13c725a4 feat: Phase 1 complete — Matrix login, rooms, chat, profile
- Direct m.login.password auth against matrix.m8chat.au
- Room list with unread badges, last message, timestamps
- Chat timeline (text, images, files, replies, reactions)
- Profile screen with expandable Notifications and Security sections
- Olm E2EE initialisation (web WASM bootstrap)
- Global error handler preventing Matrix SDK crashes
- GoRouter with refreshListenable (no recreation on auth change)
- Feature-first clean architecture: Riverpod + GoRouter + Drift
- Deployed to https://app2.m8chat.au

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-02 06:26:57 +10:00

179 lines
5.1 KiB
Dart

// Version: 1.0.0 | Created: 2026-04-01
// Main rooms list screen with bottom navigation.
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import '../../profile/presentation/profile_screen.dart';
import '../../spaces/presentation/spaces_screen.dart';
import 'room_tile.dart';
import 'rooms_controller.dart';
class RoomsScreen extends ConsumerStatefulWidget {
const RoomsScreen({super.key});
@override
ConsumerState<RoomsScreen> createState() => _RoomsScreenState();
}
class _RoomsScreenState extends ConsumerState<RoomsScreen> {
int _selectedIndex = 0;
static const _destinations = [
NavigationDestination(
icon: Icon(Icons.chat_bubble_outline),
selectedIcon: Icon(Icons.chat_bubble),
label: 'Rooms',
),
NavigationDestination(
icon: Icon(Icons.dashboard_outlined),
selectedIcon: Icon(Icons.dashboard),
label: 'Spaces',
),
NavigationDestination(
icon: Icon(Icons.person_outline),
selectedIcon: Icon(Icons.person),
label: 'Profile',
),
];
Widget _buildBody() {
return switch (_selectedIndex) {
0 => const _RoomListBody(),
1 => const SpacesScreen(embedded: true),
2 => const ProfileScreen(embedded: true),
_ => const _RoomListBody(),
};
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: _selectedIndex == 0
? AppBar(
title: const Text('M8Chat'),
actions: [
IconButton(
icon: const Icon(Icons.search),
tooltip: 'Search rooms',
onPressed: () {
// Phase 2: room search
},
),
IconButton(
icon: const Icon(Icons.edit_square),
tooltip: 'New message',
onPressed: () {
// Phase 2: start a new DM or group chat
},
),
],
)
: null,
body: _buildBody(),
bottomNavigationBar: NavigationBar(
selectedIndex: _selectedIndex,
onDestinationSelected: (index) =>
setState(() => _selectedIndex = index),
destinations: _destinations,
),
);
}
}
class _RoomListBody extends ConsumerWidget {
const _RoomListBody();
@override
Widget build(BuildContext context, WidgetRef ref) {
final roomsAsync = ref.watch(roomsListProvider);
return roomsAsync.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (error, _) => Center(
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.error_outline, size: 48),
const SizedBox(height: 16),
Text(
'Could not load rooms.',
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 8),
Text(
error.toString(),
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodySmall,
),
const SizedBox(height: 24),
ElevatedButton(
onPressed: () => ref.refresh(roomsListProvider),
child: const Text('Retry'),
),
],
),
),
),
data: (rooms) {
if (rooms.isEmpty) {
return const _EmptyRoomsState();
}
return ListView.separated(
itemCount: rooms.length,
separatorBuilder: (_, __) => const Divider(height: 1, indent: 72),
itemBuilder: (context, index) {
final room = rooms[index];
return RoomTile(
room: room,
onTap: () =>
context.push('/rooms/${Uri.encodeComponent(room.id)}'),
);
},
);
},
);
}
}
class _EmptyRoomsState extends StatelessWidget {
const _EmptyRoomsState();
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Center(
child: Padding(
padding: const EdgeInsets.all(32),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.chat_bubble_outline,
size: 64,
color: theme.colorScheme.onSurface.withAlpha(77),
),
const SizedBox(height: 16),
Text(
'No rooms yet',
style: theme.textTheme.titleMedium?.copyWith(
color: theme.colorScheme.onSurface.withAlpha(153),
),
),
const SizedBox(height: 8),
Text(
'Rooms you join will appear here.',
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurface.withAlpha(102),
),
),
],
),
),
);
}
}