尝试使用API来构建网格.一切都很好,但在最后一排瓷砖之后,页面变得空白.只是保持滚动和放大滚动& …网格是这样构建的:
body: new GridView.builder( gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: (orientation == Orientation.portrait) ? 2 : 3),itemBuilder: (BuildContext context,int index) { return new Card( child: new GridTile( footer: new Text(data[index]['name']),child: new Text(data[index]['image']),//just for testing,will fill with image later ),); },)
例外情况是我不断向下滚动空白页面,最后一个数字(包括:24)变大2倍(24,26,28等)的倍数.
I/flutter (11001): Another exception was thrown: RangeError (index): Invalid value: Not in range 0..23,inclusive: 24
有人看过GridView.builder的这种行为吗?
解决方法
您可以将项目计数传递给构建器.
例:
body: new GridView.builder( itemCount: data.length gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: (orientation == Orientation.portrait) ? 2 : 3),int index) { return new Card( child: new GridTile( footer: new Text(data[index]['name']),will fill with image later ),); },)
希望有所帮助!