fix: interface and logic
This commit is contained in:
parent
9c36507fb7
commit
4041384733
|
@ -1,31 +1,62 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class GlobalButton extends StatelessWidget {
|
enum ButtonType { primary, secondary, disabled }
|
||||||
final VoidCallback onPressed;
|
|
||||||
final String text;
|
|
||||||
|
|
||||||
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
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(
|
return SizedBox(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
foregroundColor: Colors.white,
|
backgroundColor: backgroundColor,
|
||||||
backgroundColor: const Color(0xFF0052CC),
|
foregroundColor: foregroundColor,
|
||||||
shadowColor: const Color(0x330052CC),
|
elevation: isDisabled ? 0 : 4,
|
||||||
elevation: 4,
|
shadowColor: !isDisabled ? backgroundColor.withOpacity(0.3) : Colors.transparent,
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
side: borderColor != null ? BorderSide(color: borderColor, width: 2) : BorderSide.none,
|
||||||
),
|
),
|
||||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
||||||
textStyle: const TextStyle(
|
textStyle: const TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onPressed: onPressed,
|
onPressed: isDisabled ? null : onPressed,
|
||||||
child: Text(text),
|
child: Text(text),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -29,7 +29,7 @@ class GlobalTextField extends StatelessWidget {
|
||||||
hintText: hintText,
|
hintText: hintText,
|
||||||
hintStyle: const TextStyle(color: Color(0xFF6B778C), fontSize: 14),
|
hintStyle: const TextStyle(color: Color(0xFF6B778C), fontSize: 14),
|
||||||
filled: true,
|
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),
|
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
|
|
@ -12,6 +12,7 @@ class HomeView extends GetView<HomeController> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
backgroundColor: const Color(0xFFFAFBFC),
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: ListView(
|
child: ListView(
|
||||||
children: [
|
children: [
|
||||||
|
|
|
@ -2,6 +2,7 @@ import 'package:get/get.dart';
|
||||||
import 'package:google_sign_in/google_sign_in.dart';
|
import 'package:google_sign_in/google_sign_in.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:quiz_app/app/routes/app_pages.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/core/utils/logger.dart';
|
||||||
import 'package:quiz_app/data/models/login/login_request_model.dart';
|
import 'package:quiz_app/data/models/login/login_request_model.dart';
|
||||||
import 'package:quiz_app/data/models/login/login_response_model.dart';
|
import 'package:quiz_app/data/models/login/login_response_model.dart';
|
||||||
|
@ -13,15 +14,37 @@ class LoginController extends GetxController {
|
||||||
final UserStorageService _userStorageService;
|
final UserStorageService _userStorageService;
|
||||||
|
|
||||||
LoginController(this._authService, this._userStorageService);
|
LoginController(this._authService, this._userStorageService);
|
||||||
|
|
||||||
final TextEditingController emailController = TextEditingController();
|
final TextEditingController emailController = TextEditingController();
|
||||||
final TextEditingController passwordController = TextEditingController();
|
final TextEditingController passwordController = TextEditingController();
|
||||||
|
|
||||||
|
final Rx<ButtonType> isButtonEnabled = ButtonType.disabled.obs;
|
||||||
|
|
||||||
var isPasswordHidden = true.obs;
|
var isPasswordHidden = true.obs;
|
||||||
var isLoading = false.obs;
|
var isLoading = false.obs;
|
||||||
|
|
||||||
final GoogleSignIn _googleSignIn = GoogleSignIn(
|
final GoogleSignIn _googleSignIn = GoogleSignIn(
|
||||||
scopes: ['email', 'profile', 'openid'],
|
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() {
|
void togglePasswordVisibility() {
|
||||||
isPasswordHidden.value = !isPasswordHidden.value;
|
isPasswordHidden.value = !isPasswordHidden.value;
|
||||||
}
|
}
|
||||||
|
@ -89,20 +112,4 @@ class LoginController extends GetxController {
|
||||||
}
|
}
|
||||||
|
|
||||||
void goToRegsPage() => Get.toNamed(AppRoutes.registerPage);
|
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),
|
const SizedBox(height: 32),
|
||||||
GlobalButton(
|
Obx(() => GlobalButton(
|
||||||
onPressed: controller.loginWithEmail,
|
onPressed: controller.loginWithEmail,
|
||||||
text: "Masuk",
|
text: "Masuk",
|
||||||
),
|
type: controller.isButtonEnabled.value,
|
||||||
|
)),
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
const LabelTextField(
|
const LabelTextField(
|
||||||
label: "OR",
|
label: "OR",
|
||||||
|
|
|
@ -11,6 +11,7 @@ class RegisterView extends GetView<RegisterController> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
backgroundColor: const Color(0xFFFAFBFC),
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
|
|
@ -29,6 +29,7 @@ class SplashScreenView extends StatelessWidget {
|
||||||
});
|
});
|
||||||
|
|
||||||
return const Scaffold(
|
return const Scaffold(
|
||||||
|
backgroundColor: Color(0xFFFAFBFC),
|
||||||
body: Center(
|
body: Center(
|
||||||
child: AppName(),
|
child: AppName(),
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue