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.

92 lines
2.8KB

  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. decoration: BoxDecoration(
  36. color: Colors.white,
  37. borderRadius: const BorderRadius.all(
  38. Radius.circular(38.0),
  39. ),
  40. boxShadow: <BoxShadow>[
  41. BoxShadow(
  42. color: Colors.grey.withOpacity(0.2),
  43. offset: const Offset(0, 2),
  44. blurRadius: 8.0),
  45. ],
  46. ),
  47. child: Padding(
  48. padding: const EdgeInsets.only(
  49. left: 16, right: 16, top: 4, bottom: 4),
  50. child: TextField(
  51. textInputAction: TextInputAction.done,
  52. controller: _searchController,
  53. onChanged: (String txt) {},
  54. cursorColor: AppColors.GRAY1,
  55. decoration: InputDecoration(
  56. border: InputBorder.none,
  57. hintText: 'Tìm kiếm ...',
  58. ),
  59. onSubmitted: (value) {
  60. FocusScope.of(context).requestFocus(FocusNode());
  61. BlocProvider.of<SupplyBloc>(_blocContext).add(OnSearch(
  62. searchString: value,
  63. type: widget.type,
  64. selectedId: widget.selectedId));
  65. },
  66. ),
  67. ),
  68. ),
  69. ),
  70. ),
  71. ],
  72. ),
  73. );
  74. }
  75. @override
  76. Widget build(BuildContext context) {
  77. _blocContext = context;
  78. return Container(child: getSearchBarUI());
  79. }
  80. @override
  81. void dispose() {
  82. _searchController.dispose();
  83. super.dispose();
  84. }
  85. }