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.

76 lines
2.2KB

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