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.

116 lines
3.7KB

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