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.4KB

  1. import 'package:farm_tpf/utils/const_color.dart';
  2. import 'package:flutter/material.dart';
  3. class WidgetSearch extends StatefulWidget {
  4. @override
  5. _WidgetSearchState createState() => _WidgetSearchState();
  6. }
  7. class _WidgetSearchState extends State<WidgetSearch> {
  8. BuildContext _blocContext;
  9. TextEditingController _searchController = TextEditingController();
  10. @override
  11. void initState() {
  12. super.initState();
  13. _searchController.addListener(() {
  14. final keyword = _searchController.text;
  15. if (keyword.isNotEmpty) {
  16. //search when text change
  17. }
  18. });
  19. }
  20. Widget getSearchBarUI() {
  21. _searchController.text = "";
  22. return Padding(
  23. padding: const EdgeInsets.only(left: 8, right: 8, top: 4, bottom: 0),
  24. child: Row(
  25. children: <Widget>[
  26. Expanded(
  27. child: Padding(
  28. padding: const EdgeInsets.only(right: 8, top: 8, bottom: 0),
  29. child: Container(
  30. decoration: BoxDecoration(
  31. color: Colors.white,
  32. borderRadius: const BorderRadius.all(
  33. Radius.circular(38.0),
  34. ),
  35. boxShadow: <BoxShadow>[
  36. BoxShadow(
  37. color: Colors.grey.withOpacity(0.2),
  38. offset: const Offset(0, 2),
  39. blurRadius: 8.0),
  40. ],
  41. ),
  42. child: Padding(
  43. padding: const EdgeInsets.only(
  44. left: 16, right: 16, top: 4, bottom: 4),
  45. child: TextField(
  46. textInputAction: TextInputAction.done,
  47. controller: _searchController,
  48. onChanged: (String txt) {},
  49. cursorColor: COLOR_CONST.GRAY1,
  50. decoration: InputDecoration(
  51. border: InputBorder.none,
  52. hintText: 'Tìm kiếm ...',
  53. ),
  54. onSubmitted: (value) {
  55. FocusScope.of(context).requestFocus(FocusNode());
  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. }