找不到使用null的方法

问题描述 投票:0回答:2

有些方法是使用null初始化。任何地方都没有警告或错误。我三重检查了我认为有错的代码,但我找不到任何东西。

控制台日志片段:

I / flutter(21233):══╡WIDGETS LIBRARY的例外情况╞═​​═══════════════════════════════════════════════════════════════════════════════════════════════════ ══════════════════════════════════════════════════════════════════════════════════════════════════I

I / flutter(21233):方法'[]'在null上调用。

I / flutter(21233):Receiver:null

I / flutter(21233):试着打电话:

I / flutter(21233):抛出异常时,这就是堆栈:

I / flutter(21233):#0 Object.noSuchMethod(dart:core / runtime / libobject_patch.dart:50:5)

I / flutter(21233):#1 ButtonsLists.foodList(package:customer / lists.dart:35:71)

I / flutter(21233):#2 ButtonsLists.foodList(package:customer / lists.dart:33:24)

=========================================================================

https://gist.github.com/Norman518/17be934d342b7523e80c7abc2e40aced

 final List<MainButtons> buttonList = [
    MainButtons(Icons.domain, 'Class Supplies', Page(suppliesList)),
    MainButtons(Icons.local_dining, 'Food and Snacks', Page(foodList)),
    MainButtons(Icons.hot_tub, 'Personal Supplies', Page(toiletriesList)),
    MainButtons(Icons.local_cafe, 'Drinks', Page(drinksList))
  ];
  MainButtons(this.image, this.name, this.onTap);

  final IconData image;
  final String name;
  final Route onTap;
  .
  .
  .
   onTap: () {
         Navigator.of(context).push(onTap);
       },

=========================================================================

我希望能够显示四个墨水瓶按钮。

=========================================================================

这是更改,这是控制台输出

I / flutter(4037):══╡WIDGETS LIBRARY的例外情况╞═​​═════════════════════════════════════════════════════════════════════════════════════════════════════ ════════════════════════════════════════════════════════════════════════════════════════════════>>

I / flutter(4037):在初始化期间读取静态变量'suppliesList'

I / flutter(4037):当抛出异常时,这就是堆栈:

I / flutter(4037):#0 ButtonsLists.suppliesList(package:customer / lists.dart:26:24)

I / flutter(4037):#1 new ButtonsLists(package:customer / lists.dart:55:54)

I / flutter(4037):#2 new BuyItem(package:customer / buyItem.dart:66:35)

I / flutter(4037):#3 ButtonsLists.buyItemList(package:customer / lists.dart:8:5)

I / flutter(4037):#4 ButtonsLists.buyItemList(package:customer / lists.dart:7:23)

dart flutter
2个回答
0
投票

我认为问题出在这里

BrowsePage(this.buttonList);
final List<Widget> buttonList;

而是试试这种方式

 final List<Widget> buttonList;
 BrowsePage(this.buttonList);

0
投票

不要将列表放在登录页面和buyitem中,将其放在浏览页面中。

© www.soinside.com 2019 - 2024. All rights reserved.