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.

85 lines
2.5KB

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