You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
120 lines
3.8 KiB
Dart
120 lines
3.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../app_style/sizing.dart';
|
|
|
|
class ATextFormField extends StatefulWidget {
|
|
final Function(String?)? onSaved;
|
|
final String? Function(String?)? validator;
|
|
final Function(String)? onChange;
|
|
final bool? obscureText;
|
|
final VoidCallback? showPassword;
|
|
final String? hintText;
|
|
final String? labelText;
|
|
final TextInputType? textInputType;
|
|
final String? initialValue;
|
|
final TextStyle? style;
|
|
final bool? enable;
|
|
final TextAlign? textAlign;
|
|
final FocusNode? node;
|
|
final Widget? suffixIcon;
|
|
final IconData? prefixIconData;
|
|
final double? prefixIconSize;
|
|
final TextEditingController? controller;
|
|
final TextInputAction? textInputAction;
|
|
final VoidCallback? onAction;
|
|
|
|
const ATextFormField({
|
|
Key? key,
|
|
this.initialValue,
|
|
this.node,
|
|
this.onChange,
|
|
this.showPassword,
|
|
this.hintText,
|
|
this.labelText,
|
|
this.style,
|
|
this.textAlign,
|
|
this.suffixIcon,
|
|
this.prefixIconSize,
|
|
this.textInputAction,
|
|
this.onAction,
|
|
this.obscureText,
|
|
this.textInputType = TextInputType.text,
|
|
this.enable = true,
|
|
this.prefixIconData,
|
|
this.controller,
|
|
this.onSaved,
|
|
this.validator,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
State<ATextFormField> createState() => _ATextFormFieldState();
|
|
}
|
|
|
|
class _ATextFormFieldState extends State<ATextFormField> {
|
|
@override
|
|
void initState() {
|
|
if (widget.controller != null) {
|
|
widget.controller!.text = widget.initialValue ?? '';
|
|
}
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
height: widget.textInputType == TextInputType.multiline ? null : 50,
|
|
padding: const EdgeInsets.only(left: 12, right: 12),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xfff5f5f5),
|
|
border: Border.all(
|
|
color: const Color(0xffefefef),
|
|
),
|
|
borderRadius: BorderRadius.circular(
|
|
AppStyle.borderRadius * AppStyle.getScaleFactor(context),
|
|
),
|
|
),
|
|
child: TextFormField(
|
|
focusNode: widget.node,
|
|
enabled: widget.enable,
|
|
onSaved: widget.onSaved,
|
|
initialValue: widget.controller != null ? null : widget.initialValue,
|
|
validator: widget.validator,
|
|
onChanged: widget.onChange,
|
|
textAlign: TextAlign.left,
|
|
obscureText: widget.obscureText ?? false,
|
|
keyboardType: widget.textInputType,
|
|
maxLines: widget.textInputType == TextInputType.multiline ? null : 1,
|
|
obscuringCharacter: "●",
|
|
controller: widget.controller,
|
|
textInputAction: widget.textInputType == TextInputType.multiline
|
|
? null
|
|
: widget.textInputAction ?? TextInputAction.next,
|
|
onEditingComplete:
|
|
widget.onAction ?? () => FocusScope.of(context).nextFocus(),
|
|
// style: widget.style,
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
decoration: InputDecoration(
|
|
border: InputBorder.none,
|
|
suffixIconConstraints: const BoxConstraints(minWidth: 0),
|
|
disabledBorder: InputBorder.none,
|
|
focusedBorder: InputBorder.none,
|
|
enabledBorder: InputBorder.none,
|
|
constraints: const BoxConstraints(),
|
|
errorStyle: const TextStyle(height: 0.3),
|
|
//contentPadding: EdgeInsets.only(left: 0),
|
|
hintText: widget.hintText,
|
|
labelText: widget.labelText,
|
|
//suffixIcon: widget.suffixIcon,
|
|
suffixIcon: widget.prefixIconData == null
|
|
? null
|
|
: Icon(widget.prefixIconData,
|
|
size: widget.prefixIconSize == null
|
|
? 20 * AppStyle.getScaleFactor(context)
|
|
: (widget.prefixIconSize! - 10) *
|
|
AppStyle.getScaleFactor(context),
|
|
color: const Color(0xff2e303a))),
|
|
),
|
|
);
|
|
}
|
|
}
|