import 'package:app/core/app/router.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; class LoginPage extends StatefulWidget { const LoginPage({super.key}); @override State createState() => _LoginPageState(); } class _LoginPageState extends State { bool _loading = false; Future _simulateLogin() async { if (_loading) return; setState(() => _loading = true); // Simulate latency, perform demo login, then go home. await Future.delayed(const Duration(milliseconds: 900)); // await App.service().login('demo', 'demo'); if (!mounted) return; context.go(AppRoute.home.path); setState(() => _loading = false); } @override Widget build(BuildContext context) { final theme = Theme.of(context); return Scaffold( appBar: AppBar(title: const Text('Login')), body: Center( child: ConstrainedBox( constraints: const BoxConstraints(maxWidth: 360), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ const FlutterLogo(size: 64), const SizedBox(height: 24), Text('Please sign in', style: theme.textTheme.titleMedium), const SizedBox(height: 24), SizedBox( width: double.infinity, child: ElevatedButton( onPressed: _loading ? null : _simulateLogin, child: AnimatedSwitcher( duration: const Duration(milliseconds: 250), transitionBuilder: (child, anim) => FadeTransition(opacity: anim, child: child), child: _loading ? const SizedBox( key: ValueKey('loading'), width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2), ) : const Text('Login', key: ValueKey('text')), ), ), ), const SizedBox(height: 12), AnimatedSwitcher( duration: const Duration(milliseconds: 250), child: _loading ? Padding( padding: const EdgeInsets.only(top: 4), child: Text( 'Signing you in…', style: theme.textTheme.bodySmall, ), ) : const SizedBox.shrink(), ), ], ), ), ), ); } }