update
This commit is contained in:
parent
11fc5c43bf
commit
41651ae447
13 changed files with 237 additions and 125 deletions
|
|
@ -1,11 +1,9 @@
|
|||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
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/functions/barcode_scan_function.dart';
|
||||
import 'package:pharmacy_mobile/functions/checkresult_function.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';
|
||||
|
|
@ -44,7 +42,6 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
final _storage = Storage();
|
||||
final _nameController = TextEditingController();
|
||||
final _barcodeController = TextEditingController();
|
||||
final FocusNode _focusNode = FocusNode();
|
||||
bool _isLoading = false;
|
||||
|
||||
late List _genericNameList = [];
|
||||
|
|
@ -58,21 +55,21 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
late bool imageUploaded = false;
|
||||
late String imageUrl = '';
|
||||
|
||||
void _checkResult(List list, String name) {
|
||||
if (list.isEmpty) {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: No $name Found', false);
|
||||
// void _checkResult(List list, String name) {
|
||||
// if (list.isEmpty) {
|
||||
// if (mounted) {
|
||||
// showNotification(context, 'Error: No $name Found', false);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
context.push('/main');
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
setState(() => {});
|
||||
}
|
||||
}
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// if (mounted) {
|
||||
// context.push('/main');
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// } else {
|
||||
// setState(() => {});
|
||||
// }
|
||||
// }
|
||||
|
||||
// Future<Uint8List> compressFile(XFile file) async {
|
||||
// var result = await FlutterImageCompress.compressWithFile(
|
||||
|
|
@ -85,28 +82,32 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
// return result;
|
||||
// }
|
||||
|
||||
void _getGenerics() async {
|
||||
Future<void> _getGenerics() async {
|
||||
_genericNameList = await _refGenericNames.getList();
|
||||
_checkResult(_genericNameList, 'Generics');
|
||||
setState(() {
|
||||
checkResult(context, _genericNameList, 'Generics');
|
||||
});
|
||||
}
|
||||
|
||||
void _getTypes() async {
|
||||
Future<void> _getTypes() async {
|
||||
_typeList = await _refTypes.getList();
|
||||
_checkResult(_typeList, 'Types');
|
||||
setState(() {
|
||||
checkResult(context, _typeList, 'Types');
|
||||
});
|
||||
}
|
||||
|
||||
void _getManufactorer() async {
|
||||
Future<void> _getManufactorer() async {
|
||||
_manufactorerList = await _refManufactorer.getList();
|
||||
_checkResult(_manufactorerList, 'Manufactorer');
|
||||
setState(() {
|
||||
checkResult(context, _manufactorerList, 'Manufactorer');
|
||||
});
|
||||
}
|
||||
|
||||
void autoRun() async {
|
||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||
_getGenerics();
|
||||
_getTypes();
|
||||
_getManufactorer();
|
||||
|
||||
setState(() {});
|
||||
await _getGenerics();
|
||||
await _getTypes();
|
||||
await _getManufactorer();
|
||||
|
||||
// final sample = await _refMedicines.getList2();
|
||||
} else {
|
||||
|
|
@ -139,20 +140,20 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
}
|
||||
|
||||
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 ?? '' : '';
|
||||
// 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 = await barcodeScan(context);
|
||||
}
|
||||
|
||||
void _saveMedicine() async {
|
||||
|
|
@ -214,7 +215,6 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
@override
|
||||
void dispose() {
|
||||
_nameController.dispose();
|
||||
_focusNode.dispose();
|
||||
_barcodeController.dispose();
|
||||
|
||||
_genericNameList = [];
|
||||
|
|
|
|||
|
|
@ -1,17 +1,25 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:internet_connection_checker/internet_connection_checker.dart';
|
||||
import 'package:pharmacy_mobile/functions/barcode_scan_function.dart';
|
||||
import 'package:pharmacy_mobile/functions/checkresult_function.dart';
|
||||
import 'package:pharmacy_mobile/security/encryption.dart';
|
||||
import 'package:pharmacy_mobile/tables/ref_medicines.dart';
|
||||
import 'package:pharmacy_mobile/tables/stocks.dart';
|
||||
import 'package:pharmacy_mobile/widgets/button_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/datepicker_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/dropdown_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/dropdown_wrappermulti_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/form_border_widget2.dart';
|
||||
import 'package:pharmacy_mobile/widgets/input_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/page_background_widget.dart';
|
||||
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';
|
||||
|
||||
class AddStockPage extends StatefulWidget {
|
||||
|
|
@ -23,10 +31,10 @@ class AddStockPage extends StatefulWidget {
|
|||
|
||||
class _AddStockPageState extends State<AddStockPage> with WidgetsBindingObserver {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final FocusNode _focusNode = FocusNode();
|
||||
final _refMedicines = RefMedicines();
|
||||
final _quantityController = TextEditingController();
|
||||
final _dateController = TextEditingController();
|
||||
final _medicineController = TextEditingController();
|
||||
final _stocks = Stocks();
|
||||
|
||||
final bool _isLoading = false;
|
||||
|
|
@ -36,10 +44,42 @@ class _AddStockPageState extends State<AddStockPage> with WidgetsBindingObserver
|
|||
late DateTime selectedDate = DateTime.now();
|
||||
late String barcode = '';
|
||||
|
||||
void autoRun() async {
|
||||
_medicineList = await _refMedicines.getList();
|
||||
// void autoRun() async {
|
||||
// _medicineList = await _refMedicines.getList();
|
||||
// }
|
||||
|
||||
void _getMedicines() async {
|
||||
_medicineList = await _refMedicines.getList2();
|
||||
|
||||
setState(() {
|
||||
checkResult(context, _medicineList, 'Medicines');
|
||||
});
|
||||
}
|
||||
|
||||
void autoRun() async {
|
||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||
_getMedicines();
|
||||
} else {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: No Internet Connection', false);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
context.push('/main');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Future<bool> _getMedicines() async {
|
||||
// late bool? result;
|
||||
// _medicineList = await _refMedicines.getList();
|
||||
// if (mounted) {
|
||||
// result = await checkResult(context, _medicineList, 'Medicines');
|
||||
// log(result.toString());
|
||||
// }
|
||||
// return result ?? false;
|
||||
// }
|
||||
|
||||
void _updateMedicine(dynamic medicine) {
|
||||
_selectedMedicine = medicine;
|
||||
}
|
||||
|
|
@ -52,15 +92,24 @@ class _AddStockPageState extends State<AddStockPage> with WidgetsBindingObserver
|
|||
await _stocks.postStock(stockNameUUID, stockExpiration, stockQuantity);
|
||||
}
|
||||
|
||||
Future<void> _scanBarcode() async {
|
||||
_selectedMedicine = await barcodeScan(context);
|
||||
}
|
||||
|
||||
Future<String> _getMedicineUsingBarcode(String name) async {
|
||||
final encryptedBarcode = await _refMedicines.getBarcode(name);
|
||||
final barcode = decrypt(encryptedBarcode);
|
||||
return barcode;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
autoRun();
|
||||
_getMedicines();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_focusNode.dispose();
|
||||
_medicineList = [];
|
||||
_selectedMedicine = '';
|
||||
_quantityController.dispose();
|
||||
|
|
@ -89,13 +138,52 @@ class _AddStockPageState extends State<AddStockPage> with WidgetsBindingObserver
|
|||
child: Form(
|
||||
key: _formKey,
|
||||
child: Center(
|
||||
child: Column(
|
||||
child: DropdownWrapperMultiWidget(
|
||||
list: _medicineList,
|
||||
text: 'Data',
|
||||
children: [
|
||||
DropDownWidget(
|
||||
label: 'Medicine Name',
|
||||
list: _medicineList,
|
||||
listTitle: 'medicine_name',
|
||||
onChanged: _updateMedicine),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: _scanBarcode,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
// color: const Color.fromARGB(0, 36, 18, 58),
|
||||
// boxShadow: [
|
||||
// BoxShadow(
|
||||
// color: Colors.black26,
|
||||
// blurRadius: 5.0,
|
||||
// offset: Offset(0, 2),
|
||||
// ),
|
||||
// ],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.qr_code_scanner,
|
||||
color: Colors.white,
|
||||
size: 22,
|
||||
),
|
||||
const Gap(8),
|
||||
TextWidget(
|
||||
text: 'Scan Barcode',
|
||||
size: 14,
|
||||
color: Colors.white,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const Gap(16),
|
||||
InputWidget(label: 'Quantity', controller: _quantityController),
|
||||
const Gap(16),
|
||||
|
|
@ -107,28 +195,6 @@ class _AddStockPageState extends State<AddStockPage> with WidgetsBindingObserver
|
|||
const Gap(32),
|
||||
ButtonWidget(text: 'Add Stock', onPressed: _saveStock),
|
||||
const Gap(16),
|
||||
ButtonWidget(
|
||||
text: 'Barcode',
|
||||
onPressed: () async {
|
||||
String? bc = 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,
|
||||
);
|
||||
setState(() {
|
||||
barcode = bc as String;
|
||||
});
|
||||
},
|
||||
),
|
||||
const Gap(16),
|
||||
TextWidget(
|
||||
text: barcode,
|
||||
size: 14,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue