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.
115 lines
3.4 KiB
Dart
115 lines
3.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:test_sa/views/app_style/colors.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(
|
|
padding: EdgeInsets.symmetric(
|
|
horizontal: 16
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
border: Border.all(color:AColors.black),
|
|
borderRadius: BorderRadius.circular(
|
|
AppStyle.borderRadius * AppStyle.getScaleFactor(context)
|
|
),
|
|
boxShadow: [
|
|
AppStyle.boxShadow
|
|
]
|
|
),
|
|
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: widget.textAlign ?? TextAlign.center,
|
|
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,
|
|
decoration: InputDecoration(
|
|
border: InputBorder.none,
|
|
disabledBorder: InputBorder.none,
|
|
focusedBorder: InputBorder.none,
|
|
enabledBorder: InputBorder.none,
|
|
|
|
hintText: widget.hintText,
|
|
labelText: widget.labelText,
|
|
suffixIcon: widget.suffixIcon,
|
|
prefixIcon: widget.prefixIconData == null ? null : Icon(
|
|
widget.prefixIconData,
|
|
size: widget.prefixIconSize == null
|
|
? 32 * AppStyle.getScaleFactor(context)
|
|
: (widget.prefixIconSize - 10) * AppStyle.getScaleFactor(context),
|
|
color: AColors.black,
|
|
)
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|