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>
This commit is contained in:
2026-04-02 06:26:57 +10:00
commit 8f13c725a4
114 changed files with 4336 additions and 0 deletions

31
lib/app/app.dart Normal file
View File

@@ -0,0 +1,31 @@
// Version: 1.0.0 | Created: 2026-04-01
// Root MaterialApp widget. Wires together theme + router.
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'router.dart';
import 'theme.dart';
/// Root application widget.
///
/// [ProviderScope] is set up in main.dart. This widget only handles
/// theme and routing — no business logic here.
class M8ChatApp extends ConsumerWidget {
const M8ChatApp({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final router = ref.watch(routerProvider);
return MaterialApp.router(
title: 'M8Chat',
theme: buildLightTheme(),
darkTheme: buildDarkTheme(),
// Default to dark — M8Chat is a dark-first chat app.
themeMode: ThemeMode.system,
routerConfig: router,
debugShowCheckedModeBanner: false,
);
}
}

115
lib/app/router.dart Normal file
View File

@@ -0,0 +1,115 @@
// Version: 1.0.2 | Created: 2026-04-01
// All route definitions in one place.
// GoRouter is created ONCE (keepAlive) and re-evaluates redirects via
// refreshListenable — avoids the GoRouter recreation bug from ref.watch.
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../core/auth/auth_notifier.dart';
import '../core/auth/auth_state.dart';
import '../features/auth/presentation/login_screen.dart';
import '../features/calls/presentation/call_screen.dart';
import '../features/chat/presentation/chat_screen.dart';
import '../features/profile/presentation/profile_screen.dart';
import '../features/rooms/presentation/rooms_screen.dart';
import '../features/spaces/presentation/spaces_screen.dart';
part 'router.g.dart';
/// Route path constants — use these instead of raw strings.
abstract final class AppRoutes {
static const String root = '/';
static const String login = '/login';
static const String rooms = '/rooms';
static const String chat = '/rooms/:roomId';
static const String call = '/calls/:roomId';
static const String profile = '/profile';
static const String spaces = '/spaces';
}
/// ChangeNotifier that GoRouter listens to for redirect re-evaluation.
/// Notified by ref.listen whenever authProvider changes.
class _AuthRefreshNotifier extends ChangeNotifier {
void notify() => notifyListeners();
}
@Riverpod(keepAlive: true)
GoRouter router(Ref ref) {
// Create once — notifier triggers re-redirect without recreating the router.
final notifier = _AuthRefreshNotifier();
ref.listen<AuthState>(authProvider, (_, __) => notifier.notify());
ref.onDispose(notifier.dispose);
return GoRouter(
initialLocation: AppRoutes.root,
refreshListenable: notifier,
debugLogDiagnostics: false,
redirect: (BuildContext context, GoRouterState state) {
// Read (not watch) so redirect does not itself trigger provider changes.
final authState = ref.read(authProvider);
final isLoggedIn = authState is AuthAuthenticated;
final isOnLogin = state.matchedLocation == AppRoutes.login;
// While restoring session, stay on splash.
if (authState is AuthInitial || authState is AuthLoading) return null;
// Unauthenticated users must go to login.
if (!isLoggedIn && !isOnLogin) return AppRoutes.login;
// Authenticated users should not see the login screen.
if (isLoggedIn && isOnLogin) return AppRoutes.rooms;
return null;
},
routes: [
GoRoute(
path: AppRoutes.root,
builder: (context, state) => const _SplashRedirectPage(),
),
GoRoute(
path: AppRoutes.login,
builder: (context, state) => const LoginScreen(),
),
GoRoute(
path: AppRoutes.rooms,
builder: (context, state) => const RoomsScreen(),
),
GoRoute(
path: AppRoutes.chat,
builder: (context, state) {
// safe: path param is guaranteed by route definition
final roomId = state.pathParameters['roomId']!;
return ChatScreen(roomId: roomId);
},
),
GoRoute(
path: AppRoutes.call,
builder: (context, state) {
// safe: path param is guaranteed by route definition
final roomId = state.pathParameters['roomId']!;
return CallScreen(roomId: roomId);
},
),
GoRoute(
path: AppRoutes.profile,
builder: (context, state) => const ProfileScreen(),
),
GoRoute(
path: AppRoutes.spaces,
builder: (context, state) => const SpacesScreen(),
),
],
);
}
/// Invisible page shown at `/` while GoRouter's redirect evaluates auth state.
class _SplashRedirectPage extends StatelessWidget {
const _SplashRedirectPage();
@override
Widget build(BuildContext context) {
return const Scaffold(body: Center(child: CircularProgressIndicator()));
}
}

137
lib/app/theme.dart Normal file
View File

@@ -0,0 +1,137 @@
// Version: 1.0.0 | Created: 2026-04-01
// M8Chat brand theme — dark and light variants.
// Primary brand colour: #5C35C9 (deep purple). Accent: #7B5CF6.
import 'package:flutter/material.dart';
/// M8Chat brand colours.
abstract final class M8Colours {
static const Color brandPurple = Color(0xFF5C35C9);
static const Color accentPurple = Color(0xFF7B5CF6);
static const Color darkBackground = Color(0xFF0F0F1A);
static const Color darkSurface = Color(0xFF1A1A2E);
static const Color darkSurfaceVariant = Color(0xFF22223A);
static const Color onDarkSurface = Color(0xFFE8E8F0);
static const Color subtleText = Color(0xFF9898B0);
static const Color errorRed = Color(0xFFCF6679);
static const Color unreadGreen = Color(0xFF4CAF50);
}
/// Dark theme — default for M8Chat.
ThemeData buildDarkTheme() {
const seed = M8Colours.brandPurple;
final scheme =
ColorScheme.fromSeed(
seedColor: seed,
brightness: Brightness.dark,
).copyWith(
surface: M8Colours.darkBackground,
surfaceContainerHighest: M8Colours.darkSurface,
primary: M8Colours.accentPurple,
onSurface: M8Colours.onDarkSurface,
error: M8Colours.errorRed,
);
return ThemeData(
useMaterial3: true,
colorScheme: scheme,
scaffoldBackgroundColor: M8Colours.darkBackground,
appBarTheme: AppBarTheme(
backgroundColor: M8Colours.darkSurface,
foregroundColor: M8Colours.onDarkSurface,
elevation: 0,
surfaceTintColor: Colors.transparent,
),
navigationBarTheme: NavigationBarThemeData(
backgroundColor: M8Colours.darkSurface,
indicatorColor: M8Colours.accentPurple.withAlpha(51),
labelTextStyle: WidgetStateProperty.all(
const TextStyle(fontSize: 12, color: M8Colours.onDarkSurface),
),
),
inputDecorationTheme: InputDecorationTheme(
filled: true,
fillColor: M8Colours.darkSurfaceVariant,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide.none,
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(color: M8Colours.accentPurple, width: 2),
),
labelStyle: const TextStyle(color: M8Colours.subtleText),
hintStyle: const TextStyle(color: M8Colours.subtleText),
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
backgroundColor: M8Colours.accentPurple,
foregroundColor: Colors.white,
minimumSize: const Size.fromHeight(52),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
textStyle: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
letterSpacing: 0.5,
),
),
),
cardTheme: CardThemeData(
color: M8Colours.darkSurface,
elevation: 0,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
dividerTheme: const DividerThemeData(
color: M8Colours.darkSurfaceVariant,
thickness: 1,
),
snackBarTheme: SnackBarThemeData(
backgroundColor: M8Colours.darkSurfaceVariant,
contentTextStyle: const TextStyle(color: M8Colours.onDarkSurface),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
behavior: SnackBarBehavior.floating,
),
);
}
/// Light theme — follows system preference if user selects it.
ThemeData buildLightTheme() {
const seed = M8Colours.brandPurple;
final scheme = ColorScheme.fromSeed(
seedColor: seed,
brightness: Brightness.light,
);
return ThemeData(
useMaterial3: true,
colorScheme: scheme,
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
minimumSize: const Size.fromHeight(52),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
textStyle: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
letterSpacing: 0.5,
),
),
),
inputDecorationTheme: InputDecorationTheme(
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide.none,
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: scheme.primary, width: 2),
),
),
snackBarTheme: SnackBarThemeData(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
behavior: SnackBarBehavior.floating,
),
);
}