Files
Tanami_App/lib/shared/components/form_label_textfield.dart

96 lines
3.3 KiB
Dart
Raw Normal View History

2024-05-28 16:35:33 +05:30
import 'package:flutter/material.dart';
2024-06-06 18:40:58 +05:30
import 'package:flutter/services.dart';
2024-05-28 16:35:33 +05:30
import 'package:gap/gap.dart';
import 'package:tanami_app/core/styles/app_color.dart';
import 'package:tanami_app/core/styles/app_text.dart';
import 'package:tanami_app/shared/components/password_text_form_field.dart';
import 'package:tanami_app/shared/components/text_widget.dart';
2024-05-29 13:21:55 +05:30
import '../../core/routes/route_name.dart';
import '../../core/routes/routes.dart';
2024-05-28 16:35:33 +05:30
import 'text_from_field_widget.dart';
class FormLabelTextField extends StatelessWidget {
const FormLabelTextField({
super.key,
required this.title,
required this.type,
required this.textEditingController,
required this.hintText,
2024-05-29 13:21:55 +05:30
this.prefixWidget,
2024-06-06 18:40:58 +05:30
this.onChangeFun,
2024-05-28 16:35:33 +05:30
});
final String title;
final String type;
final String hintText;
final TextEditingController textEditingController;
2024-05-29 13:21:55 +05:30
final Widget? prefixWidget;
2024-06-06 18:40:58 +05:30
final Function(String)? onChangeFun;
2024-05-28 16:35:33 +05:30
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2024-05-31 17:01:48 +05:30
TextWidget().text14W500(
2024-05-28 16:35:33 +05:30
title,
clr: AppColor.textLabelColor,
2024-06-06 18:40:58 +05:30
txtAlign: type == "description" ? TextAlign.start : TextAlign.center,
2024-05-28 16:35:33 +05:30
),
const Gap(10),
type == "password"
? PasswordField(
controller: textEditingController,
2024-06-18 11:20:24 +05:30
hintText: hintText,
2024-05-28 16:35:33 +05:30
)
: textFormField(
2024-06-06 18:40:58 +05:30
onInput: onChangeFun,
2024-05-28 16:35:33 +05:30
validator: (value) {
if (type == "phone number") {
if (value != null && value.isEmpty) {
return AppText.enterPhoneNo;
}
return null;
} else if (type == "country selection") {
if (textEditingController.text.isEmpty) {
return AppText.chooseCountry;
}
return null;
2024-06-06 18:40:58 +05:30
} else if (type == "description") {
if (textEditingController.text.isEmpty) {
return AppText.pleaseEnteraDescription;
}
return null;
2024-05-28 16:35:33 +05:30
} else {
return null;
}
},
2024-06-06 18:40:58 +05:30
inputFormatters: [
LengthLimitingTextInputFormatter(350),
],
maxlines: type == "description" ? 6 : 1,
2024-05-28 16:35:33 +05:30
texttype: type == "phone number"
? TextInputType.phone
2024-06-20 16:03:44 +05:30
: type == "Email"
? TextInputType.emailAddress
: TextInputType.name,
2024-05-28 16:35:33 +05:30
textEditingController: textEditingController,
readonly: type == "country selection" ? true : false,
hintText: hintText,
2024-05-29 13:21:55 +05:30
leadingIcon: prefixWidget,
2024-05-28 16:35:33 +05:30
suffixIcon: type == "country selection"
? const Icon(
Icons.arrow_forward_ios_rounded,
color: Color(0xFFB4B4B4),
)
2024-05-29 13:21:55 +05:30
: const SizedBox(),
onTap: () {
if (type == "country selection") {
goRouter.pushNamed(RouteName.chooseCountryScreen);
}
})
2024-05-28 16:35:33 +05:30
],
);
}
}