| @@ -53,6 +53,11 @@ abstract class RestClient { | |||
| Future<CropPlot> getCropDetail(@Path() int cropId, | |||
| {@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") | |||
| Future<void> updateCrop(@Body() TbCropDTO crop); | |||
| //Device | |||
| @@ -226,6 +226,26 @@ class _RestClient implements RestClient { | |||
| 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 | |||
| updateCrop(crop) async { | |||
| ArgumentError.checkNotNull(crop, 'crop'); | |||
| @@ -26,6 +26,11 @@ class Repository { | |||
| 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}) { | |||
| final client = RestClient(dio); | |||
| return client.getPlots(page: page, size: size, query: searchString); | |||
| @@ -24,8 +24,14 @@ class PlotDetailBloc extends Bloc<PlotDetailEvent, PlotDetailState> { | |||
| try { | |||
| if (state is PlotDetailInitial) { | |||
| 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( | |||
| items: response.activities, | |||
| page: 0, | |||
| @@ -35,8 +41,14 @@ class PlotDetailBloc extends Bloc<PlotDetailEvent, PlotDetailState> { | |||
| if (state is PlotDetailSuccess) { | |||
| final currentState = state as PlotDetailSuccess; | |||
| 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 | |||
| ? currentState.copyWith(hasReachedMax: true) | |||
| : PlotDetailSuccess( | |||
| @@ -52,8 +64,14 @@ class PlotDetailBloc extends Bloc<PlotDetailEvent, PlotDetailState> { | |||
| if (event is OnRefresh) { | |||
| try { | |||
| 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( | |||
| items: response.activities, | |||
| page: 0, | |||
| @@ -9,10 +9,12 @@ abstract class PlotDetailEvent extends Equatable { | |||
| class DataFetched extends PlotDetailEvent { | |||
| final int cropId; | |||
| DataFetched(this.cropId); | |||
| final String cropCode; | |||
| DataFetched({this.cropId, this.cropCode}); | |||
| } | |||
| class OnRefresh extends PlotDetailEvent { | |||
| final int cropId; | |||
| OnRefresh(this.cropId); | |||
| final String cropCode; | |||
| OnRefresh({this.cropId, this.cropCode}); | |||
| } | |||
| @@ -15,8 +15,9 @@ import 'package:flutter_bloc/flutter_bloc.dart'; | |||
| import 'package:farm_tpf/utils/formatter.dart'; | |||
| class PlotActionScreen extends StatefulWidget { | |||
| final int cropId; | |||
| PlotActionScreen({@required this.cropId}); | |||
| int cropId; | |||
| String cropCode; | |||
| PlotActionScreen({this.cropId, this.cropCode}); | |||
| @override | |||
| _PlotActionScreenState createState() => _PlotActionScreenState(); | |||
| } | |||
| @@ -158,9 +159,10 @@ class _PlotActionScreenState extends State<PlotActionScreen> { | |||
| ], | |||
| body: BlocProvider( | |||
| create: (context) => PlotDetailBloc(repository: Repository()) | |||
| ..add(DataFetched(widget.cropId)), | |||
| ..add(DataFetched(cropId: widget.cropId, cropCode: widget.cropCode)), | |||
| child: HoldInfinityWidget( | |||
| cropId: widget.cropId, | |||
| cropCode: widget.cropCode, | |||
| ), | |||
| ), | |||
| ); | |||
| @@ -168,8 +170,9 @@ class _PlotActionScreenState extends State<PlotActionScreen> { | |||
| } | |||
| 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>(); | |||
| @override | |||
| Widget build(BuildContext context) { | |||
| @@ -178,8 +181,9 @@ class HoldInfinityWidget extends StatelessWidget { | |||
| } | |||
| class InfinityView extends StatefulWidget { | |||
| final int cropId; | |||
| InfinityView({@required this.cropId}); | |||
| int cropId; | |||
| String cropCode; | |||
| InfinityView({this.cropId, this.cropCode}); | |||
| @override | |||
| _InfinityViewState createState() => _InfinityViewState(); | |||
| } | |||
| @@ -195,7 +199,8 @@ class _InfinityViewState extends State<InfinityView> { | |||
| final maxScroll = _scrollController.position.maxScrollExtent; | |||
| final currentScroll = _scrollController.position.pixels; | |||
| if (maxScroll - currentScroll < _scrollThreshold) { | |||
| _plotDetailBloc.add(DataFetched(widget.cropId)); | |||
| _plotDetailBloc | |||
| .add(DataFetched(cropId: widget.cropId, cropCode: widget.cropCode)); | |||
| } | |||
| }); | |||
| _plotDetailBloc = BlocProvider.of<PlotDetailBloc>(context); | |||
| @@ -227,7 +232,8 @@ class _InfinityViewState extends State<InfinityView> { | |||
| controller: _scrollController, | |||
| ), | |||
| onRefresh: () async { | |||
| _plotDetailBloc.add(OnRefresh(widget.cropId)); | |||
| _plotDetailBloc.add(OnRefresh( | |||
| cropId: widget.cropId, cropCode: widget.cropCode)); | |||
| }); | |||
| } | |||
| return Center( | |||
| @@ -8,9 +8,10 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; | |||
| import 'package:get/get.dart'; | |||
| class PlotDetailScreen extends StatefulWidget { | |||
| final int cropId; | |||
| int cropId; | |||
| String cropCode; | |||
| int initialIndex; | |||
| PlotDetailScreen({@required this.cropId, this.initialIndex = 0}); | |||
| PlotDetailScreen({this.cropId, this.initialIndex = 0, this.cropCode}); | |||
| @override | |||
| _PlotDetailScreenState createState() => _PlotDetailScreenState(); | |||
| } | |||
| @@ -47,6 +48,7 @@ class _PlotDetailScreenState extends State<PlotDetailScreen> { | |||
| PlotParameterScreen(), | |||
| PlotActionScreen( | |||
| cropId: widget.cropId, | |||
| cropCode: widget.cropCode, | |||
| ) | |||
| ], | |||
| ), | |||