fix: interface and logic
This commit is contained in:
parent
9c36507fb7
commit
4041384733
|
@ -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),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -12,6 +12,7 @@ class HomeView extends GetView<HomeController> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFFAFBFC),
|
||||
body: SafeArea(
|
||||
child: ListView(
|
||||
children: [
|
||||
|
|
|
@ -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<ButtonType> 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<void> 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");
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -57,10 +57,11 @@ class LoginView extends GetView<LoginController> {
|
|||
),
|
||||
),
|
||||
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",
|
||||
|
|
|
@ -11,6 +11,7 @@ class RegisterView extends GetView<RegisterController> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFFAFBFC),
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
|
|
|
@ -29,6 +29,7 @@ class SplashScreenView extends StatelessWidget {
|
|||
});
|
||||
|
||||
return const Scaffold(
|
||||
backgroundColor: Color(0xFFFAFBFC),
|
||||
body: Center(
|
||||
child: AppName(),
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue