diff --git a/lib/component/global_button.dart b/lib/component/global_button.dart index a7c145c..0f03d20 100644 --- a/lib/component/global_button.dart +++ b/lib/component/global_button.dart @@ -1,31 +1,62 @@ import 'package:flutter/material.dart'; -class GlobalButton extends StatelessWidget { - final VoidCallback onPressed; - final String text; +enum ButtonType { primary, secondary, disabled } - const GlobalButton({super.key, required this.onPressed, required this.text}); +class GlobalButton extends StatelessWidget { + final VoidCallback? onPressed; + final String text; + final ButtonType type; + + const GlobalButton({ + super.key, + required this.text, + required this.onPressed, + this.type = ButtonType.primary, + }); @override Widget build(BuildContext context) { + final bool isDisabled = type == ButtonType.disabled || onPressed == null; + + Color backgroundColor; + Color foregroundColor; + Color? borderColor; + + switch (type) { + case ButtonType.primary: + backgroundColor = const Color(0xFF0052CC); + foregroundColor = Colors.white; + break; + case ButtonType.secondary: + backgroundColor = Colors.white; + foregroundColor = const Color(0xFF0052CC); + borderColor = const Color(0xFF0052CC); + break; + case ButtonType.disabled: + backgroundColor = const Color(0xFFE0E0E0); + foregroundColor = const Color(0xFF9E9E9E); + break; + } + return SizedBox( width: double.infinity, child: ElevatedButton( style: ElevatedButton.styleFrom( - foregroundColor: Colors.white, - backgroundColor: const Color(0xFF0052CC), - shadowColor: const Color(0x330052CC), - elevation: 4, + backgroundColor: backgroundColor, + foregroundColor: foregroundColor, + elevation: isDisabled ? 0 : 4, + shadowColor: !isDisabled ? backgroundColor.withOpacity(0.3) : Colors.transparent, + padding: const EdgeInsets.symmetric(vertical: 16), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(16), + side: borderColor != null ? BorderSide(color: borderColor, width: 2) : BorderSide.none, ), - padding: const EdgeInsets.symmetric(vertical: 16), textStyle: const TextStyle( fontSize: 16, fontWeight: FontWeight.w600, ), ), - onPressed: onPressed, + onPressed: isDisabled ? null : onPressed, child: Text(text), ), ); diff --git a/lib/component/global_text_field.dart b/lib/component/global_text_field.dart index 0827170..f855ad4 100644 --- a/lib/component/global_text_field.dart +++ b/lib/component/global_text_field.dart @@ -29,7 +29,7 @@ class GlobalTextField extends StatelessWidget { hintText: hintText, hintStyle: const TextStyle(color: Color(0xFF6B778C), fontSize: 14), filled: true, - fillColor: const Color(0xFFFAFBFC), // Background soft white + fillColor: const Color.fromARGB(255, 234, 234, 235), // Background soft white contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16), border: OutlineInputBorder( borderRadius: BorderRadius.circular(16), diff --git a/lib/feature/home/view/home_page.dart b/lib/feature/home/view/home_page.dart index 794116a..5a8fd41 100644 --- a/lib/feature/home/view/home_page.dart +++ b/lib/feature/home/view/home_page.dart @@ -12,6 +12,7 @@ class HomeView extends GetView { @override Widget build(BuildContext context) { return Scaffold( + backgroundColor: const Color(0xFFFAFBFC), body: SafeArea( child: ListView( children: [ diff --git a/lib/feature/login/controllers/login_controller.dart b/lib/feature/login/controllers/login_controller.dart index dfc4297..8160f24 100644 --- a/lib/feature/login/controllers/login_controller.dart +++ b/lib/feature/login/controllers/login_controller.dart @@ -2,6 +2,7 @@ import 'package:get/get.dart'; import 'package:google_sign_in/google_sign_in.dart'; import 'package:flutter/material.dart'; import 'package:quiz_app/app/routes/app_pages.dart'; +import 'package:quiz_app/component/global_button.dart'; import 'package:quiz_app/core/utils/logger.dart'; import 'package:quiz_app/data/models/login/login_request_model.dart'; import 'package:quiz_app/data/models/login/login_response_model.dart'; @@ -13,15 +14,37 @@ class LoginController extends GetxController { final UserStorageService _userStorageService; LoginController(this._authService, this._userStorageService); + final TextEditingController emailController = TextEditingController(); final TextEditingController passwordController = TextEditingController(); + final Rx isButtonEnabled = ButtonType.disabled.obs; + var isPasswordHidden = true.obs; var isLoading = false.obs; + final GoogleSignIn _googleSignIn = GoogleSignIn( scopes: ['email', 'profile', 'openid'], ); + @override + void onInit() { + super.onInit(); + emailController.addListener(_validateFields); + passwordController.addListener(_validateFields); + } + + void _validateFields() { + final isEmailNotEmpty = emailController.text.trim().isNotEmpty; + final isPasswordNotEmpty = passwordController.text.trim().isNotEmpty; + print('its type'); + if (isEmailNotEmpty && isPasswordNotEmpty) { + isButtonEnabled.value = ButtonType.primary; + } else { + isButtonEnabled.value = ButtonType.disabled; + } + } + void togglePasswordVisibility() { isPasswordHidden.value = !isPasswordHidden.value; } @@ -89,20 +112,4 @@ class LoginController extends GetxController { } void goToRegsPage() => Get.toNamed(AppRoutes.registerPage); - - // /// **🔹 Logout Function** - // Future logout() async { - // try { - // await _googleSignIn.signOut(); - // // await _secureStorage.delete(key: "auth_token"); - - // emailController.clear(); - // passwordController.clear(); - - // Get.snackbar("Success", "Logged out successfully"); - // } catch (e) { - // logC.e("Logout error: $e"); - // Get.snackbar("Error", "Logout failed"); - // } - // } } diff --git a/lib/feature/login/view/login_page.dart b/lib/feature/login/view/login_page.dart index 897cdeb..9840f42 100644 --- a/lib/feature/login/view/login_page.dart +++ b/lib/feature/login/view/login_page.dart @@ -57,10 +57,11 @@ class LoginView extends GetView { ), ), const SizedBox(height: 32), - GlobalButton( - onPressed: controller.loginWithEmail, - text: "Masuk", - ), + Obx(() => GlobalButton( + onPressed: controller.loginWithEmail, + text: "Masuk", + type: controller.isButtonEnabled.value, + )), const SizedBox(height: 24), const LabelTextField( label: "OR", diff --git a/lib/feature/register/view/register_page.dart b/lib/feature/register/view/register_page.dart index 5e9621f..0063f4a 100644 --- a/lib/feature/register/view/register_page.dart +++ b/lib/feature/register/view/register_page.dart @@ -11,6 +11,7 @@ class RegisterView extends GetView { @override Widget build(BuildContext context) { return Scaffold( + backgroundColor: const Color(0xFFFAFBFC), body: SafeArea( child: Padding( padding: const EdgeInsets.all(16.0), diff --git a/lib/feature/splash_screen/presentation/splash_screen_page.dart b/lib/feature/splash_screen/presentation/splash_screen_page.dart index c5c2dc5..4081eaa 100644 --- a/lib/feature/splash_screen/presentation/splash_screen_page.dart +++ b/lib/feature/splash_screen/presentation/splash_screen_page.dart @@ -29,6 +29,7 @@ class SplashScreenView extends StatelessWidget { }); return const Scaffold( + backgroundColor: Color(0xFFFAFBFC), body: Center( child: AppName(), ),