mirror of
https://git.meshkee.com/applications/cssd.git
synced 2026-10-11 23:38:56 +03:30
Fix scan bug
This commit is contained in:
@@ -3,7 +3,9 @@ import 'dart:convert';
|
||||
import 'package:cssd/models/item_model.dart';
|
||||
import 'package:cssd/models/package_model.dart';
|
||||
import 'package:flutter_downloader/flutter_downloader.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:cssd/utils/scan.dart';
|
||||
|
||||
import '../config/urls.dart';
|
||||
import '../config/user.dart';
|
||||
@@ -78,16 +80,55 @@ class PackageProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
var isCurrectItem = false;
|
||||
|
||||
changeItemValByScan(String value, int index) async {
|
||||
filteredItems?.forEach((item) {
|
||||
if (item.id == value) {
|
||||
itemValues[index].text = "${item.name} - ${item.udi}";
|
||||
isCurrectItem = true;
|
||||
}
|
||||
print("item value : ${itemValues[index].text}");
|
||||
});
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void scanItem(isEnabled, context, index) async {
|
||||
await scan().then(
|
||||
(String result) async {
|
||||
if (result == 'cancel') {
|
||||
if (index != 0) await removeItemVal();
|
||||
print('cancel');
|
||||
} else if (result == 'error') {
|
||||
print('error');
|
||||
} else if (result == 'access') {
|
||||
print('access');
|
||||
} else {
|
||||
await changeItemValByScan(result, index);
|
||||
isEnabled = false;
|
||||
print("currect item : ${isCurrectItem}");
|
||||
if (isCurrectItem) {
|
||||
Fluttertoast.showToast(
|
||||
msg: "Item added.",
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
);
|
||||
scanItem(isEnabled, context, index += 1);
|
||||
await addItemVal();
|
||||
isCurrectItem = false;
|
||||
} else {
|
||||
Fluttertoast.showToast(
|
||||
msg: "No item exists,try again!",
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
);
|
||||
scanItem(isEnabled, context, index);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
String searchBoxValue = '';
|
||||
bool filterOn = false;
|
||||
List<PackageResultObject>? items;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import 'package:cssd/providers/packages.dart';
|
||||
import 'package:cssd/utils/scan.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
@@ -170,8 +168,10 @@ class AddItemBox extends StatelessWidget {
|
||||
),
|
||||
Spacer(),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
ScanItem(isEnabled, context, index);
|
||||
onTap: () async {
|
||||
Provider.of<PackageProvider>(context,
|
||||
listen: false)
|
||||
.scanItem(isEnabled, context, index);
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
@@ -242,33 +242,4 @@ class AddItemBox extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void ScanItem(isEnabled, context, index) async {
|
||||
await scan().then(
|
||||
(String result) async {
|
||||
if (result == 'cancel') {
|
||||
if (index != 0)
|
||||
await Provider.of<PackageProvider>(context, listen: false)
|
||||
.removeItemVal();
|
||||
print('cancel');
|
||||
} else if (result == 'error') {
|
||||
print('error');
|
||||
} else if (result == 'access') {
|
||||
print('access');
|
||||
} else {
|
||||
await Provider.of<PackageProvider>(context, listen: false)
|
||||
.changeItemValByScan(result, index);
|
||||
isEnabled = false;
|
||||
Fluttertoast.showToast(
|
||||
msg: "Item added.",
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
);
|
||||
ScanItem(isEnabled, context, index += 1);
|
||||
await Provider.of<PackageProvider>(context, listen: false)
|
||||
.addItemVal();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user