import 'package:flutter/material.dart'; import '../services/supabase_service.dart'; class LoginScreen extends StatefulWidget { const LoginScreen({super.key}); @override State createState() => _LoginScreenState(); } class _LoginScreenState extends State { final _emailController = TextEditingController(); final _passwordController = TextEditingController(); bool _isLoading = false; Future _handleLogin() async { setState(() => _isLoading = true); try { await SupabaseService().signIn( _emailController.text.trim(), _passwordController.text.trim(), ); if (mounted) { Navigator.pushReplacementNamed(context, '/home'); } } catch (e) { if (mounted) { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text('Error: $e'), backgroundColor: Colors.red), ); } } finally { if (mounted) setState(() => _isLoading = false); } } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.black, body: SingleChildScrollView( child: Padding( padding: const EdgeInsets.symmetric(horizontal: 30.0, vertical: 80.0), child: Column( children: [ const CircleAvatar( radius: 60, backgroundColor: Color(0xFF1A1A1A), child: Icon(Icons.coffee, size: 60, color: Colors.orange), ), const SizedBox(height: 30), const Text( 'Selamat Datang', style: TextStyle(color: Colors.green, fontSize: 32, fontWeight: FontWeight.bold), ), const Text( 'Sistem Kendali Pengering Kopi', style: TextStyle(color: Colors.grey, fontSize: 16), ), const SizedBox(height: 50), Container( padding: const EdgeInsets.all(20), decoration: BoxDecoration( color: const Color(0xFF1A1A1A), borderRadius: BorderRadius.circular(25), border: Border.all(color: Colors.grey.withOpacity(0.3)), ), child: Column( children: [ TextField( controller: _emailController, style: const TextStyle(color: Colors.white), decoration: const InputDecoration( prefixIcon: Icon(Icons.email, color: Colors.green), hintText: 'Email', hintStyle: TextStyle(color: Colors.grey), border: InputBorder.none, ), ), const Divider(color: Colors.grey), TextField( controller: _passwordController, obscureText: true, style: const TextStyle(color: Colors.white), decoration: const InputDecoration( prefixIcon: Icon(Icons.lock, color: Colors.green), suffixIcon: Icon(Icons.visibility, color: Colors.grey), hintText: 'Password', hintStyle: TextStyle(color: Colors.grey), border: InputBorder.none, ), ), const SizedBox(height: 30), SizedBox( width: double.infinity, height: 55, child: ElevatedButton( onPressed: _isLoading ? null : _handleLogin, style: ElevatedButton.styleFrom( backgroundColor: Colors.green, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(15), ), ), child: _isLoading ? const CircularProgressIndicator(color: Colors.white) : const Text( 'Masuk ke Akun', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.white), ), ), ), ], ), ), const SizedBox(height: 30), TextButton( onPressed: () => Navigator.pushNamed(context, '/register'), child: const Text( 'Belum punya akun? Daftar Sekarang', style: TextStyle(color: Colors.green), ), ), ], ), ), ), ); } }