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.

104 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. return Future(() => true);
  31. // Or do other work.
  32. }
  33. // Future scan(BuildContext context) async {
  34. // var _aspectTolerance = 0.00;
  35. // var _selectedCamera = -1;
  36. // var _useAutoFocus = true;
  37. // var _autoEnableFlash = false;
  38. // var repository = Repository();
  39. // try {
  40. // var options = ScanOptions(
  41. // strings: {
  42. // "cancel": "Huỷ",
  43. // "flash_on": "Bật flash",
  44. // "flash_off": "Tắt flash",
  45. // },
  46. // useCamera: _selectedCamera,
  47. // autoEnableFlash: _autoEnableFlash,
  48. // android: AndroidOptions(
  49. // aspectTolerance: _aspectTolerance,
  50. // useAutoFocus: _useAutoFocus,
  51. // ),
  52. // );
  53. // var result = await BarcodeScanner.scan(options: options);
  54. // print(result.toString());
  55. // if (result.type == ResultType.Cancelled) {
  56. // print("canncel");
  57. // } else if (result.type == ResultType.Error) {
  58. // print("error");
  59. // } else {
  60. // print("show check crop");
  61. // _showAlertCheckCropCode(context, result.rawContent, repository);
  62. // }
  63. // } on PlatformException catch (e) {
  64. // print("error: ${e.message}");
  65. // }
  66. // }
  67. _showAlertCheckCropCode(String cropCode) async {
  68. var repository = Repository();
  69. Get.defaultDialog(title: "Kiểm tra thông tin lô ....", middleText: "", content: CircularProgressIndicator());
  70. try {
  71. await repository.getPlotDetailByCode(cropCode).then((value) {
  72. print("ok");
  73. if (Get.isDialogOpen) Get.back();
  74. Get.to(PlotDetailScreen(cropId: value.tbCropDTO?.id ?? -1, cropType: value.tbCropDTO?.tbCropTypeId ?? -1, initialIndex: 0));
  75. }).catchError((onError) {
  76. Utils.showDialog(
  77. title: "Không tìm thấy lô",
  78. message: "Thử lại với mã tem khác?",
  79. textConfirm: "Thử lại",
  80. textCancel: "Huỷ",
  81. onConfirm: () {
  82. Get.back();
  83. // scan(context);
  84. });
  85. });
  86. } catch (e) {
  87. Utils.showDialog(
  88. title: "Không tìm thấy lô",
  89. message: "Thử lại với mã tem khác?",
  90. textConfirm: "Thử lại",
  91. textCancel: "Huỷ",
  92. onConfirm: () {
  93. Get.back();
  94. // scan(context);
  95. });
  96. }
  97. }