import 'package:cs_resources/constants/color_constants.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart'; import '../my_text_field.dart'; /** * 基于 MyTextField 实现圆角背景的文本框表单。 * * 主要用于注册,忘记密码等页面。 */ class CustomTextField extends StatelessWidget { final String formKey; final double marginTop; final double marginLeft; final double marginRight; final double paddingRight; final double paddingLeft; final double paddingTop; final double paddingBottom; final double height; final double fontSize; final TextInputType textInputType; final String? errorText; final TextInputAction textInputAction; final Function onSubmit; final Map formData; List? inputFormatters; bool? enabled; Color? fillBackgroundColor; CustomTextField({ required this.formKey, required this.formData, required this.onSubmit, this.marginTop = 0, this.marginLeft = 15, this.marginRight = 15, this.paddingRight = 15, this.paddingLeft = 15, this.paddingTop = 2.5, this.paddingBottom = 2.5, this.textInputType = TextInputType.text, this.errorText, this.fontSize = 15.0, this.height = 50.0, this.textInputAction = TextInputAction.next, this.inputFormatters, this.enabled, this.fillBackgroundColor = ColorConstants.dividerBar, }); @override Widget build(BuildContext context) { return IgnoreKeyboardDismiss( child: MyTextField( formKey, formData[formKey]!['value'], hintText: formData[formKey]!['hintText'], hintStyle: TextStyle( color: ColorConstants.textGrayAECAE5, fontSize: fontSize, fontWeight: FontWeight.w400, ), controller: formData[formKey]['controller'], focusNode: formData[formKey]['focusNode'], margin: EdgeInsets.only(left: marginLeft, right: marginRight, top: marginTop), showDivider: false, fillBackgroundColor: fillBackgroundColor, fillCornerRadius: 5, padding: EdgeInsets.only(left: paddingLeft, right: paddingRight, top: paddingTop, bottom: paddingBottom), height: height, style: TextStyle( color: ColorConstants.white, fontSize: fontSize, fontWeight: FontWeight.w400, ), inputType: textInputType, textInputAction: textInputAction, enabled: enabled, onSubmit: onSubmit, inputFormatters: inputFormatters, cursorColor: ColorConstants.white, obscureText: formData[formKey] != null ? formData[formKey]['obsecure'] : false, errorText: errorText, showLeftIcon: false, showRightIcon: false, ), ); } }