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'; class LoginScreen extends StatefulWidget { const LoginScreen({super.key}); @override State createState() => _LoginScreenState(); } class _LoginScreenState extends State { final _phoneController = TextEditingController(); @override void dispose() { _phoneController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return BlocListener( listener: (context, state) { if (state is AuthOtpSent) { context.push('/otp', extra: _phoneController.text.trim()); } if (state is AuthError) { ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(state.message))); } }, child: Scaffold( body: SafeArea( child: Padding( padding: const EdgeInsets.all(24), child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ const Text( 'Halo Bestie Mitra', style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold), textAlign: TextAlign.center, ), const SizedBox(height: 48), TextField( controller: _phoneController, decoration: const InputDecoration( labelText: 'Nomor HP', hintText: '+628xxxxxxxxxx', border: OutlineInputBorder(), ), keyboardType: TextInputType.phone, ), const SizedBox(height: 16), BlocBuilder( builder: (context, state) => ElevatedButton( onPressed: state is AuthLoading ? null : () { final phone = _phoneController.text.trim(); if (phone.isEmpty) return; context.read().add(PhoneOtpRequested(phone)); }, child: state is AuthLoading ? const CircularProgressIndicator() : const Text('Kirim OTP'), ), ), ], ), ), ), ), ); } }