Browse Source

scan qrcode

master
daivph 5 years ago
parent
commit
a510e5c0ca
7 changed files with 77 additions and 19 deletions
  1. +5
    -0
      lib/data/api/rest_client.dart
  2. +20
    -0
      lib/data/api/rest_client.g.dart
  3. +5
    -0
      lib/data/repository/repository.dart
  4. +24
    -6
      lib/presentation/screens/plot_detail/bloc/plot_detail_bloc.dart
  5. +4
    -2
      lib/presentation/screens/plot_detail/bloc/plot_detail_event.dart
  6. +15
    -9
      lib/presentation/screens/plot_detail/sc_plot_action.dart
  7. +4
    -2
      lib/presentation/screens/plot_detail/sc_plot_detail.dart

+ 5
- 0
lib/data/api/rest_client.dart View File

@@ -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

+ 20
- 0
lib/data/api/rest_client.g.dart View File

@@ -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');

+ 5
- 0
lib/data/repository/repository.dart View File

@@ -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
- 6
lib/presentation/screens/plot_detail/bloc/plot_detail_bloc.dart View File

@@ -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,

+ 4
- 2
lib/presentation/screens/plot_detail/bloc/plot_detail_event.dart View File

@@ -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
- 9
lib/presentation/screens/plot_detail/sc_plot_action.dart View File

@@ -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(

+ 4
- 2
lib/presentation/screens/plot_detail/sc_plot_detail.dart View File

@@ -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,
)
],
),

Loading…
Cancel
Save