智慧水务管理系统 - 精河县供水工程综合管理平台

custom_text_field.dart 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import 'package:flutter/material.dart';
  2. import 'package:water_management_system/utils/constants.dart';
  3. class CustomTextField extends StatelessWidget {
  4. final TextEditingController controller;
  5. final String labelText;
  6. final String? hintText;
  7. final IconData? prefixIcon;
  8. final Widget? suffixIcon;
  9. final bool obscureText;
  10. final String? Function(String?)? validator;
  11. final void(String)? onChanged;
  12. final void(String)? onSubmitted;
  13. final TextInputType? keyboardType;
  14. final int? maxLength;
  15. final int? maxLines;
  16. final bool enabled;
  17. final FocusNode? focusNode;
  18. const CustomTextField({
  19. super.key,
  20. required this.controller,
  21. required this.labelText,
  22. this.hintText,
  23. this.prefixIcon,
  24. this.suffixIcon,
  25. this.obscureText = false,
  26. this.validator,
  27. this.onChanged,
  28. this.onSubmitted,
  29. this.keyboardType,
  30. this.maxLength,
  31. this.maxLines = 1,
  32. this.enabled = true,
  33. this.focusNode,
  34. });
  35. @override
  36. Widget build(BuildContext context) {
  37. return TextFormField(
  38. controller: controller,
  39. decoration: InputDecoration(
  40. labelText: labelText,
  41. hintText: hintText,
  42. prefixIcon: prefixIcon != null
  43. ? Icon(
  44. prefixIcon,
  45. color: Colors.grey[600],
  46. )
  47. : null,
  48. suffixIcon: suffixIcon,
  49. border: OutlineInputBorder(
  50. borderRadius: BorderRadius.circular(8),
  51. ),
  52. enabledBorder: OutlineInputBorder(
  53. borderRadius: BorderRadius.circular(8),
  54. borderSide: BorderSide(
  55. color: Colors.grey[300]!,
  56. ),
  57. ),
  58. focusedBorder: OutlineInputBorder(
  59. borderRadius: BorderRadius.circular(8),
  60. borderSide: const BorderSide(
  61. color: AppConstants.primaryColor,
  62. width: 2,
  63. ),
  64. ),
  65. errorBorder: OutlineInputBorder(
  66. borderRadius: BorderRadius.circular(8),
  67. borderSide: const BorderSide(
  68. color: AppConstants.errorColor,
  69. width: 1,
  70. ),
  71. ),
  72. focusedErrorBorder: OutlineInputBorder(
  73. borderRadius: BorderRadius.circular(8),
  74. borderSide: const BorderSide(
  75. color: AppConstants.errorColor,
  76. width: 2,
  77. ),
  78. ),
  79. filled: true,
  80. fillColor: enabled ? Colors.white : Colors.grey[100],
  81. contentPadding: const EdgeInsets.symmetric(
  82. horizontal: 16,
  83. vertical: 12,
  84. ),
  85. ),
  86. obscureText: obscureText,
  87. validator: validator,
  88. onChanged: onChanged,
  89. onFieldSubmitted: onSubmitted,
  90. keyboardType: keyboardType,
  91. maxLength: maxLength,
  92. maxLines: maxLines,
  93. enabled: enabled,
  94. focusNode: focusNode,
  95. style: TextStyle(
  96. color: enabled ? Colors.black87 : Colors.grey[500],
  97. ),
  98. );
  99. }
  100. }