8/27/1
This commit is contained in:
@@ -1,19 +1,17 @@
|
||||
import 'package:SEFER/constant/box_name.dart';
|
||||
import 'package:SEFER/main.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
|
||||
import '../../constant/colors.dart';
|
||||
import 'package:SEFER/constant/box_name.dart';
|
||||
|
||||
class MyTextForm extends StatelessWidget {
|
||||
MyTextForm({
|
||||
super.key,
|
||||
const MyTextForm({
|
||||
Key? key,
|
||||
required this.controller,
|
||||
required this.label,
|
||||
required this.hint,
|
||||
required this.type,
|
||||
});
|
||||
}) : super(key: key);
|
||||
|
||||
final TextEditingController controller;
|
||||
final String label, hint;
|
||||
final TextInputType type;
|
||||
@@ -24,53 +22,73 @@ class MyTextForm extends StatelessWidget {
|
||||
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,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label.tr,
|
||||
style: TextStyle(
|
||||
color: CupertinoColors.label,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
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;
|
||||
},
|
||||
const SizedBox(height: 8),
|
||||
CupertinoTextField(
|
||||
controller: controller,
|
||||
keyboardType: type,
|
||||
placeholder: hint.tr,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: CupertinoColors.systemBackground,
|
||||
border: Border.all(color: CupertinoColors.systemGrey4),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
style: const TextStyle(color: CupertinoColors.label),
|
||||
placeholderStyle:
|
||||
const TextStyle(color: CupertinoColors.placeholderText),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
ValueListenableBuilder<TextEditingValue>(
|
||||
valueListenable: controller,
|
||||
builder: (context, value, child) {
|
||||
String? errorText = _getErrorText(value.text);
|
||||
return errorText != null
|
||||
? Text(
|
||||
errorText,
|
||||
style: const TextStyle(
|
||||
color: CupertinoColors.destructiveRed,
|
||||
fontSize: 12),
|
||||
)
|
||||
: const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String? _getErrorText(String value) {
|
||||
if (value.isEmpty) {
|
||||
return '${'Please enter'.tr} $label'.tr;
|
||||
}
|
||||
|
||||
if (type == TextInputType.emailAddress) {
|
||||
if (!value.contains('@')) {
|
||||
return 'Please enter a valid email.'.tr;
|
||||
}
|
||||
} else if (type == TextInputType.phone) {
|
||||
final box = GetStorage();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user