171 lines
5.6 KiB
Dart
171 lines
5.6 KiB
Dart
// ignore_for_file: must_be_immutable
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:remove_emoji_input_formatter/remove_emoji_input_formatter.dart';
|
|
|
|
class CustomTextFormField extends StatefulWidget {
|
|
CustomTextFormField({
|
|
Key? key,
|
|
this.validator,
|
|
this.inputFormatters,
|
|
this.hintText,
|
|
this.validatorText,
|
|
this.value,
|
|
this.textEditingController,
|
|
this.leadingIcon,
|
|
this.readonly = false,
|
|
this.enabled = true,
|
|
this.textCapital = false,
|
|
this.isInputPassword = false,
|
|
this.outlineColor = Colors.black,
|
|
this.bgColor = const Color(0xFFFFF3E4),
|
|
this.prefixIconColor = const Color(0xFF737373),
|
|
this.texttype,
|
|
this.onInput,
|
|
this.onTap,
|
|
this.maxlines = 1,
|
|
}) : super(key: key);
|
|
|
|
dynamic validator;
|
|
final TextEditingController? textEditingController;
|
|
final String? hintText;
|
|
final String? validatorText;
|
|
final String? value;
|
|
final Widget? leadingIcon;
|
|
final bool isInputPassword;
|
|
final bool readonly;
|
|
final bool enabled;
|
|
final bool textCapital;
|
|
final dynamic inputFormatters;
|
|
final Color outlineColor;
|
|
final Color bgColor;
|
|
final Color prefixIconColor;
|
|
final TextInputType? texttype;
|
|
Function(String)? onInput;
|
|
final VoidCallback? onTap;
|
|
final int maxlines;
|
|
|
|
@override
|
|
State<CustomTextFormField> createState() => _CustomtextFormFieldState();
|
|
}
|
|
|
|
class _CustomtextFormFieldState extends State<CustomTextFormField> {
|
|
late bool obscureText;
|
|
var emojiFormatter = RemoveEmojiInputFormatter();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
obscureText = widget.isInputPassword;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
List<TextInputFormatter> allFormatters = [emojiFormatter];
|
|
if (widget.inputFormatters != null) {
|
|
allFormatters.addAll(widget.inputFormatters);
|
|
}
|
|
return TextFormField(
|
|
textCapitalization: widget.textCapital
|
|
? TextCapitalization.characters
|
|
: TextCapitalization.none,
|
|
onTap: widget.onTap,
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
),
|
|
initialValue: widget.value,
|
|
readOnly: widget.readonly,
|
|
enabled: widget.enabled,
|
|
//enableInteractiveSelection: false,
|
|
maxLines: widget.maxlines,
|
|
cursorColor: Colors.black,
|
|
autovalidateMode: AutovalidateMode.onUserInteraction,
|
|
obscureText: obscureText,
|
|
controller: widget.textEditingController,
|
|
decoration: InputDecoration(
|
|
labelStyle: const TextStyle(color: Colors.black),
|
|
errorStyle: TextStyle(
|
|
fontSize: 13.sp,
|
|
color: Color.fromARGB(255, 245, 130, 122),
|
|
),
|
|
contentPadding: EdgeInsets.symmetric(vertical: 10, horizontal: 20),
|
|
filled: true,
|
|
fillColor: widget.bgColor,
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(5),
|
|
borderSide: const BorderSide(color: Color(0xFFE8C69F80), width: 1),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(5),
|
|
borderSide: const BorderSide(color: Color(0xFFE8C69F80), width: 1),
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(5),
|
|
borderSide: const BorderSide(color: Color(0xFFE8C69F80), width: 1),
|
|
),
|
|
errorBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(5),
|
|
borderSide: const BorderSide(color: Colors.red, width: 1),
|
|
),
|
|
focusedErrorBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(5),
|
|
borderSide: const BorderSide(color: Colors.red, width: 1),
|
|
),
|
|
hintStyle: const TextStyle(
|
|
color: Color(0xFF737373),
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w400,
|
|
fontFamily: "DM Sans"),
|
|
hintText: widget.hintText,
|
|
prefixIconColor: widget.prefixIconColor,
|
|
// ignore: prefer_null_aware_operators
|
|
prefixIcon: widget.leadingIcon == null ? null : widget.leadingIcon!,
|
|
suffixIcon: widget.isInputPassword
|
|
? GestureDetector(
|
|
onTap: () => setState(() => obscureText = !obscureText),
|
|
child: obscureText
|
|
? const Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.only(right: 20.0),
|
|
child: Icon(
|
|
Icons.remove_red_eye,
|
|
color: Color(0xFF959595),
|
|
),
|
|
),
|
|
],
|
|
)
|
|
: const Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.only(right: 20.0),
|
|
child: Icon(
|
|
Icons.remove_red_eye_outlined,
|
|
color: Color(0xFF959595),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: null,
|
|
),
|
|
keyboardType: widget.texttype,
|
|
validator: widget.validator ??
|
|
(value) {
|
|
if (value == null || value.isEmpty) {
|
|
return "Empty value";
|
|
}
|
|
return null;
|
|
},
|
|
inputFormatters: allFormatters,
|
|
onChanged: (value) {
|
|
widget.onInput?.call(value);
|
|
},
|
|
);
|
|
}
|
|
}
|