feat : login api call

This commit is contained in:
2025-05-17 15:24:06 +03:30
parent 0e630e709b
commit 303ff86d85
22 changed files with 518 additions and 522 deletions

View File

@@ -6,7 +6,8 @@ import 'package:rasadyar_core/core.dart';
class CaptchaWidgetLogic extends GetxController
with StateMixin<CaptchaResponseModel> {
TextEditingController textController = TextEditingController();
Rx<TextEditingController> textController = TextEditingController().obs;
RxnString captchaKey = RxnString();
GlobalKey<FormState> formKey = GlobalKey<FormState>();
AuthRepositoryImpl authRepository = diAuth.get<AuthRepositoryImpl>();
@@ -17,17 +18,19 @@ class CaptchaWidgetLogic extends GetxController
getCaptcha();
}
@override
void onClose() {
textController.value.dispose();
super.onClose();
}
Future<void> getCaptcha() async {
change(null, status: RxStatus.loading());
textController.value.clear();
safeCall(
call: () async => await authRepository.captcha(),
onSuccess: (value) {
captchaKey.value = value?.captchaKey;
change(value, status: RxStatus.success());
},
onError: (error, stackTrace) {

View File

@@ -8,9 +8,7 @@ import 'package:rasadyar_core/core.dart';
import 'logic.dart';
class CaptchaWidget extends GetView<CaptchaWidgetLogic> {
CaptchaWidget({super.key});
final CaptchaWidgetLogic logic = Get.put(CaptchaWidgetLogic());
const CaptchaWidget({super.key});
@override
Widget build(BuildContext context) {
@@ -19,7 +17,7 @@ class CaptchaWidget extends GetView<CaptchaWidgetLogic> {
children: [
Container(
width: 135,
height: 48,
height: 50,
clipBehavior: Clip.antiAliasWithSaveLayer,
decoration: BoxDecoration(
color: AppColor.whiteNormalHover,
@@ -27,75 +25,62 @@ class CaptchaWidget extends GetView<CaptchaWidgetLogic> {
borderRadius: BorderRadius.circular(8),
),
child: controller.obx(
(state) => Image.memory(base64Decode(state?.captchaImage??''),fit: BoxFit.cover,),
(state) => Image.memory(
base64Decode(state?.captchaImage ?? ''),
fit: BoxFit.cover,
),
onLoading: const Center(
child: CupertinoActivityIndicator(
color: AppColor.blueNormal,
),
child: CupertinoActivityIndicator(color: AppColor.blueNormal),
),
onError: (error) {
return const Center(
child: Text(
'خطا در بارگذاری کد امنیتی',
style: AppFonts.yekan13,));
child: Text(
'خطا در بارگذاری کد امنیتی',
style: AppFonts.yekan13,
),
);
},
),
),
const SizedBox(height: 20),
IconButton(
padding: EdgeInsets.zero,
onPressed: controller.getCaptcha,
icon: Icon(CupertinoIcons.refresh, size: 16),
GestureDetector(
onTap: controller.getCaptcha,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 3),
child: Icon(CupertinoIcons.refresh, size: 20),
),
),
const SizedBox(width: 8),
Expanded(
child: Form(
key: controller.formKey,
autovalidateMode: AutovalidateMode.onUserInteraction,
child: TextFormField(
controller: controller.textController,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
gapPadding: 11,
autovalidateMode: AutovalidateMode.disabled,
child: ObxValue((data) {
return RTextField(
label: 'کد امنیتی',
controller: data.value,
keyboardType: TextInputType.numberWithOptions(
decimal: false,
signed: false,
),
labelText: 'کد امنیتی',
labelStyle: AppFonts.yekan13,
errorStyle: AppFonts.yekan10.copyWith(
color: AppColor.redNormal,
fontSize: 8,
),
suffixIconConstraints: BoxConstraints(
maxHeight: 24,
minHeight: 24,
maxWidth: 24,
minWidth: 24,
),
suffix:
controller.textController.text
.trim()
.isNotEmpty
? clearButton(() => controller.textController.clear())
: null,
counterText: '',
),
keyboardType: TextInputType.numberWithOptions(
decimal: false,
signed: false,
),
maxLines: 1,
maxLength: 6,
onChanged: (value) {},
validator: (value) {
if (value == null || value.isEmpty) {
return 'کد امنیتی را وارد کنید';
}
/*if (value != controller.captchaCode.toString()) {
return '⚠️کد امنیتی وارد شده اشتباه است';
}*/
return null;
},
style: AppFonts.yekan13,
),
maxLines: 1,
maxLength: 6,
suffixIcon:
(data.value.text.trim().isNotEmpty ?? false)
? clearButton(
() => controller.textController.value.clear(),
)
: null,
onSubmitted: (data) {},
validator: (value) {
if (value == null || value.isEmpty) {
return 'کد امنیتی را وارد کنید';
}
return null;
},
style: AppFonts.yekan13,
);
}, controller.textController),
),
),
],