import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:kmobile/features/auth/controllers/auth_cubit.dart'; import 'package:kmobile/features/auth/screens/verification_screen.dart'; import 'package:kmobile/l10n/app_localizations.dart'; class LoginScreen extends StatefulWidget { const LoginScreen({super.key}); @override LoginScreenState createState() => LoginScreenState(); } class LoginScreenState extends State with SingleTickerProviderStateMixin { final _formKey = GlobalKey(); final _customerNumberController = TextEditingController(); final _passwordController = TextEditingController(); bool _obscurePassword = true; @override void initState() { super.initState(); context.read().reset(); } @override void dispose() { _customerNumberController.dispose(); _passwordController.dispose(); super.dispose(); } void _submitForm() { if (_formKey.currentState!.validate()) { Navigator.of(context).push( MaterialPageRoute( builder: (_) => VerificationScreen( customerNo: _customerNumberController.text.trim(), password: _passwordController.text, ), ), ); } } @override Widget build(BuildContext context) { return Scaffold( // appBar: AppBar(title: const Text('Login')), body: Padding( padding: const EdgeInsets.all(24.0), child: Form( key: _formKey, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Image.asset( 'assets/images/logo.png', width: 150, height: 150, errorBuilder: (context, error, stackTrace) { return Icon( Icons.account_balance, size: 100, color: Theme.of(context).primaryColor, ); }, ), const SizedBox(height: 16), // Title Text( AppLocalizations.of(context).kccb, style: TextStyle( fontSize: 32, fontWeight: FontWeight.bold, color: Theme.of(context).primaryColor, ), ), const SizedBox(height: 48), TextFormField( controller: _customerNumberController, decoration: InputDecoration( labelText: AppLocalizations.of(context).customerNumber, // prefixIcon: Icon(Icons.person), border: const OutlineInputBorder(), isDense: true, filled: true, fillColor: Theme.of(context).scaffoldBackgroundColor, enabledBorder: OutlineInputBorder( borderSide: BorderSide( color: Theme.of(context).colorScheme.outline), ), focusedBorder: OutlineInputBorder( borderSide: BorderSide( color: Theme.of(context).colorScheme.primary, width: 2), ), ), keyboardType: TextInputType.number, textInputAction: TextInputAction.next, validator: (value) { if (value == null || value.isEmpty) { return AppLocalizations.of(context).pleaseEnterUsername; } return null; }, ), const SizedBox(height: 24), // Password TextFormField( controller: _passwordController, obscureText: _obscurePassword, textInputAction: TextInputAction.done, onFieldSubmitted: (_) => _submitForm(), decoration: InputDecoration( labelText: AppLocalizations.of(context).password, border: const OutlineInputBorder(), isDense: true, filled: true, fillColor: Theme.of(context).scaffoldBackgroundColor, enabledBorder: OutlineInputBorder( borderSide: BorderSide( color: Theme.of(context).colorScheme.outline), ), focusedBorder: OutlineInputBorder( borderSide: BorderSide( color: Theme.of(context).colorScheme.primary, width: 2), ), suffixIcon: IconButton( icon: Icon( _obscurePassword ? Icons.visibility : Icons.visibility_off, ), onPressed: () { setState(() { _obscurePassword = !_obscurePassword; }); }, ), ), validator: (value) { if (value == null || value.isEmpty) { return AppLocalizations.of(context).pleaseEnterPassword; } return null; }, ), const SizedBox(height: 24), //Login Button SizedBox( width: 250, child: ElevatedButton( onPressed: _submitForm, style: ElevatedButton.styleFrom( shape: const StadiumBorder(), padding: const EdgeInsets.symmetric(vertical: 16), backgroundColor: Theme.of(context).scaffoldBackgroundColor, foregroundColor: Theme.of(context).primaryColorDark, side: BorderSide( color: Theme.of(context).colorScheme.outline, width: 1), elevation: 0, ), child: Text( AppLocalizations.of(context).login, style: TextStyle( color: Theme.of(context) .colorScheme .onPrimaryContainer), ), ), ), const SizedBox(height: 15), const SizedBox(height: 25), ], ), ), ), ); } }