input.dart 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import 'package:flutter/material.dart';
  2. class VInput extends StatelessWidget {
  3. final String? placeholder;
  4. final String? initialValue;
  5. final TextEditingController? controller;
  6. final FocusNode? focusNode;
  7. final ValueChanged<String>? onChanged;
  8. final VoidCallback? onTap;
  9. final bool? readOnly;
  10. final double? radius;
  11. final Widget? suffixIcon;
  12. final int? maxLines;
  13. const VInput({
  14. super.key,
  15. this.initialValue,
  16. this.controller,
  17. this.focusNode,
  18. this.placeholder,
  19. this.onChanged,
  20. this.onTap,
  21. this.readOnly = false,
  22. this.radius,
  23. this.suffixIcon,
  24. this.maxLines = 1,
  25. });
  26. @override
  27. Widget build(BuildContext context) {
  28. final c = controller ?? TextEditingController(text: initialValue);
  29. final borderRadius = BorderRadius.all(Radius.circular(radius ?? 0));
  30. return TextField(
  31. controller: c,
  32. textAlign: TextAlign.start,
  33. textAlignVertical: TextAlignVertical.center,
  34. maxLines: maxLines,
  35. decoration: InputDecoration(
  36. enabledBorder: OutlineInputBorder(
  37. borderRadius: borderRadius,
  38. borderSide: const BorderSide(color: Colors.grey),
  39. ),
  40. focusedBorder: OutlineInputBorder(
  41. borderRadius: borderRadius,
  42. borderSide: BorderSide(color: Theme.of(context).primaryColor),
  43. ),
  44. errorBorder: OutlineInputBorder(
  45. borderRadius: borderRadius,
  46. borderSide: BorderSide(color: Theme.of(context).colorScheme.error),
  47. ),
  48. suffixIcon: suffixIcon,
  49. // errorText: "112323",
  50. errorMaxLines: 1,
  51. fillColor: Colors.white,
  52. filled: true,
  53. hintText: placeholder,
  54. hintStyle: const TextStyle(
  55. fontSize: 16,
  56. color: Colors.black54,
  57. ),
  58. contentPadding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
  59. // isDense: true,
  60. isCollapsed: false,
  61. ),
  62. onChanged: (value) {
  63. onChanged?.call(value);
  64. },
  65. onTap: () {
  66. onTap?.call();
  67. },
  68. readOnly: readOnly!,
  69. );
  70. }
  71. }