round_my_text_field.dart 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import 'package:cs_resources/constants/color_constants.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
  5. import '../my_text_field.dart';
  6. /**
  7. * 基于 MyTextField 实现圆角背景的文本框表单。
  8. *
  9. * 主要用于注册,忘记密码等页面。
  10. */
  11. class CustomTextField extends StatelessWidget {
  12. final String formKey;
  13. final double marginTop;
  14. final double marginLeft;
  15. final double marginRight;
  16. final double paddingRight;
  17. final double paddingLeft;
  18. final double paddingTop;
  19. final double paddingBottom;
  20. final double height;
  21. final double fontSize;
  22. final double cornerRadius;
  23. final TextInputType textInputType;
  24. final String? errorText;
  25. final TextInputAction textInputAction;
  26. final Function onSubmit;
  27. final Map<String, dynamic> formData;
  28. List<TextInputFormatter>? inputFormatters;
  29. bool? enabled;
  30. Color? fillBackgroundColor;
  31. Color? textColor;
  32. CustomTextField({
  33. required this.formKey,
  34. required this.formData,
  35. required this.onSubmit,
  36. this.marginTop = 0,
  37. this.marginLeft = 15,
  38. this.marginRight = 15,
  39. this.paddingRight = 15,
  40. this.paddingLeft = 15,
  41. this.paddingTop = 2.5,
  42. this.paddingBottom = 2.5,
  43. this.textInputType = TextInputType.text,
  44. this.errorText,
  45. this.fontSize = 15.0,
  46. this.height = 50.0,
  47. this.cornerRadius = 5.0,
  48. this.textInputAction = TextInputAction.next,
  49. this.inputFormatters,
  50. this.enabled,
  51. this.fillBackgroundColor = ColorConstants.dividerBar,
  52. this.textColor = ColorConstants.white,
  53. });
  54. @override
  55. Widget build(BuildContext context) {
  56. return IgnoreKeyboardDismiss(
  57. child: MyTextField(
  58. formKey,
  59. formData[formKey]!['value'],
  60. hintText: formData[formKey]!['hintText'],
  61. hintStyle: TextStyle(
  62. color: ColorConstants.textGrayAECAE5,
  63. fontSize: fontSize,
  64. fontWeight: FontWeight.w400,
  65. ),
  66. controller: formData[formKey]['controller'],
  67. focusNode: formData[formKey]['focusNode'],
  68. margin: EdgeInsets.only(left: marginLeft, right: marginRight, top: marginTop),
  69. showDivider: false,
  70. fillBackgroundColor: fillBackgroundColor,
  71. fillCornerRadius: cornerRadius,
  72. padding: EdgeInsets.only(left: paddingLeft, right: paddingRight, top: paddingTop, bottom: paddingBottom),
  73. height: height,
  74. style: TextStyle(
  75. color: textColor,
  76. fontSize: fontSize,
  77. fontWeight: FontWeight.w400,
  78. ),
  79. inputType: textInputType,
  80. textInputAction: textInputAction,
  81. enabled: enabled,
  82. onSubmit: onSubmit,
  83. inputFormatters: inputFormatters,
  84. cursorColor: ColorConstants.white,
  85. obscureText: formData[formKey] != null ? formData[formKey]['obsecure'] : false,
  86. errorText: errorText,
  87. showLeftIcon: false,
  88. showRightIcon: false,
  89. ),
  90. );
  91. }
  92. }