英文:
Issues after moving function to separate file
问题
以下是我的 initState
和 ListView.builder
的代码。refreshShoppingItems
函数已经移动到另一个文件中。现在我的 ListView.builder
不再显示来自 sqflite 数据库的任何信息。
ListView.builder(
shrinkWrap: true,
itemCount: shoppingItems.length,
itemBuilder: (context, index) {
return GenericTile(
gradient: const LinearGradient(colors: [
Color.fromARGB(255, 80, 107, 86),
Color fromARGB(255, 16, 187, 121),
]),
taskName: shoppingItems[index]['title'],
taskCompleted: false,
onTapped: () {},
showDeleteButton: true,
showEditButton: true,
onDeletePressed: () => deleteShoppingItem(
shoppingItems[index]['id'],
context,
),
onEditPressed: () => _showItemForm(
shoppingItems[index]['id'],
),
);
},
),
@override
void initState() {
_tabController = TabController(length: 3, vsync: this);
super.initState();
refreshShoppingItems(data, _isLoading, () {
setState(() {
shoppingItems = data;
});
});
print("..number of items ${shoppingItems.length}");
}
void refreshShoppingItems(
List shoppingItems,
bool isLoading,
Function setState,
) async {
final data = await SQLHelper_Shopping.getItems();
setState(() {
shoppingItems.clear();
shoppingItems.addAll(data);
});
}
对一些东西进行了编辑,但我有点卡住了。
英文:
Below is the code of my initState
and ListView.builder
. The refreshShoppingItems
function has been moved to a different file. Now my ListView.builder
does not show any information from my sqflite database anymore
ListView.builder(
shrinkWrap: true,
itemCount: shoppingItems.length,
itemBuilder: (context, index) {
return GenericTile(
gradient: const LinearGradient(colors: [
Color.fromARGB(255, 80, 107, 86),
Color.fromARGB(255, 16, 187, 121),
]),
taskName: shoppingItems[index]['title'],
taskCompleted: false,
onTapped: () {},
showDeleteButton: true,
showEditButton: true,
onDeletePressed: () => deleteShoppingItem(
shoppingItems[index]['id'],
context,
),
onEditPressed: () => _showItemForm(
shoppingItems[index]['id'],
),
);
},
),
@override
void initState() {
_tabController = TabController(length: 3, vsync: this);
super.initState();
refreshShoppingItems(data, _isLoading, () {
setState(() {
shoppingItems = data;
});
});
print("..number of items ${shoppingItems.length}");
}
void refreshShoppingItems(
List shoppingItems,
bool isLoading,
Function setState,
) async {
final data = await SQLHelper_Shopping.getItems();
setState(() {
shoppingItems.clear();
shoppingItems.addAll(data);
});
}
Editing a couple of things but im kinda stuck
答案1
得分: 1
Reverting back to a previous commit has solved my issues. I will tackle this in a later state when adding proper state management for this part of the app.
英文:
Reverting back to a previous commit has solved my issues. I will tackle this in a later state when adding proper state management for this part of the app.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论