| buildscript { | buildscript { | ||||
| ext.kotlin_version = '1.3.61' | |||||
| ext.kotlin_version = '1.5.10' | |||||
| repositories { | repositories { | ||||
| google() | google() | ||||
| jcenter() | jcenter() |
| // } | // } | ||||
| // } | // } | ||||
| _showAlertCheckCropCode(BuildContext context, String cropCode, Repository repository) async { | |||||
| _showAlertCheckCropCode(String cropCode) async { | |||||
| var repository = Repository(); | |||||
| Get.defaultDialog(title: "Kiểm tra thông tin lô ....", middleText: "", content: CircularProgressIndicator()); | Get.defaultDialog(title: "Kiểm tra thông tin lô ....", middleText: "", content: CircularProgressIndicator()); | ||||
| try { | try { | ||||
| await repository.getPlotDetailByCode(cropCode, page: 1, size: 1).then((value) { | await repository.getPlotDetailByCode(cropCode, page: 1, size: 1).then((value) { |
| import 'dart:io'; | |||||
| import 'package:farm_tpf/presentation/custom_widgets/app_bar_widget.dart'; | |||||
| import 'package:flutter/material.dart'; | |||||
| import 'package:get/get.dart'; | |||||
| import 'package:qr_code_scanner/qr_code_scanner.dart'; | |||||
| class QrCodeScannerScreen extends StatefulWidget { | |||||
| @override | |||||
| State<StatefulWidget> createState() => _QrCodeScannerScreenState(); | |||||
| } | |||||
| class _QrCodeScannerScreenState extends State<QrCodeScannerScreen> { | |||||
| // Barcode? result; | |||||
| QRViewController controller; | |||||
| final GlobalKey qrKey = GlobalKey(debugLabel: 'QR'); | |||||
| // In order to get hot reload to work we need to pause the camera if the platform | |||||
| // is android, or resume the camera if the platform is iOS. | |||||
| @override | |||||
| void reassemble() { | |||||
| super.reassemble(); | |||||
| if (Platform.isAndroid) { | |||||
| controller.pauseCamera(); | |||||
| } | |||||
| controller.resumeCamera(); | |||||
| } | |||||
| @override | |||||
| Widget build(BuildContext context) { | |||||
| return Scaffold( | |||||
| appBar: AppBarWidget( | |||||
| isBack: true, | |||||
| ), | |||||
| body: Column( | |||||
| children: <Widget>[ | |||||
| Expanded(flex: 4, child: _buildQrView(context)), | |||||
| ], | |||||
| ), | |||||
| ); | |||||
| } | |||||
| Widget _buildQrView(BuildContext context) { | |||||
| // For this example we check how width or tall the device is and change the scanArea and overlay accordingly. | |||||
| var scanArea = (MediaQuery.of(context).size.width < 400 || MediaQuery.of(context).size.height < 400) ? 150.0 : 300.0; | |||||
| // To ensure the Scanner view is properly sizes after rotation | |||||
| // we need to listen for Flutter SizeChanged notification and update controller | |||||
| return QRView( | |||||
| key: qrKey, | |||||
| onQRViewCreated: _onQRViewCreated, | |||||
| overlay: QrScannerOverlayShape(borderColor: Colors.red, borderRadius: 10, borderLength: 30, borderWidth: 10, cutOutSize: scanArea), | |||||
| ); | |||||
| } | |||||
| void _onQRViewCreated(QRViewController controller) { | |||||
| setState(() { | |||||
| this.controller = controller; | |||||
| }); | |||||
| controller.scannedDataStream.listen((scanData) { | |||||
| if (scanData != null) { | |||||
| Get.back(result: scanData); | |||||
| } | |||||
| }); | |||||
| } | |||||
| void _onPermissionSet(BuildContext context, QRViewController ctrl, bool p) { | |||||
| if (!p) { | |||||
| ScaffoldMessenger.of(context).showSnackBar( | |||||
| const SnackBar(content: Text('no Permission')), | |||||
| ); | |||||
| } | |||||
| } | |||||
| @override | |||||
| void dispose() { | |||||
| controller?.dispose(); | |||||
| super.dispose(); | |||||
| } | |||||
| } |
| import 'package:badges/badges.dart'; | import 'package:badges/badges.dart'; | ||||
| import 'package:dio/dio.dart'; | import 'package:dio/dio.dart'; | ||||
| import 'package:farm_tpf/custom_model/NotificationObjectDTO.dart'; | import 'package:farm_tpf/custom_model/NotificationObjectDTO.dart'; | ||||
| import 'package:farm_tpf/data/repository/repository.dart'; | |||||
| import 'package:farm_tpf/data/repository/user_repository.dart'; | import 'package:farm_tpf/data/repository/user_repository.dart'; | ||||
| import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart'; | |||||
| import 'package:farm_tpf/presentation/screens/account/sc_account.dart'; | import 'package:farm_tpf/presentation/screens/account/sc_account.dart'; | ||||
| import 'package:farm_tpf/presentation/screens/control_device/sc_control_device.dart'; | import 'package:farm_tpf/presentation/screens/control_device/sc_control_device.dart'; | ||||
| import 'package:farm_tpf/presentation/screens/notification/sc_notification.dart'; | import 'package:farm_tpf/presentation/screens/notification/sc_notification.dart'; | ||||
| import 'package:farm_tpf/presentation/screens/notification/update_count_noti_bloc.dart'; | import 'package:farm_tpf/presentation/screens/notification/update_count_noti_bloc.dart'; | ||||
| import 'package:farm_tpf/presentation/screens/plot/sc_plot.dart'; | import 'package:farm_tpf/presentation/screens/plot/sc_plot.dart'; | ||||
| import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_detail.dart'; | import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_detail.dart'; | ||||
| import 'package:farm_tpf/presentation/screens/qr_scan/qr_scan_page.dart'; | |||||
| import 'package:farm_tpf/utils/NotificationsBloc.dart'; | import 'package:farm_tpf/utils/NotificationsBloc.dart'; | ||||
| import 'package:farm_tpf/utils/const_color.dart'; | import 'package:farm_tpf/utils/const_color.dart'; | ||||
| import 'package:farm_tpf/utils/const_common.dart'; | import 'package:farm_tpf/utils/const_common.dart'; | ||||
| if (index == 2) { | if (index == 2) { | ||||
| changeTabbar.changeIndex(changeTabbar.index); | changeTabbar.changeIndex(changeTabbar.index); | ||||
| // scan(context); | // scan(context); | ||||
| Get.to(QrCodeScannerScreen()).then((value) { | |||||
| if (value != null) { | |||||
| _showAlertCheckCropCode(value); | |||||
| } | |||||
| }); | |||||
| } else { | } else { | ||||
| changeTabbar.changeIndex(itemsTabbar[index].index); | changeTabbar.changeIndex(itemsTabbar[index].index); | ||||
| } | } | ||||
| })), | })), | ||||
| ))); | ))); | ||||
| } | } | ||||
| _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); | |||||
| }); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| class TabbarSelected extends GetxController { | class TabbarSelected extends GetxController { |
| url: "https://pub.dartlang.org" | url: "https://pub.dartlang.org" | ||||
| source: hosted | source: hosted | ||||
| version: "0.1.7" | version: "0.1.7" | ||||
| qr_code_scanner: | |||||
| dependency: "direct main" | |||||
| description: | |||||
| name: qr_code_scanner | |||||
| url: "https://pub.dartlang.org" | |||||
| source: hosted | |||||
| version: "0.0.14" | |||||
| quiver: | quiver: | ||||
| dependency: transitive | dependency: transitive | ||||
| description: | description: |
| flutter_svg: ^0.20.0-nullsafety.3 | flutter_svg: ^0.20.0-nullsafety.3 | ||||
| google_fonts: ^1.1.1 | google_fonts: ^1.1.1 | ||||
| ffi: ^1.0.0 | ffi: ^1.0.0 | ||||
| # qr_code_scanner: ^1.0.1 | |||||
| qr_code_scanner: ^0.0.7 | |||||
| dev_dependencies: | dev_dependencies: |