77 lines
2.3 KiB
Dart
77 lines
2.3 KiB
Dart
import 'package:SEFER/constant/box_name.dart';
|
|
import 'package:SEFER/main.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:get_storage/get_storage.dart';
|
|
|
|
import '../../constant/colors.dart';
|
|
|
|
class MyTextForm extends StatelessWidget {
|
|
MyTextForm({
|
|
super.key,
|
|
required this.controller,
|
|
required this.label,
|
|
required this.hint,
|
|
required this.type,
|
|
});
|
|
final TextEditingController controller;
|
|
final String label, hint;
|
|
final TextInputType type;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(bottom: 10),
|
|
child: SizedBox(
|
|
width: Get.width * .8,
|
|
child: TextFormField(
|
|
keyboardType: type,
|
|
cursorColor: AppColor.accentColor,
|
|
controller: controller,
|
|
decoration: InputDecoration(
|
|
focusedBorder: OutlineInputBorder(
|
|
borderSide: const BorderSide(
|
|
color: AppColor.primaryColor,
|
|
width: 2.0,
|
|
),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
focusColor: AppColor.accentColor,
|
|
fillColor: AppColor.accentColor,
|
|
border: const OutlineInputBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(12))),
|
|
labelText: label.tr,
|
|
hintText: hint.tr,
|
|
),
|
|
validator: (value) {
|
|
if (value!.isEmpty) {
|
|
return '${'Please enter'.tr} $label.'.tr;
|
|
}
|
|
if (label.contains("Insert card number".tr)) {
|
|
if (value.length != 16) {
|
|
return "Please enter a valid card 16-digit number.".tr;
|
|
}
|
|
}
|
|
|
|
if (type == TextInputType.emailAddress) {
|
|
if (!value.contains('@')) {
|
|
return 'Please enter a valid email.'.tr;
|
|
}
|
|
} else if (type == TextInputType.phone) {
|
|
if (box.read(BoxName.countryCode) == 'Egypt') {
|
|
if (value.length != 11) {
|
|
return 'Please enter a valid phone number.'.tr;
|
|
}
|
|
} else if (value.length != 10) {
|
|
return 'Please enter a valid phone number.'.tr;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|