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.

83 lines
2.5KB

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