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.

88 lines
2.6KB

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