import 'package:camera/camera.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:get/route_manager.dart'; import 'app.dart'; import 'data/repository/authentication_repository.dart'; import 'data/repository/repository.dart'; import 'presentation/custom_widgets/widget_utils.dart'; List cameras = []; Future main() async { // Fetch the available cameras before initializing the app. try { WidgetsFlutterBinding.ensureInitialized(); cameras = await availableCameras(); } on CameraException catch (e) { print(e.description); } runApp(App(authenticationRepository: AuthenticationRepository())); } Future myBackgroundMessageHandler(Map message) { if (message.containsKey('data')) { // Handle data message final dynamic data = message['data']; } if (message.containsKey('notification')) { // Handle notification message final dynamic notification = message['notification']; } // Or do other work. } // Future scan(BuildContext context) async { // var _aspectTolerance = 0.00; // var _selectedCamera = -1; // var _useAutoFocus = true; // var _autoEnableFlash = false; // var repository = Repository(); // try { // var options = ScanOptions( // strings: { // "cancel": "Huỷ", // "flash_on": "Bật flash", // "flash_off": "Tắt flash", // }, // useCamera: _selectedCamera, // autoEnableFlash: _autoEnableFlash, // android: AndroidOptions( // aspectTolerance: _aspectTolerance, // useAutoFocus: _useAutoFocus, // ), // ); // var result = await BarcodeScanner.scan(options: options); // print(result.toString()); // if (result.type == ResultType.Cancelled) { // print("canncel"); // } else if (result.type == ResultType.Error) { // print("error"); // } else { // print("show check crop"); // _showAlertCheckCropCode(context, result.rawContent, repository); // } // } on PlatformException catch (e) { // print("error: ${e.message}"); // } // } _showAlertCheckCropCode(String cropCode) async { var repository = Repository(); 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, cropType: value.tbCropDTO.tbCropTypeId, initialIndex: 0)); }).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); }); } }