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.

96 lines
3.3KB

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