我有一个问题,不知道如何在我的情况下正确使用 if 语句,我执行 sql 查询并返回数据,所以我创建了 If 语句,当 Needed-Scanned=0 时增加索引,
基本上它的意思是,当没有任何东西剩下时转到下一个数据,但它不起作用或在第一次迭代后结束。所以接下来我确实尝试使用 Setstate(){ Index ++; } 我有以下错误:
Expanded(
child: FutureBuilder<List?>(
future: read( // "SELECT ProductAdress, ProductSeriesDescr+' ' ProductSeriesDescr, replace(ProductName, '\"', '')ProductName, NeedCount+'' NeedCount, ScanCount+'' ScanCount, ProductBarCode, ProductSeriesCount, ProductExpirationDate FROM ScanRest WHERE ProductStation = '${widget.nrStatie}' AND BoxID = '$cutieScan' Order By ProductName ASC"),
"SELECT ProductAdress, NeedCount+' ' NeedCount, ProductSeriesDescr+' ' ProductSeriesDescr, replace(ProductName, '\"', '')ProductName, ScanCount+' ' ScanCount, ProductSeriesCount+' ' ProductSeriesCount, ProductExpirationDate, ProductBarCode FROM ScanRest WHERE ProductStation = '${widget.nrStatie}' AND BoxID = '$cutieScan' Order By ProductAdress ASC"), // OrderDate = Cast(getdate() as date)
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return const Text('Loading....');
default:
if (snapshot.hasError) {
debugPrint("call error ${snapshot.error}"); //"call error = ${snapshot.error}"
return Text('Error: ${snapshot.error}');
}
debugPrint(
"call success din sql"); // "call success = ${snapshot.data}"
List data = snapshot.data ?? [];
if (snapshot.data!.isEmpty) {
return Visibility(
visible: !vizibil,
child: Column(children: [
const Text('Barcode gresit sau statie goala'),
IconButton(
onPressed: () {
Navigator.push(context,
MaterialPageRoute(
builder: (context) => widget));
},
icon: const Icon(Icons.replay_outlined)),
]));
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
if (int.parse((data[index]as Map)['NeedCount'].toString()) - int.parse((data[index]as Map)['ScanCount'].toString()) == 0){
index ++;
if(index == snapshot.data?.length){
Navigator.push( context,
MaterialPageRoute( builder: (context) => dita_lista(
nrStatie: widget.nrStatie,
cutieScan: cutieScan,
)));
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
}
debugPrint(index.toString());
return SingleChildScrollView(
child: Column(
children: [
const SizedBox(height: 10),
Row(
children: [
Expanded(
flex: 3,
child: Text((data[index]as Map)['ProductAdress'].toString(),textAlign: TextAlign.center,
style: const TextStyle(fontSize: 40),)),