Files

113 lines
3.5 KiB
Dart
Raw Permalink Normal View History

2025-07-28 15:57:30 +03:30
import 'dart:convert';
2025-06-03 16:55:49 +03:30
import 'dart:math';
2025-05-17 09:39:09 +03:30
2025-05-17 09:08:46 +03:30
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart';
import 'package:rasadyar_inspection/presentation/pages/auth/logic.dart';
2025-08-02 15:09:06 +03:30
2025-05-17 09:08:46 +03:30
import 'logic.dart';
class CaptchaWidget extends GetView<CaptchaWidgetLogic> {
2025-05-17 15:24:06 +03:30
const CaptchaWidget({super.key});
2025-05-17 09:08:46 +03:30
@override
Widget build(BuildContext context) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2025-05-17 15:24:06 +03:30
GestureDetector(
2025-06-03 16:55:49 +03:30
onTap: controller.getCaptcha,
child: Container(
width: 135,
height: 50,
clipBehavior: Clip.antiAliasWithSaveLayer,
decoration: BoxDecoration(
color: AppColor.whiteNormalHover,
border: Border.all(color: Colors.grey.shade300),
borderRadius: BorderRadius.circular(8),
),
child: controller.obx(
2025-08-02 15:09:06 +03:30
(state) =>
Image.memory(base64Decode(state?.captchaImage ?? ''), fit: BoxFit.cover),
2025-07-12 14:46:52 +03:30
onLoading: const Center(
child: CupertinoActivityIndicator(color: AppColor.blueNormal),
),
2025-06-03 16:55:49 +03:30
onError: (error) {
2025-07-12 14:46:52 +03:30
return Center(
child: Text('خطا ', style: AppFonts.yekan13.copyWith(color: Colors.red)),
);
2025-06-03 16:55:49 +03:30
},
),
),
),
2025-05-18 10:21:50 +03:30
2025-05-17 15:24:06 +03:30
const SizedBox(width: 8),
2025-05-17 09:08:46 +03:30
Expanded(
child: Form(
key: controller.formKey,
2025-05-17 15:24:06 +03:30
autovalidateMode: AutovalidateMode.disabled,
2025-07-06 20:44:11 +03:30
child: RTextField(
label: 'کد امنیتی',
controller: controller.textController,
2025-08-02 12:19:25 +03:30
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(color: AppColor.textColor, width: 1),
),
2025-07-06 20:44:11 +03:30
keyboardType: TextInputType.numberWithOptions(decimal: false, signed: false),
maxLines: 1,
maxLength: 6,
2025-08-02 15:09:06 +03:30
suffixIcon: (controller.textController.text
.trim()
.isNotEmpty ?? false)
2025-07-06 20:44:11 +03:30
? clearButton(() => controller.textController.clear())
: null,
2025-05-17 15:24:06 +03:30
2025-07-06 20:44:11 +03:30
validator: (value) {
if (value == null || value.isEmpty) {
return 'کد امنیتی را وارد کنید';
}
return null;
},
onChanged: (pass) {
2025-07-12 14:46:52 +03:30
if (pass.length == 6) {
if (controller.formKey.currentState?.validate() ?? false) {
2025-08-02 15:09:06 +03:30
Get
.find<AuthLogic>()
.isDisabled
.value = false;
2025-06-03 22:52:21 +03:30
}
2025-07-06 20:44:11 +03:30
}
},
style: AppFonts.yekan13,
2025-07-12 14:46:52 +03:30
),
2025-05-17 09:08:46 +03:30
),
),
],
);
}
}
2025-06-03 16:55:49 +03:30
class _CaptchaLinePainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final random = Random();
final paint1 = Paint()
2025-06-03 22:52:21 +03:30
..color = Colors.deepOrange
2025-06-03 16:55:49 +03:30
..strokeWidth = 2;
final paint2 = Paint()
2025-07-12 14:46:52 +03:30
..color = Colors.blue
2025-06-03 16:55:49 +03:30
..strokeWidth = 2;
2025-07-12 14:46:52 +03:30
// First line: top-left to bottom-right
canvas.drawLine(Offset(0, 0), Offset(size.width, size.height), paint1);
2025-06-03 16:55:49 +03:30
2025-07-12 14:46:52 +03:30
// Second line: bottom-left to top-right
canvas.drawLine(Offset(0, size.height), Offset(size.width, 0), paint2);
2025-06-03 16:55:49 +03:30
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
}