TKK_E32220112/Aplikasi Mobile/lib/app/modules/login/views/login_view.dart

183 lines
5.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart';
import '../controllers/login_controller.dart';
class LoginView extends GetView<LoginController> {
const LoginView({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color.fromARGB(255, 253, 253, 253),
body: SafeArea(
child: Stack(
children: [
Align(
alignment: Alignment.topRight,
child: IconButton(
icon: const Icon(Icons.admin_panel_settings, color: Colors.black, size: 32),
onPressed: () {
Get.toNamed('/login-admin'); // route ke halaman admin
},
),
),
Center(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildGreetingSection(),
const SizedBox(height: 20),
_buildLoginCard(context),
],
),
),
),
),
],
),
),
);
}
Widget _buildGreetingSection() {
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"Selamat Datang!",
style: GoogleFonts.poppins(
color: Colors.black,
fontSize: 22,
fontWeight: FontWeight.bold,
),
),
Text(
"Silakan masuk untuk melanjutkan",
style: GoogleFonts.poppins(
fontSize: 16,
color: Colors.black54,
),
),
],
);
}
Widget _buildLoginCard(BuildContext context) {
return Card(
color: Colors.white,
elevation: 6,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18),
),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
_buildInputField("Email", controller.emailController, false),
const SizedBox(height: 15),
_buildInputField("Kata Sandi", controller.passwordController, true),
const SizedBox(height: 0),
Align(
alignment: Alignment.centerRight,
child: TextButton(
onPressed: () {
// Panggil showForgotPasswordDialog yang ada di controller
controller.showForgotPasswordDialog();
},
child: Text(
"Lupa Kata Sandi?",
style: GoogleFonts.poppins(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Colors.black87,
),
),
),
),
_buildLoginButton(),
const SizedBox(height: 10),
_buildSignUpOption(),
],
),
),
);
}
Widget _buildSignUpOption() {
return Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Belum punya akun? ",
style: GoogleFonts.poppins(fontSize: 14, color: Colors.black54),
),
TextButton(
onPressed: () => Get.toNamed('/signup'),
child: Text(
"Daftar",
style: GoogleFonts.poppins(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
),
],
),
);
}
Widget _buildInputField(String label, TextEditingController controller, bool isObscure) {
return TextField(
controller: controller,
obscureText: isObscure,
decoration: InputDecoration(
labelText: label,
labelStyle: GoogleFonts.poppins(
color: Colors.black54,
fontSize: 14,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
filled: true,
fillColor: Colors.white,
),
);
}
Widget _buildLoginButton() {
return SizedBox(
width: double.infinity,
child: Obx(() => ElevatedButton(
onPressed: controller.isLoading.value ? null : controller.login,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.black,
padding: const EdgeInsets.symmetric(vertical: 15),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: controller.isLoading.value
? const CircularProgressIndicator(color: Colors.white)
: Text(
"Masuk",
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
)),
);
}
}