问题:将函数移动到单独文件后出现的问题。

huangapple go评论93阅读模式
英文:

Issues after moving function to separate file

问题

以下是我的 initStateListView.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.

huangapple
  • 本文由 发表于 2023年3月7日 17:51:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75660350.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定