2025-08-12 17:13:02 +07:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
2025-08-13 01:17:00 +07:00
|
|
|
import '../../../../common/extension/extension.dart';
|
2025-08-12 17:13:02 +07:00
|
|
|
import '../../../../common/theme/theme.dart';
|
|
|
|
|
import '../../../components/button/button.dart';
|
|
|
|
|
import '../../../components/spacer/spacer.dart';
|
2025-08-12 17:36:41 +07:00
|
|
|
import '../../../router/app_router.gr.dart';
|
2025-08-12 17:13:02 +07:00
|
|
|
import 'widgets/email_field.dart';
|
|
|
|
|
import 'widgets/password_field.dart';
|
|
|
|
|
|
|
|
|
|
@RoutePage()
|
|
|
|
|
class LoginPage extends StatefulWidget {
|
|
|
|
|
const LoginPage({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<LoginPage> createState() => _LoginPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _LoginPageState extends State<LoginPage> with TickerProviderStateMixin {
|
|
|
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
|
final _emailController = TextEditingController();
|
|
|
|
|
final _passwordController = TextEditingController();
|
|
|
|
|
|
|
|
|
|
bool _isLoading = false;
|
|
|
|
|
|
|
|
|
|
late AnimationController _fadeController;
|
|
|
|
|
late AnimationController _slideController;
|
|
|
|
|
late Animation<double> _fadeAnimation;
|
|
|
|
|
late Animation<Offset> _slideAnimation;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
|
|
_fadeController = AnimationController(
|
|
|
|
|
duration: const Duration(milliseconds: 1500),
|
|
|
|
|
vsync: this,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
_slideController = AnimationController(
|
|
|
|
|
duration: const Duration(milliseconds: 1200),
|
|
|
|
|
vsync: this,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
_fadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
|
|
|
|
|
CurvedAnimation(parent: _fadeController, curve: Curves.easeInOut),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
_slideAnimation =
|
|
|
|
|
Tween<Offset>(begin: const Offset(0, 0.3), end: Offset.zero).animate(
|
|
|
|
|
CurvedAnimation(parent: _slideController, curve: Curves.easeOutCubic),
|
|
|
|
|
);
|
|
|
|
|
_emailController.text = 'test@example.com';
|
|
|
|
|
_passwordController.text = 'password';
|
|
|
|
|
_fadeController.forward();
|
|
|
|
|
_slideController.forward();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_fadeController.dispose();
|
|
|
|
|
_slideController.dispose();
|
|
|
|
|
_emailController.dispose();
|
|
|
|
|
_passwordController.dispose();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _handleLogin() async {
|
|
|
|
|
if (_formKey.currentState!.validate()) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Simulasi proses login
|
|
|
|
|
await Future.delayed(const Duration(seconds: 2));
|
|
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
2025-08-12 17:36:41 +07:00
|
|
|
|
|
|
|
|
context.router.replace(const MainRoute());
|
2025-08-12 17:13:02 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
body: Container(
|
|
|
|
|
decoration: const BoxDecoration(
|
|
|
|
|
gradient: LinearGradient(
|
|
|
|
|
begin: Alignment.topLeft,
|
|
|
|
|
end: Alignment.bottomRight,
|
|
|
|
|
colors: AppColor.primaryGradient,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: SafeArea(
|
|
|
|
|
child: Center(
|
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: AppValue.padding),
|
|
|
|
|
child: FadeTransition(
|
|
|
|
|
opacity: _fadeAnimation,
|
|
|
|
|
child: SlideTransition(
|
|
|
|
|
position: _slideAnimation,
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
2025-08-13 01:17:00 +07:00
|
|
|
_buildLogo(context),
|
2025-08-12 17:13:02 +07:00
|
|
|
SpaceHeight(48),
|
2025-08-13 01:17:00 +07:00
|
|
|
_buildLoginCard(context),
|
2025-08-12 17:13:02 +07:00
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-13 01:17:00 +07:00
|
|
|
Widget _buildLogo(BuildContext context) {
|
2025-08-12 17:13:02 +07:00
|
|
|
return Column(
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
2025-08-13 01:17:00 +07:00
|
|
|
context.lang.login_header,
|
2025-08-12 17:13:02 +07:00
|
|
|
style: AppStyle.h1.copyWith(
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
color: AppColor.white,
|
|
|
|
|
),
|
2025-08-13 01:17:00 +07:00
|
|
|
textAlign: TextAlign.center,
|
2025-08-12 17:13:02 +07:00
|
|
|
),
|
|
|
|
|
const SpaceHeight(8),
|
|
|
|
|
Text(
|
2025-08-13 01:17:00 +07:00
|
|
|
context.lang.login_desc,
|
2025-08-12 17:13:02 +07:00
|
|
|
style: AppStyle.lg.copyWith(color: AppColor.textLight),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-13 01:17:00 +07:00
|
|
|
Widget _buildLoginCard(BuildContext context) {
|
2025-08-12 17:13:02 +07:00
|
|
|
return Container(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 32, horizontal: 24),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColor.white,
|
|
|
|
|
borderRadius: BorderRadius.circular(24),
|
|
|
|
|
boxShadow: [
|
|
|
|
|
BoxShadow(
|
|
|
|
|
color: AppColor.black.withOpacity(0.1),
|
|
|
|
|
blurRadius: 30,
|
|
|
|
|
offset: const Offset(0, 15),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
child: Form(
|
|
|
|
|
key: _formKey,
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
|
children: [
|
|
|
|
|
LoginEmailField(controller: _emailController),
|
|
|
|
|
const SpaceHeight(24),
|
|
|
|
|
LoginPasswordField(controller: _passwordController),
|
|
|
|
|
const SpaceHeight(16),
|
2025-08-13 01:17:00 +07:00
|
|
|
_buildForgetPassword(context),
|
2025-08-12 17:13:02 +07:00
|
|
|
const SpaceHeight(32),
|
|
|
|
|
_buildLoginButton(),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-13 01:17:00 +07:00
|
|
|
Widget _buildForgetPassword(BuildContext context) {
|
2025-08-12 17:13:02 +07:00
|
|
|
return Align(
|
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
|
child: GestureDetector(
|
|
|
|
|
onTap: () {},
|
|
|
|
|
child: Text(
|
2025-08-13 01:17:00 +07:00
|
|
|
'${context.lang.forgot_password}?',
|
2025-08-12 17:13:02 +07:00
|
|
|
style: AppStyle.md.copyWith(
|
|
|
|
|
color: AppColor.primary,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildLoginButton() {
|
|
|
|
|
return AppElevatedButton(
|
2025-08-13 01:17:00 +07:00
|
|
|
text: context.lang.sign_in,
|
2025-08-12 17:13:02 +07:00
|
|
|
isLoading: _isLoading,
|
|
|
|
|
onPressed: _isLoading ? null : _handleLogin,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|