diff --git a/infinite_list/lib/src/api/fetch.dart b/infinite_list/lib/src/api/fetch.dart index 30c7f1995..ad36840a6 100644 --- a/infinite_list/lib/src/api/fetch.dart +++ b/infinite_list/lib/src/api/fetch.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:math'; import 'package:flutter/material.dart'; import 'item.dart'; @@ -30,7 +31,7 @@ Future fetchPage(int startingIndex) async { // The page of items is generated here. return ItemPage( items: List.generate( - itemsPerPage, + min(itemsPerPage, catalogLength - startingIndex), (index) => Item( color: Colors.primaries[index % Colors.primaries.length], name: 'Color #${startingIndex + index}',