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.

93 lines
2.9KB

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