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.

95 lines
3.0KB

  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. decoration: BoxDecoration(
  38. color: Colors.white,
  39. borderRadius: const BorderRadius.all(
  40. Radius.circular(38.0),
  41. ),
  42. boxShadow: <BoxShadow>[
  43. BoxShadow(
  44. color: Colors.grey.withOpacity(0.2),
  45. offset: const Offset(0, 2),
  46. blurRadius: 8.0),
  47. ],
  48. ),
  49. child: Padding(
  50. padding: const EdgeInsets.only(
  51. left: 16, right: 16, top: 4, bottom: 4),
  52. child: TextField(
  53. textInputAction: TextInputAction.done,
  54. controller: _searchController,
  55. onChanged: (String txt) {},
  56. cursorColor: AppColors.GRAY1,
  57. decoration: InputDecoration(
  58. border: InputBorder.none,
  59. hintText: 'Tìm kiếm ...',
  60. ),
  61. onSubmitted: (value) {
  62. FocusScope.of(context).requestFocus(FocusNode());
  63. BlocProvider.of<LocationBloc>(_blocContext).add(OnSearch(
  64. searchString: value,
  65. locationType: widget.type,
  66. selectedId: widget.selectedId,
  67. filterId: widget.filterId));
  68. },
  69. ),
  70. ),
  71. ),
  72. ),
  73. ),
  74. ],
  75. ),
  76. );
  77. }
  78. @override
  79. Widget build(BuildContext context) {
  80. _blocContext = context;
  81. return Container(child: getSearchBarUI());
  82. }
  83. @override
  84. void dispose() {
  85. _searchController.dispose();
  86. super.dispose();
  87. }
  88. }