import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:go_router/go_router.dart'; import '../../core/auth/auth_bloc.dart'; import '../../core/pairing/pairing_bloc.dart'; class HomeScreen extends StatelessWidget { const HomeScreen({super.key}); @override Widget build(BuildContext context) { return BlocListener( listener: (context, state) { if (state is PairingSearching) { context.go('/chat/searching'); } else if (state is PairingNoBestie) { context.go('/chat/no-bestie'); } else if (state is PairingError) { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text(state.message)), ); } }, child: BlocBuilder( builder: (context, state) { final displayName = state is AuthAuthenticated ? state.profile['display_name'] as String : state is AuthAnonymous ? state.displayName : ''; return Scaffold( appBar: AppBar( title: const Text('Halo Bestie'), actions: [ IconButton( icon: const Icon(Icons.logout), onPressed: () => context.read().add(LogoutRequested()), ), ], ), body: Center( child: Padding( padding: const EdgeInsets.all(32), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text('Halo, $displayName!', style: const TextStyle(fontSize: 24)), const SizedBox(height: 48), ElevatedButton( style: ElevatedButton.styleFrom( padding: const EdgeInsets.symmetric(horizontal: 48, vertical: 16), ), onPressed: () => context.read().add(RequestPairing()), child: const Text('Mulai Curhat', style: TextStyle(fontSize: 18)), ), ], ), ), ), ); }, ), ); } }