这是CaiYouHui前端,一个关于flutter的安卓app,前端使用flutter实现

app_text_field.dart 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import 'package:flutter/material.dart';
  2. class AppTextField extends StatelessWidget {
  3. final TextEditingController controller;
  4. final String labelText;
  5. final String? hintText;
  6. final TextInputType keyboardType;
  7. final bool obscureText;
  8. final bool enabled;
  9. final int? maxLines;
  10. final int? maxLength;
  11. final String? Function(String?)? validator;
  12. final void Function(String)? onChanged;
  13. final Widget? suffixIcon;
  14. final Widget? prefixIcon;
  15. final bool showCounter;
  16. const AppTextField({
  17. super.key,
  18. required this.controller,
  19. required this.labelText,
  20. this.hintText,
  21. this.keyboardType = TextInputType.text,
  22. this.obscureText = false,
  23. this.enabled = true,
  24. this.maxLines = 1,
  25. this.maxLength,
  26. this.validator,
  27. this.onChanged,
  28. this.suffixIcon,
  29. this.prefixIcon,
  30. this.showCounter = false,
  31. });
  32. @override
  33. Widget build(BuildContext context) {
  34. return Column(
  35. crossAxisAlignment: CrossAxisAlignment.start,
  36. children: [
  37. Text(
  38. labelText,
  39. style: const TextStyle(
  40. fontSize: 14,
  41. fontWeight: FontWeight.w500,
  42. color: Colors.black87,
  43. ),
  44. ),
  45. const SizedBox(height: 8),
  46. TextFormField(
  47. controller: controller,
  48. keyboardType: keyboardType,
  49. obscureText: obscureText,
  50. enabled: enabled,
  51. maxLines: maxLines,
  52. maxLength: maxLength,
  53. validator: validator,
  54. onChanged: onChanged,
  55. decoration: InputDecoration(
  56. hintText: hintText,
  57. prefixIcon: prefixIcon,
  58. suffixIcon: suffixIcon,
  59. border: OutlineInputBorder(
  60. borderRadius: BorderRadius.circular(10),
  61. borderSide: const BorderSide(color: Colors.grey),
  62. ),
  63. enabledBorder: OutlineInputBorder(
  64. borderRadius: BorderRadius.circular(10),
  65. borderSide: const BorderSide(color: Colors.grey),
  66. ),
  67. focusedBorder: OutlineInputBorder(
  68. borderRadius: BorderRadius.circular(10),
  69. borderSide: BorderSide(color: Theme.of(context).primaryColor),
  70. ),
  71. errorBorder: OutlineInputBorder(
  72. borderRadius: BorderRadius.circular(10),
  73. borderSide: const BorderSide(color: Colors.red),
  74. ),
  75. filled: true,
  76. fillColor: Colors.grey[50],
  77. contentPadding: const EdgeInsets.symmetric(
  78. horizontal: 16,
  79. vertical: 14,
  80. ),
  81. counterText: showCounter ? null : '',
  82. ),
  83. ),
  84. ],
  85. );
  86. }
  87. }