我正在嘗試制作一個串列視圖,顯示對某個數字的添加。在圖中,我正在嘗試為 ListView 中的 16 個步驟生成一個加法表。它在加載時看起來很好,但在滾動頂部和底部元素后會自動更新。這個問題只有在基本控制ListView中item個數的變數tableSize的值超過15的時候才明顯,這個問題怎么解決??

// tableSize = 16 && tCount = 10
這是代碼
return ListView.builder(
key: UniqueKey(),
padding: EdgeInsets.symmetric(horizontal: 5),
itemCount: DataFile.tableSize,
scrollDirection: Axis.vertical,
itemBuilder: (context, index) {
tCount = tCount 1;
String title;
print(" Tcount = ${tCount}");
if (sign == DataFile.divisionSign) {
double ans = tableNo / tCount;
title = tableNo.toString()
space
sign
space
tCount.toString()
space
equal
space
f.format(ans);
} else {
int ans;
if (sign == DataFile.additionSign) {
ans = tableNo tCount;
} else if (sign == DataFile.subtractionSign) {
ans = tableNo - tCount;
} else {
ans = tableNo * tCount;
}
title = tableNo.toString()
space
space
sign
space
space
tCount.toString()
space
space
equal
space
space
int.parse(ans.toString()).toString();
print(title);
}
return InkWell(
child: Container(
height: cellHeight,
margin: EdgeInsets.symmetric(
vertical: ConstantData.getScreenPercentSize(context, 2.3)),
child: Center(
child: ConstantWidget.getTextWidget(
title,
ConstantData.textColors!,
ConstantData.getPercentSize(cellHeight, 98),
FontWeight.w500,
TextAlign.center),
),
),
onTap: () {},
);
},
);
uj5u.com熱心網友回復:
tCount需要更改,它是狀態變數中的可變資料。
使用此代碼:
return ListView.builder(
key: UniqueKey(),
padding: EdgeInsets.symmetric(horizontal: 5),
itemCount: DataFile.tableSize,
scrollDirection: Axis.vertical,
itemBuilder: (context, index) {
tCount = index 1; //change here
String title;
print(" Tcount = ${tCount}");
if (sign == DataFile.divisionSign) {
double ans = tableNo / tCount;
title = tableNo.toString()
space
sign
space
tCount.toString()
space
equal
space
f.format(ans);
} else {
int ans;
if (sign == DataFile.additionSign) {
ans = tableNo tCount;
} else if (sign == DataFile.subtractionSign) {
ans = tableNo - tCount;
} else {
ans = tableNo * tCount;
}
title = tableNo.toString()
space
space
sign
space
space
tCount.toString()
space
space
equal
space
space
int.parse(ans.toString()).toString();
print(title);
}
return InkWell(
child: Container(
height: cellHeight,
margin: EdgeInsets.symmetric(
vertical: ConstantData.getScreenPercentSize(context, 2.3)),
child: Center(
child: ConstantWidget.getTextWidget(
title,
ConstantData.textColors!,
ConstantData.getPercentSize(cellHeight, 98),
FontWeight.w500,
TextAlign.center),
),
),
onTap: () {},
);
},
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/478162.html
