|
|
|
@@ -1,16 +1,13 @@ |
|
|
|
import 'package:barcode_scan/barcode_scan.dart'; |
|
|
|
import 'package:camera/camera.dart'; |
|
|
|
import 'package:farm_tpf/presentation/screens/plot_detail/bloc/plot_detail_bloc.dart'; |
|
|
|
import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_detail.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter/services.dart'; |
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart'; |
|
|
|
import 'package:get/route_manager.dart'; |
|
|
|
import 'package:rflutter_alert/rflutter_alert.dart'; |
|
|
|
import 'app.dart'; |
|
|
|
import 'custom_model/CropPlot.dart'; |
|
|
|
import 'data/repository/authentication_repository.dart'; |
|
|
|
import 'data/repository/repository.dart'; |
|
|
|
import 'presentation/custom_widgets/widget_utils.dart'; |
|
|
|
|
|
|
|
List<CameraDescription> cameras = []; |
|
|
|
Future<void> main() async { |
|
|
|
@@ -43,6 +40,7 @@ Future scan(BuildContext context) async { |
|
|
|
var _selectedCamera = -1; |
|
|
|
var _useAutoFocus = true; |
|
|
|
var _autoEnableFlash = false; |
|
|
|
var repository = Repository(); |
|
|
|
try { |
|
|
|
var options = ScanOptions( |
|
|
|
strings: { |
|
|
|
@@ -64,75 +62,50 @@ Future scan(BuildContext context) async { |
|
|
|
} else if (result.type == ResultType.Error) { |
|
|
|
print("error"); |
|
|
|
} else { |
|
|
|
_showAlertCheckCropCode(context, result.rawContent); |
|
|
|
print("show check crop"); |
|
|
|
_showAlertCheckCropCode(context, result.rawContent, repository); |
|
|
|
} |
|
|
|
} on PlatformException catch (e) { |
|
|
|
var result = ScanResult( |
|
|
|
type: ResultType.Error, |
|
|
|
format: BarcodeFormat.unknown, |
|
|
|
); |
|
|
|
print("error: ${e.message}"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
_showAlertCheckCropCode(BuildContext context, String cropCode) { |
|
|
|
Alert( |
|
|
|
context: context, |
|
|
|
title: "", |
|
|
|
style: AlertStyle(isCloseButton: false, isOverlayTapDismiss: false), |
|
|
|
content: BlocProvider<PlotDetailBloc>( |
|
|
|
create: (context) => PlotDetailBloc(repository: Repository()) |
|
|
|
..add(DataFetched(cropCode: cropCode)), |
|
|
|
child: BlocBuilder<PlotDetailBloc, PlotDetailState>( |
|
|
|
builder: (context, state) { |
|
|
|
if (state is PlotDetailInitial) { |
|
|
|
return Center( |
|
|
|
child: Text(""), |
|
|
|
); |
|
|
|
} else if (state is PlotDetailFailure) { |
|
|
|
return Center( |
|
|
|
child: Column( |
|
|
|
children: [ |
|
|
|
Text("Lô không tồn tại"), |
|
|
|
SizedBox( |
|
|
|
height: 16, |
|
|
|
), |
|
|
|
DialogButton( |
|
|
|
onPressed: () { |
|
|
|
Get.back(); |
|
|
|
scan(context); |
|
|
|
}, |
|
|
|
child: Text( |
|
|
|
"Quét lại", |
|
|
|
style: TextStyle(color: Colors.white, fontSize: 20), |
|
|
|
), |
|
|
|
) |
|
|
|
], |
|
|
|
), |
|
|
|
); |
|
|
|
} else if (state is PlotDetailSuccess) { |
|
|
|
var result = state.ownerItem as CropPlot; |
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) { |
|
|
|
Get.back(); |
|
|
|
Get.to(PlotDetailScreen( |
|
|
|
cropId: result.tbCropDTO.id, |
|
|
|
initialIndex: 1, |
|
|
|
)); |
|
|
|
}); |
|
|
|
return Center(child: Text("")); |
|
|
|
} else { |
|
|
|
return Center( |
|
|
|
child: Column( |
|
|
|
children: [ |
|
|
|
CircularProgressIndicator(), |
|
|
|
SizedBox( |
|
|
|
height: 8, |
|
|
|
), |
|
|
|
Text("Kiểm tra thông tin lô ....") |
|
|
|
], |
|
|
|
), |
|
|
|
); |
|
|
|
} |
|
|
|
})), |
|
|
|
buttons: []).show(); |
|
|
|
_showAlertCheckCropCode( |
|
|
|
BuildContext context, String cropCode, Repository repository) async { |
|
|
|
Get.defaultDialog( |
|
|
|
title: "Kiểm tra thông tin lô ....", |
|
|
|
middleText: "", |
|
|
|
content: CircularProgressIndicator()); |
|
|
|
try { |
|
|
|
await repository |
|
|
|
.getPlotDetailByCode(cropCode, page: 1, size: 1) |
|
|
|
.then((value) { |
|
|
|
print("ok"); |
|
|
|
if (Get.isDialogOpen) Get.back(); |
|
|
|
Get.to(PlotDetailScreen( |
|
|
|
cropId: value.tbCropDTO.id, |
|
|
|
initialIndex: 1, |
|
|
|
)); |
|
|
|
}).catchError((onError) { |
|
|
|
Utils.showDialog( |
|
|
|
title: "Không tìm thấy lô", |
|
|
|
message: "Thử lại với mã tem khác?", |
|
|
|
textConfirm: "Thử lại", |
|
|
|
textCancel: "Huỷ", |
|
|
|
onConfirm: () { |
|
|
|
Get.back(); |
|
|
|
scan(context); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} catch (e) { |
|
|
|
Utils.showDialog( |
|
|
|
title: "Không tìm thấy lô", |
|
|
|
message: "Thử lại với mã tem khác?", |
|
|
|
textConfirm: "Thử lại", |
|
|
|
textCancel: "Huỷ", |
|
|
|
onConfirm: () { |
|
|
|
Get.back(); |
|
|
|
scan(context); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |