round_my_text_field.dart 2.8 KB

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