某些方法正在使用null初始化。任何地方都没有警告或错误。然后我三遍检查了我认为有误的代码,但找不到任何东西。
控制台日志片段:
I / flutter(21233):W小组件库引起的异常提示 ╞═════════════════════════════════════════════════ ══════════ I / flutter(21233):在构建Builder时引发了以下NoSuchMethodError:
I / flutter(21233):方法'[]'在null上调用。
I / flutter(21233):接收方:空
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):W小工具库引起的异常CA ════════════════════════════ I / flutter(4037):在构建Builder时引发了以下CyclicInitializationError:
I / flutter(4037):在初始化期间读取静态变量'suppliesList'
I / flutter(4037):引发异常时,这是堆栈:
I / flutter(4037):#0 ButtonsLists.suppliesList(package:customer / lists.dart:26:24)
I / flutter(4037):#1个新的ButtonsLists(package:customer / lists.dart:55:54)
I / flutter(4037):#2新的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)
答案 0 :(得分:0)
我认为问题出在这里
BrowsePage(this.buttonList);
final List<Widget> buttonList;
改为尝试
final List<Widget> buttonList;
BrowsePage(this.buttonList);
答案 1 :(得分:0)
不要将列表放在登录页面和购买项目中,而是将其放在浏览页面中。