2017-12-14 30 views
0

グリッドを構築するためにAPIを使用しようとしています。すべてがうまくレンダリングしますが、タイルの最後の行の後にページが&がちょうど&をスクロール&をスクロールし続けて空白になる...グリッドがそうのように構築されています:GridView.builderは無限にスクロールするページを作成します

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で確認しましたか?

答えて

2

ビルダーにアイテム数を渡すことができます。

例:

body: new GridView.builder(
      itemCount: data.length 
      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 
      ), 
      ); 
      }, 
    ) 

助けを願っています!

+0

ありがとう@Hemanth、単に文書でそれを飛び越えました – JC23

関連する問題