// Version: 1.0.1 | Created: 2026-04-01 // Profile screen. Shows current user info and logout button. import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../../core/auth/auth_notifier.dart'; import '../../../core/auth/auth_state.dart'; import '../../../core/network/matrix_client.dart'; class ProfileScreen extends ConsumerWidget { const ProfileScreen({super.key, this.embedded = false}); /// When true, this screen is shown inside the bottom-nav tab of RoomsScreen. final bool embedded; @override Widget build(BuildContext context, WidgetRef ref) { final authState = ref.watch(authProvider); final client = ref.watch(matrixClientProvider); final userId = authState.maybeWhen( authenticated: (userId, _, __) => userId, orElse: () => '', ); final displayName = client.userID != null ? (client.userID!.split(':').first.replaceFirst('@', '')) : 'Unknown'; final body = ListView( padding: const EdgeInsets.all(24), children: [ _ProfileAvatar(displayName: displayName), const SizedBox(height: 16), Center( child: Text( '@$displayName', style: Theme.of( context, ).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.bold), ), ), Center( child: Text( userId, style: Theme.of(context).textTheme.bodySmall?.copyWith( color: Theme.of(context).colorScheme.onSurface.withAlpha(153), ), ), ), const SizedBox(height: 32), const Divider(), const SizedBox(height: 16), Text( 'Settings', style: Theme.of(context).textTheme.labelLarge?.copyWith( color: Theme.of(context).colorScheme.onSurface.withAlpha(153), ), ), const SizedBox(height: 8), ExpansionTile( leading: const Icon(Icons.notifications_outlined), title: const Text('Notifications'), children: [ SwitchListTile( title: const Text('Push notifications'), subtitle: const Text('Coming in Phase 2'), value: false, onChanged: null, ), SwitchListTile( title: const Text('Notification sounds'), subtitle: const Text('Coming in Phase 2'), value: false, onChanged: null, ), ], ), ExpansionTile( leading: const Icon(Icons.security_outlined), title: const Text('Security & Privacy'), children: [ ListTile( leading: const Icon(Icons.lock_outline), title: const Text('End-to-end encryption'), subtitle: const Text('Active — messages are encrypted'), enabled: false, ), ListTile( leading: const Icon(Icons.verified_user_outlined), title: const Text('Verify devices'), subtitle: const Text('Cross-signing setup — coming in Phase 2'), enabled: false, ), ListTile( leading: const Icon(Icons.password_outlined), title: const Text('Change password'), subtitle: const Text('Managed via m8chat.au account settings'), enabled: false, ), ], ), const SizedBox(height: 16), const Divider(), const SizedBox(height: 16), _LogoutButton( onLogout: () async { await ref.read(authProvider.notifier).logout(); }, ), const SizedBox(height: 16), Center( child: Text( 'M8Chat 1.0.0 · matrix.m8chat.au', style: Theme.of(context).textTheme.bodySmall?.copyWith( color: Theme.of(context).colorScheme.onSurface.withAlpha(77), ), ), ), ], ); if (embedded) return body; return Scaffold( appBar: AppBar(title: const Text('Profile')), body: body, ); } } class _ProfileAvatar extends StatelessWidget { const _ProfileAvatar({required this.displayName}); final String displayName; @override Widget build(BuildContext context) { final initials = displayName.isNotEmpty ? displayName[0].toUpperCase() : '?'; return Center( child: CircleAvatar( radius: 48, backgroundColor: Theme.of(context).colorScheme.primary.withAlpha(51), child: Text( initials, style: TextStyle( fontSize: 36, fontWeight: FontWeight.bold, color: Theme.of(context).colorScheme.primary, ), ), ), ); } } class _LogoutButton extends StatelessWidget { const _LogoutButton({required this.onLogout}); final VoidCallback onLogout; @override Widget build(BuildContext context) { return OutlinedButton.icon( onPressed: () { showDialog( context: context, builder: (_) => AlertDialog( title: const Text('Sign out'), content: const Text('Are you sure you want to sign out of M8Chat?'), actions: [ TextButton( onPressed: () => Navigator.of(context).pop(), child: const Text('Cancel'), ), TextButton( onPressed: () { Navigator.of(context).pop(); onLogout(); }, child: Text( 'Sign out', style: TextStyle(color: Theme.of(context).colorScheme.error), ), ), ], ), ); }, icon: const Icon(Icons.logout), label: const Text('Sign out'), style: OutlinedButton.styleFrom( foregroundColor: Theme.of(context).colorScheme.error, side: BorderSide(color: Theme.of(context).colorScheme.error), minimumSize: const Size.fromHeight(48), ), ); } }