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.
cloudsolutions-atoms/lib/views/widgets/app_text_form_field.dart

108 lines
3.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:test_sa/views/app_style/sizing.dart';
class ATextFormField extends StatefulWidget {
final Function(String) onSaved;
final 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.onSaved,
this.validator,
this.node,
this.onChange,
this.obscureText,
this.showPassword,
this.hintText,
this.labelText,
this.textInputType = TextInputType.text,
this.initialValue,
this.enable = true,
this.style,
this.textAlign,
this.suffixIcon,
this.prefixIconData,
this.prefixIconSize,
this.controller,
this.textInputAction,
this.onAction})
: 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: EdgeInsets.only(left: 12, right: 12),
decoration: BoxDecoration(
color: Color(0xfff5f5f5),
border: Border.all(
color: 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.bodyText1,
decoration: InputDecoration(
border: InputBorder.none,
suffixIconConstraints: BoxConstraints(minWidth: 0),
disabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
constraints: BoxConstraints(),
errorStyle: 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: Color(0xff2e303a))),
),
);
}
}