search_input.dart 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import 'package:flutter/material.dart';
  2. class VSearchInput extends StatelessWidget {
  3. /// 占位提示
  4. final String? placeholder;
  5. /// 搜索回调
  6. final ValueChanged<String>? onSearch;
  7. const VSearchInput({
  8. super.key,
  9. this.placeholder,
  10. this.onSearch,
  11. });
  12. @override
  13. Widget build(BuildContext context) {
  14. final controller = TextEditingController();
  15. const border = OutlineInputBorder(
  16. borderRadius: BorderRadius.all(Radius.circular(8)),
  17. borderSide: BorderSide.none,
  18. );
  19. return TextField(
  20. controller: controller,
  21. decoration: InputDecoration(
  22. enabledBorder: border,
  23. focusedBorder: border,
  24. fillColor: Colors.grey.shade400,
  25. filled: true,
  26. hintText: placeholder,
  27. hintStyle: const TextStyle(
  28. fontSize: 20,
  29. color: Colors.black54,
  30. ),
  31. // contentPadding: EdgeInsets.symmetric(horizontal: 40, vertical: 24),
  32. // isDense: true,
  33. isCollapsed: false,
  34. prefixIcon: IconButton(
  35. icon: const Icon(Icons.search, size: 36),
  36. onPressed: () {
  37. onSearch?.call(controller.text);
  38. },
  39. ),
  40. ),
  41. );
  42. }
  43. }