update
This commit is contained in:
parent
b299297fa5
commit
11fc5c43bf
29 changed files with 1041 additions and 124 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
|
|
@ -5,6 +6,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:gap/gap.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:internet_connection_checker/internet_connection_checker.dart';
|
||||
import 'package:pharmacy_mobile/security/encryption.dart';
|
||||
import 'package:pharmacy_mobile/tables/ref_categories.dart';
|
||||
import 'package:pharmacy_mobile/tables/ref_generic_names.dart';
|
||||
import 'package:pharmacy_mobile/tables/ref_manufactorers.dart';
|
||||
|
|
@ -21,6 +23,7 @@ import 'package:pharmacy_mobile/widgets/snackbar_widget.dart';
|
|||
import 'package:pharmacy_mobile/widgets/text_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/title_widget.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:simple_barcode_scanner/simple_barcode_scanner.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
import 'package:flutter_image_compress/flutter_image_compress.dart';
|
||||
|
||||
|
|
@ -40,6 +43,7 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
final _refMedicines = RefMedicines();
|
||||
final _storage = Storage();
|
||||
final _nameController = TextEditingController();
|
||||
final _barcodeController = TextEditingController();
|
||||
final FocusNode _focusNode = FocusNode();
|
||||
bool _isLoading = false;
|
||||
|
||||
|
|
@ -134,17 +138,37 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
_selectedManufactorer = manufactorer;
|
||||
}
|
||||
|
||||
Future<void> _scanBarcode() async {
|
||||
String? barcode = await SimpleBarcodeScanner.scanBarcode(
|
||||
context,
|
||||
// barcodeAppBar: const BarcodeAppBar(
|
||||
// // appBarTitle: 'Test',
|
||||
// // centerTitle: false,
|
||||
// // enableBackButton: false,
|
||||
// // backButtonIcon: Icon(Icons.arrow_back_ios),
|
||||
// ),
|
||||
// isShowFlashIcon: true,
|
||||
delayMillis: 2000,
|
||||
scanType: ScanType.barcode,
|
||||
cameraFace: CameraFace.back,
|
||||
);
|
||||
_barcodeController.text = barcode != '-1' ? barcode ?? '' : '';
|
||||
}
|
||||
|
||||
void _saveMedicine() async {
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
try {
|
||||
final String encrpytedBarcode = await encrypt(_barcodeController.text);
|
||||
|
||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||
final medName = _nameController.text;
|
||||
final medGenericUUID = await _refGenericNames.getUUID(_selectedGeneric);
|
||||
final medTypeUUID = await _refTypes.getUUID(_selectedType);
|
||||
final medManufactorerUUID = await _refManufactorer.getUUID(_selectedManufactorer);
|
||||
|
||||
await _refMedicines.postMedicine(uuid, medName, medManufactorerUUID, medGenericUUID, medTypeUUID);
|
||||
await _refMedicines.postMedicine(
|
||||
uuid, medName, medManufactorerUUID, medGenericUUID, medTypeUUID, encrpytedBarcode);
|
||||
} else {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: No Internet Connection', false);
|
||||
|
|
@ -191,6 +215,7 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
void dispose() {
|
||||
_nameController.dispose();
|
||||
_focusNode.dispose();
|
||||
_barcodeController.dispose();
|
||||
|
||||
_genericNameList = [];
|
||||
_selectedGeneric = '';
|
||||
|
|
@ -245,6 +270,10 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
list: _manufactorerList,
|
||||
listTitle: 'manufactorer_name',
|
||||
onChanged: _updateManufactorer),
|
||||
const Gap(16),
|
||||
InputWidget(label: 'Barcode', controller: _barcodeController),
|
||||
const Gap(8),
|
||||
ButtonWidget(text: 'Scan Barcode', onPressed: _scanBarcode),
|
||||
const Gap(32),
|
||||
if (imageUrl.isNotEmpty)
|
||||
Center(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue