714 lines
23 KiB
Dart
714 lines
23 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:flutter_svg/flutter_svg.dart';
|
|
|
|
import 'package:glassmorphism/glassmorphism.dart';
|
|
import 'package:regroup/Utils/Common/sized_box.dart';
|
|
import 'package:remove_emoji_input_formatter/remove_emoji_input_formatter.dart';
|
|
|
|
class CustomTextFormField extends StatefulWidget {
|
|
CustomTextFormField({
|
|
Key? key,
|
|
this.validator,
|
|
this.validationMessage,
|
|
this.textEditingController,
|
|
this.hintText,
|
|
this.leadingIcon,
|
|
this.prefixIconColor = const Color(0xFF737373),
|
|
this.isInputPassword = false,
|
|
this.value,
|
|
this.readonly = false,
|
|
this.enabled = true,
|
|
this.outlineColor = Colors.black,
|
|
this.maxlines = 1,
|
|
this.texttype,
|
|
this.inputFormatters,
|
|
this.onInput,
|
|
this.onTap,
|
|
this.suffixIcon,
|
|
this.opacity1 = 0.04,
|
|
this.opacity2 = 0.05,
|
|
}) : super(key: key);
|
|
|
|
final String? Function(String?)? validator;
|
|
final TextEditingController? textEditingController;
|
|
final String? hintText;
|
|
final Widget? leadingIcon;
|
|
final Color prefixIconColor;
|
|
final bool isInputPassword;
|
|
final String? value;
|
|
final bool readonly;
|
|
final bool enabled;
|
|
final int maxlines;
|
|
final TextInputType? texttype;
|
|
final List<TextInputFormatter>? inputFormatters;
|
|
final Color outlineColor;
|
|
final Function(String)? onInput;
|
|
final VoidCallback? onTap;
|
|
final Widget? suffixIcon;
|
|
final double opacity1;
|
|
final double opacity2;
|
|
|
|
String? validationMessage;
|
|
|
|
@override
|
|
State<CustomTextFormField> createState() => _CustomTextFormFieldState();
|
|
}
|
|
|
|
class _CustomTextFormFieldState extends State<CustomTextFormField> {
|
|
late bool obscureText;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
obscureText = widget.isInputPassword;
|
|
}
|
|
|
|
void validateField(String value) {
|
|
setState(() {
|
|
widget.validationMessage =
|
|
widget.validator?.call(value) ?? (value.isEmpty ? "" : null);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
GlassmorphicContainer(
|
|
width: double.infinity,
|
|
height: 50,
|
|
borderRadius: 30,
|
|
blur: 10,
|
|
alignment: Alignment.bottomCenter,
|
|
border: 0.8,
|
|
linearGradient: LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [
|
|
const Color(0xFFffffff).withOpacity(widget.opacity1),
|
|
const Color(0xFFFFFFFF).withOpacity(widget.opacity2),
|
|
],
|
|
stops: [
|
|
0.1,
|
|
1,
|
|
]),
|
|
borderGradient: const LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [
|
|
Color(0xff434A53),
|
|
Color(0xFF434A53),
|
|
],
|
|
),
|
|
child: TextFormField(
|
|
style: TextStyle(
|
|
fontSize: 16.sp, color: Colors.white, fontFamily: 'Helvetica'),
|
|
cursorColor: Colors.red,
|
|
initialValue: widget.value,
|
|
readOnly: widget.readonly,
|
|
onTap: widget.onTap,
|
|
enabled: widget.enabled,
|
|
enableInteractiveSelection: false,
|
|
maxLines: widget.maxlines,
|
|
obscureText: obscureText,
|
|
controller: widget.textEditingController,
|
|
decoration: InputDecoration(
|
|
hintText: widget.hintText,
|
|
prefixIconColor: widget.prefixIconColor,
|
|
constraints: BoxConstraints(minHeight: 50),
|
|
hintStyle: TextStyle(
|
|
fontSize: 16.sp,
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.w400,
|
|
fontFamily: 'Helvetica'),
|
|
prefixIcon: widget.leadingIcon == null
|
|
? null
|
|
: Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 10),
|
|
child: widget.leadingIcon!,
|
|
),
|
|
suffixIcon: widget.isInputPassword
|
|
? GestureDetector(
|
|
onTap: () => setState(() => obscureText = !obscureText),
|
|
child: obscureText
|
|
? Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.only(right: 20.0),
|
|
child: SvgPicture.asset(
|
|
"assets/images/svg/loginpasswordclose.svg",
|
|
),
|
|
),
|
|
],
|
|
)
|
|
: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.only(right: 20.0),
|
|
child: SvgPicture.asset(
|
|
'assets/images/svg/loginpasswordopen.svg',
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: widget.suffixIcon == null
|
|
? null
|
|
: widget.suffixIcon!,
|
|
border: InputBorder.none,
|
|
contentPadding:
|
|
const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
|
),
|
|
keyboardType: widget.texttype,
|
|
inputFormatters: widget.inputFormatters,
|
|
onChanged: (value) {
|
|
widget.onInput?.call(value);
|
|
validateField(value);
|
|
},
|
|
),
|
|
),
|
|
sizedBoxHeight(5.h),
|
|
widget.validationMessage == null
|
|
? SizedBox()
|
|
: Text(
|
|
widget.validationMessage ?? '',
|
|
style: TextStyle(color: Colors.red, fontSize: 12.sp),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class CustomTextFormField2 extends StatefulWidget {
|
|
CustomTextFormField2({
|
|
Key? key,
|
|
this.validator,
|
|
this.validationMessage,
|
|
this.textEditingController,
|
|
this.hintText,
|
|
this.leadingIcon,
|
|
this.prefixIconColor = const Color(0xFF737373),
|
|
this.isInputPassword = false,
|
|
this.validatorText,
|
|
this.value,
|
|
this.readonly = false,
|
|
this.enabled = true,
|
|
this.maxlines = 1,
|
|
this.texttype,
|
|
this.inputFormatters,
|
|
this.onInput,
|
|
this.onTap,
|
|
this.suffixIcon,
|
|
}) : super(key: key);
|
|
|
|
final dynamic validator;
|
|
final TextEditingController? textEditingController;
|
|
final String? hintText;
|
|
final Widget? leadingIcon;
|
|
final Color prefixIconColor;
|
|
final bool isInputPassword;
|
|
final String? validatorText;
|
|
final String? value;
|
|
final bool readonly;
|
|
final bool enabled;
|
|
final int maxlines;
|
|
final TextInputType? texttype;
|
|
final dynamic inputFormatters;
|
|
final Function(String)? onInput;
|
|
final VoidCallback? onTap;
|
|
final Widget? suffixIcon;
|
|
String? validationMessage;
|
|
|
|
@override
|
|
State<CustomTextFormField2> createState() => _CustomTextFormField2State();
|
|
}
|
|
|
|
class _CustomTextFormField2State extends State<CustomTextFormField2> {
|
|
late bool obscureText;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
obscureText = widget.isInputPassword;
|
|
}
|
|
|
|
void validateField(String value) {
|
|
setState(() {
|
|
widget.validationMessage = widget.validator?.call(value) ??
|
|
(value.isEmpty ? "Empty value" : null);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
GlassmorphicContainer(
|
|
width: double.infinity,
|
|
height: 100.h,
|
|
borderRadius: 10,
|
|
blur: 10,
|
|
alignment: Alignment.bottomCenter,
|
|
border: 0.8,
|
|
linearGradient: LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [
|
|
const Color(0xFFffffff).withOpacity(0.04),
|
|
const Color(0xFFFFFFFF).withOpacity(0.05),
|
|
],
|
|
stops: [
|
|
0.1,
|
|
1,
|
|
]),
|
|
borderGradient: const LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [
|
|
Color(0xff434A53),
|
|
Color(0xFF434A53),
|
|
],
|
|
),
|
|
child: TextFormField(
|
|
cursorColor: Colors.red,
|
|
initialValue: widget.value,
|
|
readOnly: widget.readonly,
|
|
onTap: widget.onTap,
|
|
enabled: widget.enabled,
|
|
enableInteractiveSelection: false,
|
|
maxLines: widget.maxlines,
|
|
autovalidateMode: AutovalidateMode.onUserInteraction,
|
|
obscureText: obscureText,
|
|
controller: widget.textEditingController,
|
|
|
|
decoration: InputDecoration(
|
|
hintText: widget.hintText,
|
|
prefixIconColor: widget.prefixIconColor,
|
|
constraints: BoxConstraints(minHeight: 50),
|
|
|
|
hintStyle: TextStyle(
|
|
fontSize: 16.sp,
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.w400,
|
|
fontFamily: 'hiragino'),
|
|
|
|
// 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),
|
|
),
|
|
],
|
|
)
|
|
: const Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.only(right: 20.0),
|
|
child: Icon(
|
|
Icons.remove_red_eye_outlined,
|
|
color: Color(0xFF959595),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: widget.suffixIcon == null
|
|
? null
|
|
: widget.suffixIcon!,
|
|
border: InputBorder.none,
|
|
contentPadding:
|
|
const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
|
|
),
|
|
style: const TextStyle(color: Colors.white),
|
|
keyboardType: widget.texttype,
|
|
// validator: widget.validator ??
|
|
// (value) {
|
|
// if (value == null || value.isEmpty) {
|
|
// return "Empty value";
|
|
// }
|
|
// return null;
|
|
// },
|
|
inputFormatters: widget.inputFormatters,
|
|
onChanged: (value) {
|
|
widget.onInput?.call(value);
|
|
},
|
|
),
|
|
),
|
|
sizedBoxHeight(5.h),
|
|
Text(
|
|
widget.validationMessage ?? '',
|
|
style: TextStyle(color: Colors.red, fontSize: 12.sp),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class CustomTextFormFieldPassword extends StatefulWidget {
|
|
CustomTextFormFieldPassword({
|
|
Key? key,
|
|
this.validator,
|
|
this.validationMessage,
|
|
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.prefixIconColor = Colors.white,
|
|
this.texttype,
|
|
this.onInput,
|
|
this.onTap,
|
|
this.maxlines = 1,
|
|
}) : super(key: key);
|
|
|
|
final String? Function(String?)? 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 List<TextInputFormatter>? inputFormatters;
|
|
final Color outlineColor;
|
|
final Color prefixIconColor;
|
|
final TextInputType? texttype;
|
|
final Function(String)? onInput;
|
|
final VoidCallback? onTap;
|
|
final int maxlines;
|
|
String? validationMessage;
|
|
|
|
@override
|
|
State<CustomTextFormFieldPassword> createState() =>
|
|
_CustomtextFormFieldPasswordState();
|
|
}
|
|
|
|
class _CustomtextFormFieldPasswordState
|
|
extends State<CustomTextFormFieldPassword> {
|
|
late bool obscureText;
|
|
var emojiFormatter = RemoveEmojiInputFormatter();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
obscureText = widget.isInputPassword;
|
|
}
|
|
|
|
void validateField(String value) {
|
|
setState(() {
|
|
widget.validationMessage = widget.validator?.call(value) ??
|
|
(value.isEmpty ? "Empty value" : null);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
List<TextInputFormatter> allFormatters = [emojiFormatter];
|
|
if (widget.inputFormatters != null) {
|
|
allFormatters.addAll(widget.inputFormatters!);
|
|
}
|
|
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
GlassmorphicContainer(
|
|
width: double.infinity,
|
|
height: 50,
|
|
borderRadius: 30,
|
|
blur: 10,
|
|
alignment: Alignment.bottomCenter,
|
|
border: 0.8,
|
|
linearGradient: LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [
|
|
const Color(0xFFffffff).withOpacity(0.04),
|
|
const Color(0xFFFFFFFF).withOpacity(0.05),
|
|
],
|
|
stops: [0.1, 1],
|
|
),
|
|
borderGradient: const LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [
|
|
Color(0xff434A53),
|
|
Color(0xFF434A53),
|
|
],
|
|
),
|
|
child: TextFormField(
|
|
textCapitalization: widget.textCapital
|
|
? TextCapitalization.characters
|
|
: TextCapitalization.none,
|
|
onTap: widget.onTap,
|
|
style: TextStyle(
|
|
fontSize: 16.sp, color: Colors.white, fontFamily: 'Helvetica'),
|
|
initialValue: widget.value,
|
|
readOnly: widget.readonly,
|
|
enabled: widget.enabled,
|
|
maxLines: widget.maxlines,
|
|
cursorColor: Colors.white,
|
|
obscureText: obscureText,
|
|
controller: widget.textEditingController,
|
|
decoration: InputDecoration(
|
|
hintStyle: TextStyle(
|
|
fontSize: 16.sp,
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.w400,
|
|
fontFamily: 'Helvetica'),
|
|
labelStyle: const TextStyle(color: Colors.white),
|
|
errorStyle: TextStyle(
|
|
fontSize: 13.sp,
|
|
color: Color.fromARGB(255, 245, 130, 122),
|
|
),
|
|
contentPadding: EdgeInsets.symmetric(vertical: 10, horizontal: 0),
|
|
filled: true,
|
|
fillColor:
|
|
Colors.transparent, // Make sure fillColor is transparent
|
|
border: InputBorder.none,
|
|
hintText: widget.hintText,
|
|
prefixIconColor: widget.prefixIconColor,
|
|
prefixIcon:
|
|
widget.leadingIcon == null ? null : widget.leadingIcon!,
|
|
suffixIcon: widget.isInputPassword
|
|
? GestureDetector(
|
|
onTap: () => setState(() => obscureText = !obscureText),
|
|
child: obscureText
|
|
? Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.only(right: 20.0),
|
|
child: SvgPicture.asset(
|
|
"assets/images/svg/loginpasswordclose.svg",
|
|
),
|
|
),
|
|
],
|
|
)
|
|
: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.only(right: 20.0),
|
|
child: SvgPicture.asset(
|
|
'assets/images/svg/loginpasswordopen.svg',
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: null,
|
|
),
|
|
keyboardType: widget.texttype,
|
|
inputFormatters: allFormatters,
|
|
onChanged: (value) {
|
|
widget.onInput?.call(value);
|
|
validateField(value);
|
|
},
|
|
validator: widget.validator,
|
|
),
|
|
),
|
|
sizedBoxHeight(5.h),
|
|
Text(
|
|
widget.validationMessage ?? '',
|
|
style: TextStyle(color: Colors.red, fontSize: 12.sp),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class SearchTextFormField extends StatefulWidget {
|
|
SearchTextFormField({
|
|
Key? key,
|
|
this.validator,
|
|
this.validationMessage,
|
|
this.textEditingController,
|
|
this.hintText,
|
|
this.leadingIcon,
|
|
this.prefixIconColor = const Color(0xFF737373),
|
|
this.isInputPassword = false,
|
|
this.value,
|
|
this.readonly = false,
|
|
this.enabled = true,
|
|
this.outlineColor = Colors.black,
|
|
this.maxlines = 1,
|
|
this.texttype,
|
|
this.inputFormatters,
|
|
this.onInput,
|
|
this.onTap,
|
|
this.suffixIcon,
|
|
}) : super(key: key);
|
|
|
|
final String? Function(String?)? validator;
|
|
final TextEditingController? textEditingController;
|
|
final String? hintText;
|
|
final Widget? leadingIcon;
|
|
final Color prefixIconColor;
|
|
final bool isInputPassword;
|
|
final String? value;
|
|
final bool readonly;
|
|
final bool enabled;
|
|
final int maxlines;
|
|
final TextInputType? texttype;
|
|
final List<TextInputFormatter>? inputFormatters;
|
|
final Color outlineColor;
|
|
final Function(String)? onInput;
|
|
final VoidCallback? onTap;
|
|
final Widget? suffixIcon;
|
|
String? validationMessage;
|
|
|
|
@override
|
|
State<SearchTextFormField> createState() => _SearchTextFormFieldState();
|
|
}
|
|
|
|
class _SearchTextFormFieldState extends State<SearchTextFormField> {
|
|
late bool obscureText;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
obscureText = widget.isInputPassword;
|
|
}
|
|
|
|
void validateField(String value) {
|
|
setState(() {
|
|
widget.validationMessage =
|
|
widget.validator?.call(value) ?? (value.isEmpty ? "" : null);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
GlassmorphicContainer(
|
|
width: double.infinity,
|
|
height: 50,
|
|
borderRadius: 10,
|
|
blur: 10,
|
|
alignment: Alignment.bottomCenter,
|
|
border: 0.8,
|
|
linearGradient: LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [
|
|
const Color(0xFFffffff).withOpacity(0.04),
|
|
const Color(0xFFFFFFFF).withOpacity(0.05),
|
|
],
|
|
stops: [
|
|
0.1,
|
|
1,
|
|
]),
|
|
borderGradient: const LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [
|
|
Color(0xff434A53),
|
|
Color(0xFF434A53),
|
|
],
|
|
),
|
|
child: TextFormField(
|
|
style: TextStyle(
|
|
fontSize: 16.sp, color: Colors.white, fontFamily: 'Helvetica'),
|
|
cursorColor: Colors.red,
|
|
initialValue: widget.value,
|
|
readOnly: widget.readonly,
|
|
onTap: widget.onTap,
|
|
enabled: widget.enabled,
|
|
enableInteractiveSelection: false,
|
|
maxLines: widget.maxlines,
|
|
obscureText: obscureText,
|
|
controller: widget.textEditingController,
|
|
decoration: InputDecoration(
|
|
hintText: widget.hintText,
|
|
prefixIconColor: widget.prefixIconColor,
|
|
constraints: BoxConstraints(minHeight: 50),
|
|
hintStyle: TextStyle(
|
|
fontSize: 16.sp,
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.w400,
|
|
fontFamily: 'Helvetica'),
|
|
prefixIcon:
|
|
widget.leadingIcon == null ? null : widget.leadingIcon!,
|
|
suffixIcon: widget.isInputPassword
|
|
? GestureDetector(
|
|
onTap: () => setState(() => obscureText = !obscureText),
|
|
child: obscureText
|
|
? Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.only(right: 20.0),
|
|
child: SvgPicture.asset(
|
|
"assets/images/svg/loginpasswordclose.svg",
|
|
),
|
|
),
|
|
],
|
|
)
|
|
: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.only(right: 20.0),
|
|
child: SvgPicture.asset(
|
|
'assets/images/svg/loginpasswordopen.svg',
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: widget.suffixIcon == null
|
|
? null
|
|
: widget.suffixIcon!,
|
|
border: InputBorder.none,
|
|
contentPadding:
|
|
const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
|
|
),
|
|
keyboardType: widget.texttype,
|
|
inputFormatters: widget.inputFormatters,
|
|
onChanged: (value) {
|
|
widget.onInput?.call(value);
|
|
validateField(value);
|
|
},
|
|
),
|
|
),
|
|
sizedBoxHeight(5.h),
|
|
Text(
|
|
widget.validationMessage ?? '',
|
|
style: TextStyle(color: Colors.red, fontSize: 12.sp),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|