round_my_text_field.dart 2.3 KB

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