title: RangeError (index): Invalid value: Valid value range is empty: 1
body: <p>after whole day of trying to solve this myself I had to come and ask for help.</p>
  
  <p>I'm trying to build this ListView.builder, it has fixed amount of itemCount. And its building Widgets using data retrieved from locally stored JSON file. </p>
  
  <p>I'm using Provider to pass that data around. The problem is, on app start or hot restart that ListView.builder turns red and shows error, and then after like quarter of a second it shows my data. </p>
  
  <p>I understand why this happens, my list of data that I get from json is initially empty. So I put ternary operator like: <code>provider.data == null ? CircularProgressIndicator() : ListView.builder...</code> but this doesnt stop it from crashing.</p>
  
  <p>I dont know why and its driving me crazy. Here is full code:</p>
  
  <p>We are talking here about widget called RecommendedCardList, its showing widgets from above mentioned list by having random number (in range of list length) as index.</p>
  
  <p>I have similar ListView on HomeScreen called CategoryCardList and its working similarly to RecommendedCardList but I'm not having this issue with it. Also the rest of the home screen shows good, only the portion where RecommendedCardList is turns red for a short period of time.</p>
  
  <p>Home Screen class:</p>
  
  <pre><code>    class HomeScreen extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      // Get user's screen properties
      // We are using this properties to adjust size accordingly
      // In order to achieve maximum responsivnes for different screen sizes
      var height = MediaQuery.of(context).size.height;
      var width = MediaQuery.of(context).size.width;
  
      var repoProvider = Provider.of&lt;Repository&gt;(context);
      var recipeDataList = repoProvider.recipeDataList;
  
      return Container(
        color: backgroundColor,
        child: repoProvider.recipeDataList == null
            ? Center(child: CircularProgressIndicator())
            : Padding(
                padding: contentPadding,
                child: ListView(
                  children: &lt;Widget&gt;[
                    AppTitle(),
                    SizedBox(
                      height: height * 0.03,
                    ),
                    Column(
                      children: &lt;Widget&gt;[
                        CategoryAndSeeAll(),
                        CategoryCardsList(height: height, provider: repoProvider),
                      ],
                    ),
                    SizedBox(
                      height: height * 0.05,
                    ),
                    Container(
                      width: double.infinity,
                      height: height * 0.1,
                      decoration: BoxDecoration(
                        border: Border.all(color: accentColor),
                      ),
                      child: Text(
                        'Reserved for AD',
                        textAlign: TextAlign.center,
                      ),
                    ),
                    SizedBox(
                      height: height * 0.05,
                    ),
                  RecommendedCardsList(height: height, width: width, recipeDataList: recipeDataList),
                  ],
                ),
              ),
      );
       }
  
  
  
         }
  </code></pre>
  
  <p>RecommendedCardsList class:</p>
  
  <pre><code>class RecommendedCardsList extends StatelessWidget {
    const RecommendedCardsList({
      Key key,
      @required this.height,
      @required this.width,
      @required this.recipeDataList,
    }) : super(key: key);
  
    final double height;
    final double width;
    final recipeDataList;
    @override
    Widget build(BuildContext context) {
  
      return Container(
              height: height * 0.30,
              child: ListView.builder(
                  scrollDirection: Axis.horizontal,
                  itemCount: numberOfRecommendedRecipes,
                  itemBuilder: (context, counter) {
                    int randomNumber = Random().nextInt(recipeDataList.length);
                    return Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: &lt;Widget&gt;[
                       RecommendedCard(
                          width: width,
                          height: height,
                          imagePath: recipeDataList.elementAt(randomNumber).image,
                          text: recipeDataList.elementAt(randomNumber).title,
                        ),
                      ],
                    );
  
                  }),
  
  
  
  
  
            );
    }
  }
  </code></pre>
  
  <p>Repository class:</p>
  
  <pre><code>class Repository extends ChangeNotifier {
    Repository() {
      loadJson();
    }
  
    var _recipeData;
  
  
    List&lt;RecipeModel&gt; _recipeDataList = [];
    List&lt;RecipeModel&gt; get recipeDataList =&gt; _recipeDataList;
  
    void loadJson() async {
  
      var json = await rootBundle.loadString('assets/recipes.json');
      var parsedJson = jsonDecode(json);
      for (var item in parsedJson) {
        _recipeData = RecipeModel.fromJson(item);
        _recipeDataList.add(_recipeData);
      }
      //print('Title:${_recipeDataList[0].title}\nImage:${_recipeDataList[0].image}'); // For debugging
  
      notifyListeners();
    }
  }
  </code></pre>