import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../services/iptv_provider.dart'; class LoginScreen extends StatefulWidget { const LoginScreen({super.key}); @override State createState() => _LoginScreenState(); } class _LoginScreenState extends State { final _serverController = TextEditingController(); final _usernameController = TextEditingController(); final _passwordController = TextEditingController(); bool _obscurePassword = true; @override void dispose() { _serverController.dispose(); _usernameController.dispose(); _passwordController.dispose(); super.dispose(); } Future _login() async { final provider = context.read(); await provider.login( _serverController.text.trim(), _usernameController.text.trim(), _passwordController.text.trim(), ); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.black, body: Center( child: Container( constraints: const BoxConstraints(maxWidth: 400), padding: const EdgeInsets.all(24), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ const Icon( Icons.live_tv, size: 80, color: Colors.red, ), const SizedBox(height: 24), const Text( 'XStream TV', style: TextStyle( fontSize: 32, fontWeight: FontWeight.bold, color: Colors.white, ), ), const SizedBox(height: 8), const Text( 'IPTV Player for Android TV', style: TextStyle( fontSize: 14, color: Colors.grey, ), ), const SizedBox(height: 48), TextField( controller: _serverController, style: const TextStyle(color: Colors.white), decoration: InputDecoration( labelText: 'Server URL', labelStyle: const TextStyle(color: Colors.grey), hintText: 'http://example.com', hintStyle: const TextStyle(color: Colors.grey), prefixIcon: const Icon(Icons.dns, color: Colors.grey), filled: true, fillColor: Colors.grey[900], border: OutlineInputBorder( borderRadius: BorderRadius.circular(8), borderSide: BorderSide.none, ), ), ), const SizedBox(height: 16), TextField( controller: _usernameController, style: const TextStyle(color: Colors.white), decoration: InputDecoration( labelText: 'Username', labelStyle: const TextStyle(color: Colors.grey), prefixIcon: const Icon(Icons.person, color: Colors.grey), filled: true, fillColor: Colors.grey[900], border: OutlineInputBorder( borderRadius: BorderRadius.circular(8), borderSide: BorderSide.none, ), ), ), const SizedBox(height: 16), TextField( controller: _passwordController, obscureText: _obscurePassword, style: const TextStyle(color: Colors.white), decoration: InputDecoration( labelText: 'Password', labelStyle: const TextStyle(color: Colors.grey), prefixIcon: const Icon(Icons.lock, color: Colors.grey), suffixIcon: IconButton( icon: Icon( _obscurePassword ? Icons.visibility : Icons.visibility_off, color: Colors.grey, ), onPressed: () { setState(() { _obscurePassword = !_obscurePassword; }); }, ), filled: true, fillColor: Colors.grey[900], border: OutlineInputBorder( borderRadius: BorderRadius.circular(8), borderSide: BorderSide.none, ), ), ), const SizedBox(height: 24), Consumer( builder: (context, provider, _) { if (provider.error != null) { return Padding( padding: const EdgeInsets.only(bottom: 16), child: Text( provider.error!, style: const TextStyle(color: Colors.red), textAlign: TextAlign.center, ), ); } return const SizedBox.shrink(); }, ), SizedBox( width: double.infinity, height: 50, child: Consumer( builder: (context, provider, _) { return ElevatedButton( onPressed: provider.isLoading ? null : _login, style: ElevatedButton.styleFrom( backgroundColor: Colors.red, foregroundColor: Colors.white, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(8), ), ), child: provider.isLoading ? const SizedBox( width: 24, height: 24, child: CircularProgressIndicator( color: Colors.white, strokeWidth: 2, ), ) : const Text( 'Login', style: TextStyle(fontSize: 16), ), ); }, ), ), ], ), ), ), ); } }