325 lines
9.7 KiB
Dart
325 lines
9.7 KiB
Dart
// ignore_for_file: must_be_immutable
|
|
|
|
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.textCapital = false,
|
|
this.outlineColor = Colors.black,
|
|
// this.bgColor = const Color(0xFFFFF3E4),
|
|
// this.prefixIconColor = Colors.white,
|
|
|
|
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 Color outlineColor;
|
|
// final Color bgColor;
|
|
|
|
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,
|
|
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(
|
|
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 CustomTextFormField2 extends StatefulWidget {
|
|
const CustomTextFormField2({
|
|
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<CustomTextFormField2> createState() => _CustomTextFormField2State();
|
|
}
|
|
|
|
class _CustomTextFormField2State extends State<CustomTextFormField2> {
|
|
late bool obscureText;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
obscureText = widget.isInputPassword;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return 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,
|
|
|
|
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);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|