input.dart 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. const VInput({
  12. super.key,
  13. this.initialValue,
  14. this.controller,
  15. this.focusNode,
  16. this.placeholder,
  17. this.onChanged,
  18. this.onTap,
  19. this.readOnly = false,
  20. this.radius,
  21. });
  22. @override
  23. Widget build(BuildContext context) {
  24. final c = controller ?? TextEditingController(text: initialValue);
  25. final borderRadius = BorderRadius.all(Radius.circular(radius ?? 0));
  26. return TextField(
  27. controller: c,
  28. textAlign: TextAlign.start,
  29. textAlignVertical: TextAlignVertical.center,
  30. decoration: InputDecoration(
  31. enabledBorder: OutlineInputBorder(
  32. borderRadius: borderRadius,
  33. borderSide: const BorderSide(color: Colors.grey),
  34. ),
  35. focusedBorder: OutlineInputBorder(
  36. borderRadius: borderRadius,
  37. borderSide: BorderSide(color: Theme.of(context).primaryColor),
  38. ),
  39. errorBorder: OutlineInputBorder(
  40. borderRadius: borderRadius,
  41. borderSide: BorderSide(color: Theme.of(context).colorScheme.error),
  42. ),
  43. // errorText: "112323",
  44. errorMaxLines: 1,
  45. fillColor: Colors.white,
  46. filled: true,
  47. hintText: placeholder,
  48. hintStyle: const TextStyle(
  49. fontSize: 16,
  50. color: Colors.black54,
  51. ),
  52. contentPadding: const EdgeInsets.symmetric(horizontal: 8, vertical: 0),
  53. // isDense: true,
  54. isCollapsed: false,
  55. ),
  56. onChanged: (value) {
  57. onChanged?.call(value);
  58. },
  59. onTap: () {
  60. onTap?.call();
  61. },
  62. readOnly: readOnly!,
  63. );
  64. }
  65. }