Implement Login Page, Add App Initialization, Router, and Theme Management
This commit is contained in:
82
finlog_app/app/lib/features/login/pages/login_page.dart
Normal file
82
finlog_app/app/lib/features/login/pages/login_page.dart
Normal file
@@ -0,0 +1,82 @@
|
||||
import 'package:app/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<LoginPage> createState() => _LoginPageState();
|
||||
}
|
||||
|
||||
class _LoginPageState extends State<LoginPage> {
|
||||
bool _loading = false;
|
||||
|
||||
Future<void> _simulateLogin() async {
|
||||
if (_loading) return;
|
||||
setState(() => _loading = true);
|
||||
|
||||
// Simulate latency, perform demo login, then go home.
|
||||
await Future<void>.delayed(const Duration(milliseconds: 900));
|
||||
// await App.service<Auth>().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(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user