| Future<CropPlot> getCropDetail(@Path() int cropId, | Future<CropPlot> getCropDetail(@Path() int cropId, | ||||
| {@Path() int page = 0, @Path() int size = 20}); | {@Path() int page = 0, @Path() int size = 20}); | ||||
| @GET( | |||||
| "/api/tb-crops-scan-qrCode/{cropCode}?page={page}&size={size}&sort=executeDate,DESC") | |||||
| Future<CropPlot> getCropDetailByCode(@Path() String cropCode, | |||||
| {@Path() int page = 0, @Path() int size = 20}); | |||||
| @PUT("/api/tb-crops") | @PUT("/api/tb-crops") | ||||
| Future<void> updateCrop(@Body() TbCropDTO crop); | Future<void> updateCrop(@Body() TbCropDTO crop); | ||||
| //Device | //Device |
| return value; | return value; | ||||
| } | } | ||||
| @override | |||||
| getCropDetailByCode(cropCode, {page = 0, size = 20}) async { | |||||
| ArgumentError.checkNotNull(cropCode, 'cropCode'); | |||||
| const _extra = <String, dynamic>{}; | |||||
| final queryParameters = <String, dynamic>{}; | |||||
| queryParameters.removeWhere((k, v) => v == null); | |||||
| final _data = <String, dynamic>{}; | |||||
| final Response<Map<String, dynamic>> _result = await _dio.request( | |||||
| '/api/tb-crops-scan-qrCode/$cropCode?page=$page&size=$size&sort=executeDate,DESC', | |||||
| queryParameters: queryParameters, | |||||
| options: RequestOptions( | |||||
| method: 'GET', | |||||
| headers: <String, dynamic>{}, | |||||
| extra: _extra, | |||||
| baseUrl: baseUrl), | |||||
| data: _data); | |||||
| final value = CropPlot.fromJson(_result.data); | |||||
| return value; | |||||
| } | |||||
| @override | @override | ||||
| updateCrop(crop) async { | updateCrop(crop) async { | ||||
| ArgumentError.checkNotNull(crop, 'crop'); | ArgumentError.checkNotNull(crop, 'crop'); |
| return client.getCropDetail(cropId, page: page, size: size); | return client.getCropDetail(cropId, page: page, size: size); | ||||
| } | } | ||||
| Future<CropPlot> getPlotDetailByCode(String cropCode, {int page, int size}) { | |||||
| final client = RestClient(dio); | |||||
| return client.getCropDetailByCode(cropCode, page: page, size: size); | |||||
| } | |||||
| Future<List<Crop>> getPlots({int page, int size, String searchString}) { | Future<List<Crop>> getPlots({int page, int size, String searchString}) { | ||||
| final client = RestClient(dio); | final client = RestClient(dio); | ||||
| return client.getPlots(page: page, size: size, query: searchString); | return client.getPlots(page: page, size: size, query: searchString); |
| try { | try { | ||||
| if (state is PlotDetailInitial) { | if (state is PlotDetailInitial) { | ||||
| yield PlotDetailLoading(); | yield PlotDetailLoading(); | ||||
| final response = await repository.getPlotDetail(event.cropId, | |||||
| page: 0, size: pageSize); | |||||
| var response; | |||||
| if (event.cropId != null) { | |||||
| response = await repository.getPlotDetail(event.cropId, | |||||
| page: 0, size: pageSize); | |||||
| } else { | |||||
| response = await repository.getPlotDetailByCode(event.cropCode, | |||||
| page: 0, size: pageSize); | |||||
| } | |||||
| yield PlotDetailSuccess( | yield PlotDetailSuccess( | ||||
| items: response.activities, | items: response.activities, | ||||
| page: 0, | page: 0, | ||||
| if (state is PlotDetailSuccess) { | if (state is PlotDetailSuccess) { | ||||
| final currentState = state as PlotDetailSuccess; | final currentState = state as PlotDetailSuccess; | ||||
| int page = currentState.page + 1; | int page = currentState.page + 1; | ||||
| final response = await repository.getPlotDetail(event.cropId, | |||||
| page: page, size: pageSize); | |||||
| var response; | |||||
| if (event.cropId != null) { | |||||
| response = await repository.getPlotDetail(event.cropId, | |||||
| page: page, size: pageSize); | |||||
| } else { | |||||
| response = await repository.getPlotDetailByCode(event.cropCode, | |||||
| page: page, size: pageSize); | |||||
| } | |||||
| yield response.activities.isEmpty | yield response.activities.isEmpty | ||||
| ? currentState.copyWith(hasReachedMax: true) | ? currentState.copyWith(hasReachedMax: true) | ||||
| : PlotDetailSuccess( | : PlotDetailSuccess( | ||||
| if (event is OnRefresh) { | if (event is OnRefresh) { | ||||
| try { | try { | ||||
| yield PlotDetailLoading(); | yield PlotDetailLoading(); | ||||
| final response = await repository.getPlotDetail(event.cropId, | |||||
| page: 0, size: pageSize); | |||||
| var response; | |||||
| if (event.cropId != null) { | |||||
| response = await repository.getPlotDetail(event.cropId, | |||||
| page: 0, size: pageSize); | |||||
| } else { | |||||
| response = await repository.getPlotDetailByCode(event.cropCode, | |||||
| page: 0, size: pageSize); | |||||
| } | |||||
| yield PlotDetailSuccess( | yield PlotDetailSuccess( | ||||
| items: response.activities, | items: response.activities, | ||||
| page: 0, | page: 0, |
| class DataFetched extends PlotDetailEvent { | class DataFetched extends PlotDetailEvent { | ||||
| final int cropId; | final int cropId; | ||||
| DataFetched(this.cropId); | |||||
| final String cropCode; | |||||
| DataFetched({this.cropId, this.cropCode}); | |||||
| } | } | ||||
| class OnRefresh extends PlotDetailEvent { | class OnRefresh extends PlotDetailEvent { | ||||
| final int cropId; | final int cropId; | ||||
| OnRefresh(this.cropId); | |||||
| final String cropCode; | |||||
| OnRefresh({this.cropId, this.cropCode}); | |||||
| } | } |
| import 'package:farm_tpf/utils/formatter.dart'; | import 'package:farm_tpf/utils/formatter.dart'; | ||||
| class PlotActionScreen extends StatefulWidget { | class PlotActionScreen extends StatefulWidget { | ||||
| final int cropId; | |||||
| PlotActionScreen({@required this.cropId}); | |||||
| int cropId; | |||||
| String cropCode; | |||||
| PlotActionScreen({this.cropId, this.cropCode}); | |||||
| @override | @override | ||||
| _PlotActionScreenState createState() => _PlotActionScreenState(); | _PlotActionScreenState createState() => _PlotActionScreenState(); | ||||
| } | } | ||||
| ], | ], | ||||
| body: BlocProvider( | body: BlocProvider( | ||||
| create: (context) => PlotDetailBloc(repository: Repository()) | create: (context) => PlotDetailBloc(repository: Repository()) | ||||
| ..add(DataFetched(widget.cropId)), | |||||
| ..add(DataFetched(cropId: widget.cropId, cropCode: widget.cropCode)), | |||||
| child: HoldInfinityWidget( | child: HoldInfinityWidget( | ||||
| cropId: widget.cropId, | cropId: widget.cropId, | ||||
| cropCode: widget.cropCode, | |||||
| ), | ), | ||||
| ), | ), | ||||
| ); | ); | ||||
| } | } | ||||
| class HoldInfinityWidget extends StatelessWidget { | class HoldInfinityWidget extends StatelessWidget { | ||||
| final int cropId; | |||||
| HoldInfinityWidget({@required this.cropId}); | |||||
| int cropId; | |||||
| String cropCode; | |||||
| HoldInfinityWidget({this.cropId, this.cropCode}); | |||||
| final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); | final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); | ||||
| @override | @override | ||||
| Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
| } | } | ||||
| class InfinityView extends StatefulWidget { | class InfinityView extends StatefulWidget { | ||||
| final int cropId; | |||||
| InfinityView({@required this.cropId}); | |||||
| int cropId; | |||||
| String cropCode; | |||||
| InfinityView({this.cropId, this.cropCode}); | |||||
| @override | @override | ||||
| _InfinityViewState createState() => _InfinityViewState(); | _InfinityViewState createState() => _InfinityViewState(); | ||||
| } | } | ||||
| final maxScroll = _scrollController.position.maxScrollExtent; | final maxScroll = _scrollController.position.maxScrollExtent; | ||||
| final currentScroll = _scrollController.position.pixels; | final currentScroll = _scrollController.position.pixels; | ||||
| if (maxScroll - currentScroll < _scrollThreshold) { | if (maxScroll - currentScroll < _scrollThreshold) { | ||||
| _plotDetailBloc.add(DataFetched(widget.cropId)); | |||||
| _plotDetailBloc | |||||
| .add(DataFetched(cropId: widget.cropId, cropCode: widget.cropCode)); | |||||
| } | } | ||||
| }); | }); | ||||
| _plotDetailBloc = BlocProvider.of<PlotDetailBloc>(context); | _plotDetailBloc = BlocProvider.of<PlotDetailBloc>(context); | ||||
| controller: _scrollController, | controller: _scrollController, | ||||
| ), | ), | ||||
| onRefresh: () async { | onRefresh: () async { | ||||
| _plotDetailBloc.add(OnRefresh(widget.cropId)); | |||||
| _plotDetailBloc.add(OnRefresh( | |||||
| cropId: widget.cropId, cropCode: widget.cropCode)); | |||||
| }); | }); | ||||
| } | } | ||||
| return Center( | return Center( |
| import 'package:get/get.dart'; | import 'package:get/get.dart'; | ||||
| class PlotDetailScreen extends StatefulWidget { | class PlotDetailScreen extends StatefulWidget { | ||||
| final int cropId; | |||||
| int cropId; | |||||
| String cropCode; | |||||
| int initialIndex; | int initialIndex; | ||||
| PlotDetailScreen({@required this.cropId, this.initialIndex = 0}); | |||||
| PlotDetailScreen({this.cropId, this.initialIndex = 0, this.cropCode}); | |||||
| @override | @override | ||||
| _PlotDetailScreenState createState() => _PlotDetailScreenState(); | _PlotDetailScreenState createState() => _PlotDetailScreenState(); | ||||
| } | } | ||||
| PlotParameterScreen(), | PlotParameterScreen(), | ||||
| PlotActionScreen( | PlotActionScreen( | ||||
| cropId: widget.cropId, | cropId: widget.cropId, | ||||
| cropCode: widget.cropCode, | |||||
| ) | ) | ||||
| ], | ], | ||||
| ), | ), |