452 lines
14 KiB
Dart
452 lines
14 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:glassmorphism/glassmorphism.dart';
|
|
|
|
class CustomTextFormField extends StatefulWidget {
|
|
const CustomTextFormField({
|
|
Key? key,
|
|
this.validator,
|
|
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;
|
|
|
|
@override
|
|
State<CustomTextFormField> createState() => _CustomTextFormFieldState();
|
|
}
|
|
|
|
class _CustomTextFormFieldState extends State<CustomTextFormField> {
|
|
late bool obscureText;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
obscureText = widget.isInputPassword;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GlassmorphicContainer(
|
|
width: double.infinity,
|
|
height: 50.h,
|
|
borderRadius: 8,
|
|
blur: 10,
|
|
alignment: Alignment.center,
|
|
border: 0.8,
|
|
linearGradient: LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [
|
|
const Color(0xFFffffff).withOpacity(0.1),
|
|
const Color(0xFFFFFFFF).withOpacity(0.05),
|
|
],
|
|
stops: [
|
|
0.1,
|
|
1,
|
|
]),
|
|
borderGradient: LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [
|
|
const Color(0xff9A0000).withOpacity(0.5),
|
|
const Color(0xFFffffff).withOpacity(0.5),
|
|
],
|
|
),
|
|
child: TextFormField(
|
|
textAlignVertical: TextAlignVertical.center,
|
|
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(
|
|
hintStyle: TextStyle(color: Colors.white),
|
|
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),
|
|
),
|
|
],
|
|
)
|
|
: 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: 20),
|
|
),
|
|
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);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class CustomTextFormField1 extends StatefulWidget {
|
|
const CustomTextFormField1({
|
|
Key? key,
|
|
this.validator,
|
|
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;
|
|
|
|
@override
|
|
State<CustomTextFormField1> createState() => _CustomTextFormField1State();
|
|
}
|
|
|
|
class _CustomTextFormField1State extends State<CustomTextFormField1> {
|
|
late bool obscureText;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
obscureText = widget.isInputPassword;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GlassmorphicContainer(
|
|
width: double.infinity,
|
|
height: 50,
|
|
borderRadius: 8,
|
|
blur: 10,
|
|
alignment: Alignment.bottomCenter,
|
|
border: 0.8,
|
|
linearGradient: LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [
|
|
const Color(0xFFffffff).withOpacity(0.1),
|
|
const Color(0xFFFFFFFF).withOpacity(0.05),
|
|
],
|
|
stops: [
|
|
0.1,
|
|
1,
|
|
]),
|
|
borderGradient: const LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [
|
|
Color(0xff3A3A3A),
|
|
Color(0xFF3A3A3A),
|
|
],
|
|
),
|
|
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,
|
|
|
|
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);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class CustomTextFormField3 extends StatefulWidget {
|
|
const CustomTextFormField3({
|
|
Key? key,
|
|
this.validator,
|
|
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;
|
|
|
|
@override
|
|
State<CustomTextFormField3> createState() => _CustomTextFormField3State();
|
|
}
|
|
|
|
class _CustomTextFormField3State extends State<CustomTextFormField3> {
|
|
late bool obscureText;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
obscureText = widget.isInputPassword;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return 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,
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
borderSide: BorderSide(color: const Color(0xFF3A3A3A), width: 1),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
borderSide: BorderSide(color: const Color(0xFF3A3A3A), width: 1),
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
borderSide: BorderSide(color: const Color(0xFF3A3A3A), width: 1),
|
|
),
|
|
errorBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
borderSide: const BorderSide(color: Colors.red, width: 1),
|
|
),
|
|
focusedErrorBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
borderSide: const BorderSide(color: Colors.red, width: 1),
|
|
),
|
|
|
|
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!,
|
|
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);
|
|
},
|
|
);
|
|
}
|
|
}
|