update
This commit is contained in:
parent
cbf2ff062f
commit
7886eeb6c2
26 changed files with 210 additions and 228 deletions
|
|
@ -1,10 +1,14 @@
|
|||
import 'dart:convert';
|
||||
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';
|
||||
import 'package:pharmacy_mobile/tables/ref_manufactorers.dart';
|
||||
|
|
@ -22,7 +26,6 @@ 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';
|
||||
|
||||
|
|
@ -161,7 +164,8 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
setState(() => _isLoading = true);
|
||||
|
||||
try {
|
||||
final String encrpytedBarcode = await encrypt(_barcodeController.text);
|
||||
// final String encrpytedBarcode = await encrypt(_barcodeController.text);
|
||||
final String encrpytedBarcode = _barcodeController.text;
|
||||
|
||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||
final medName = _nameController.text;
|
||||
|
|
@ -187,16 +191,19 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
|
||||
void _addImage() async {
|
||||
final imageName = Uuid().v4();
|
||||
uuid = imageName;
|
||||
|
||||
final ImagePicker picker = ImagePicker();
|
||||
final XFile? image = await picker.pickImage(source: ImageSource.gallery);
|
||||
final XFile? image = await picker.pickImage(source: ImageSource.gallery, imageQuality: 100);
|
||||
const storageName = 'ref_medicines_images';
|
||||
|
||||
if (image == null) {
|
||||
return;
|
||||
}
|
||||
final imageBytes = await image!.readAsBytes();
|
||||
final webpImage = await _webpConvert(imageBytes);
|
||||
|
||||
imageUrl = await _storage.uploadImage(context, storageName, image, '$imageName.webp');
|
||||
uuid = imageName;
|
||||
|
||||
if (mounted) {
|
||||
imageUrl = await _storage.uploadImage(context, storageName, webpImage, '$imageName.webp');
|
||||
}
|
||||
|
||||
setState(() {
|
||||
if (imageUrl.isEmpty) {
|
||||
|
|
@ -207,6 +214,19 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
});
|
||||
}
|
||||
|
||||
Future<Uint8List> _webpConvert(Uint8List file) async {
|
||||
final result = await FlutterImageCompress.compressWithList(
|
||||
file,
|
||||
// minHeight: 1080,
|
||||
// minWidth: 1080,
|
||||
quality: 75,
|
||||
rotate: 0,
|
||||
keepExif: false,
|
||||
format: CompressFormat.webp,
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
autoRun();
|
||||
|
|
@ -261,7 +281,10 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
listTitle: 'generic_name',
|
||||
onChanged: _updateGeneric),
|
||||
const Gap(8),
|
||||
TextWidget(text: _selectedCategory, size: 18),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 12),
|
||||
child: TextWidget(text: _selectedCategory, size: 18),
|
||||
),
|
||||
const Gap(16),
|
||||
DropDownWidget(
|
||||
label: 'Type', list: _typeList, listTitle: 'type_name', onChanged: _updateType),
|
||||
|
|
@ -282,7 +305,11 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
child: Image.network(imageUrl, fit: BoxFit.cover, width: 250, height: 250)),
|
||||
)
|
||||
else
|
||||
ButtonWidget(text: 'Add Image', onPressed: _addImage),
|
||||
ButtonWidget(
|
||||
text: 'Add Image',
|
||||
onPressed: _addImage,
|
||||
outline: true,
|
||||
),
|
||||
const Gap(32),
|
||||
if (_isLoading)
|
||||
const Center(child: CircularProgressIndicator(color: Colors.white))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue