You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.3KB

  1. import 'package:farm_tpf/utils/const_color.dart';
  2. import 'package:flutter/material.dart';
  3. class SearchWidget extends StatefulWidget {
  4. final Function(String) searchPressed;
  5. SearchWidget({required this.searchPressed});
  6. @override
  7. _SearchWidgetState createState() => _SearchWidgetState();
  8. }
  9. class _SearchWidgetState extends State<SearchWidget> {
  10. BuildContext? _blocContext;
  11. TextEditingController _searchController = TextEditingController();
  12. @override
  13. void initState() {
  14. super.initState();
  15. _searchController.addListener(() {
  16. final keyword = _searchController.text;
  17. if (keyword.isNotEmpty) {
  18. //search when text change
  19. }
  20. });
  21. }
  22. Widget getSearchBarUI() {
  23. _searchController.text = "";
  24. return Padding(
  25. padding: const EdgeInsets.only(left: 8, right: 8, top: 0, bottom: 4),
  26. child: Row(
  27. children: <Widget>[
  28. Expanded(
  29. child: Padding(
  30. padding: const EdgeInsets.only(right: 8, top: 0, bottom: 0),
  31. child: Container(
  32. child: Padding(
  33. padding: const EdgeInsets.only(left: 16, right: 16, top: 4, bottom: 4),
  34. child: TextField(
  35. textInputAction: TextInputAction.done,
  36. controller: _searchController,
  37. onChanged: (String txt) {},
  38. cursorColor: AppColors.GRAY1,
  39. decoration: InputDecoration(
  40. suffixIcon: IconButton(
  41. icon: Icon(
  42. Icons.search,
  43. size: 30,
  44. ),
  45. onPressed: () {
  46. widget.searchPressed(_searchController.text);
  47. }),
  48. hintText: 'Tìm thiết bị',
  49. hintStyle: TextStyle(color: Colors.grey[500]),
  50. ),
  51. onSubmitted: widget.searchPressed,
  52. ),
  53. ),
  54. ),
  55. ),
  56. ),
  57. ],
  58. ),
  59. );
  60. }
  61. @override
  62. Widget build(BuildContext context) {
  63. _blocContext = context;
  64. return Container(child: getSearchBarUI());
  65. }
  66. @override
  67. void dispose() {
  68. _searchController.dispose();
  69. super.dispose();
  70. }
  71. }