round_my_text_field.dart 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. CustomTextField({
  32. required this.formKey,
  33. required this.formData,
  34. required this.onSubmit,
  35. this.marginTop = 0,
  36. this.marginLeft = 15,
  37. this.marginRight = 15,
  38. this.paddingRight = 15,
  39. this.paddingLeft = 15,
  40. this.paddingTop = 2.5,
  41. this.paddingBottom = 2.5,
  42. this.textInputType = TextInputType.text,
  43. this.errorText,
  44. this.fontSize = 15.0,
  45. this.height = 50.0,
  46. this.cornerRadius = 5.0,
  47. this.textInputAction = TextInputAction.next,
  48. this.inputFormatters,
  49. this.enabled,
  50. this.fillBackgroundColor = ColorConstants.dividerBar,
  51. });
  52. @override
  53. Widget build(BuildContext context) {
  54. return IgnoreKeyboardDismiss(
  55. child: MyTextField(
  56. formKey,
  57. formData[formKey]!['value'],
  58. hintText: formData[formKey]!['hintText'],
  59. hintStyle: TextStyle(
  60. color: ColorConstants.textGrayAECAE5,
  61. fontSize: fontSize,
  62. fontWeight: FontWeight.w400,
  63. ),
  64. controller: formData[formKey]['controller'],
  65. focusNode: formData[formKey]['focusNode'],
  66. margin: EdgeInsets.only(left: marginLeft, right: marginRight, top: marginTop),
  67. showDivider: false,
  68. fillBackgroundColor: fillBackgroundColor,
  69. fillCornerRadius: cornerRadius,
  70. padding: EdgeInsets.only(left: paddingLeft, right: paddingRight, top: paddingTop, bottom: paddingBottom),
  71. height: height,
  72. style: TextStyle(
  73. color: ColorConstants.white,
  74. fontSize: fontSize,
  75. fontWeight: FontWeight.w400,
  76. ),
  77. inputType: textInputType,
  78. textInputAction: textInputAction,
  79. enabled: enabled,
  80. onSubmit: onSubmit,
  81. inputFormatters: inputFormatters,
  82. cursorColor: ColorConstants.white,
  83. obscureText: formData[formKey] != null ? formData[formKey]['obsecure'] : false,
  84. errorText: errorText,
  85. showLeftIcon: false,
  86. showRightIcon: false,
  87. ),
  88. );
  89. }
  90. }