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.

103 lines
3.2KB

  1. import 'package:camera/camera.dart';
  2. import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_detail.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/services.dart';
  5. import 'package:get/route_manager.dart';
  6. import 'app.dart';
  7. import 'data/repository/authentication_repository.dart';
  8. import 'data/repository/repository.dart';
  9. import 'presentation/custom_widgets/widget_utils.dart';
  10. List<CameraDescription> cameras = [];
  11. Future<void> main() async {
  12. // Fetch the available cameras before initializing the app.
  13. try {
  14. WidgetsFlutterBinding.ensureInitialized();
  15. cameras = await availableCameras();
  16. } on CameraException catch (e) {
  17. print(e.description);
  18. }
  19. runApp(App(authenticationRepository: AuthenticationRepository()));
  20. }
  21. Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) {
  22. if (message.containsKey('data')) {
  23. // Handle data message
  24. final dynamic data = message['data'];
  25. }
  26. if (message.containsKey('notification')) {
  27. // Handle notification message
  28. final dynamic notification = message['notification'];
  29. }
  30. // Or do other work.
  31. }
  32. // Future scan(BuildContext context) async {
  33. // var _aspectTolerance = 0.00;
  34. // var _selectedCamera = -1;
  35. // var _useAutoFocus = true;
  36. // var _autoEnableFlash = false;
  37. // var repository = Repository();
  38. // try {
  39. // var options = ScanOptions(
  40. // strings: {
  41. // "cancel": "Huỷ",
  42. // "flash_on": "Bật flash",
  43. // "flash_off": "Tắt flash",
  44. // },
  45. // useCamera: _selectedCamera,
  46. // autoEnableFlash: _autoEnableFlash,
  47. // android: AndroidOptions(
  48. // aspectTolerance: _aspectTolerance,
  49. // useAutoFocus: _useAutoFocus,
  50. // ),
  51. // );
  52. // var result = await BarcodeScanner.scan(options: options);
  53. // print(result.toString());
  54. // if (result.type == ResultType.Cancelled) {
  55. // print("canncel");
  56. // } else if (result.type == ResultType.Error) {
  57. // print("error");
  58. // } else {
  59. // print("show check crop");
  60. // _showAlertCheckCropCode(context, result.rawContent, repository);
  61. // }
  62. // } on PlatformException catch (e) {
  63. // print("error: ${e.message}");
  64. // }
  65. // }
  66. _showAlertCheckCropCode(String cropCode) async {
  67. var repository = Repository();
  68. Get.defaultDialog(title: "Kiểm tra thông tin lô ....", middleText: "", content: CircularProgressIndicator());
  69. try {
  70. await repository.getPlotDetailByCode(cropCode).then((value) {
  71. print("ok");
  72. if (Get.isDialogOpen) Get.back();
  73. Get.to(PlotDetailScreen(cropId: value.tbCropDTO.id, cropType: value.tbCropDTO.tbCropTypeId, initialIndex: 0));
  74. }).catchError((onError) {
  75. Utils.showDialog(
  76. title: "Không tìm thấy lô",
  77. message: "Thử lại với mã tem khác?",
  78. textConfirm: "Thử lại",
  79. textCancel: "Huỷ",
  80. onConfirm: () {
  81. Get.back();
  82. // scan(context);
  83. });
  84. });
  85. } catch (e) {
  86. Utils.showDialog(
  87. title: "Không tìm thấy lô",
  88. message: "Thử lại với mã tem khác?",
  89. textConfirm: "Thử lại",
  90. textCancel: "Huỷ",
  91. onConfirm: () {
  92. Get.back();
  93. // scan(context);
  94. });
  95. }
  96. }