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.

86 lines
2.7KB

  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: Icon(
  47. Icons.search,
  48. size: 30,
  49. ),
  50. hintText: 'Tìm kiếm',
  51. hintStyle: TextStyle(color: Colors.grey[500])),
  52. onSubmitted: (value) {
  53. FocusScope.of(context).requestFocus(FocusNode());
  54. BlocProvider.of<LocationBloc>(_blocContext).add(OnSearch(
  55. searchString: value,
  56. locationType: widget.type,
  57. selectedId: widget.selectedId,
  58. filterId: widget.filterId));
  59. },
  60. ),
  61. ),
  62. ),
  63. ),
  64. ),
  65. ],
  66. ),
  67. );
  68. }
  69. @override
  70. Widget build(BuildContext context) {
  71. _blocContext = context;
  72. return Container(child: getSearchBarUI());
  73. }
  74. @override
  75. void dispose() {
  76. _searchController.dispose();
  77. super.dispose();
  78. }
  79. }