RangeError (index): Invalid value: Valid value range is empty: 0

后端 未结 8 1780
没有蜡笔的小新
没有蜡笔的小新 2021-02-12 13:26
Widget build(context) {
    try{
      if (isFirst == true) {
        fetchImage();
        fetchCategories(context);
        isFirst = false;
      }
    }catch(Excepti         


        
8条回答
  •  抹茶落季
    2021-02-12 13:38

    I assume you getting data from fetch ApI method, If you are getting data in fetchApI metod. then you should follow this

    fetchApI and is asynchronous method so it takes time to get data from json and in the begging fetchApI is empty, so it gives error of range. you can make fetchApI method asynchronous using await and async* and while calling that method use .then method and then access values.

    fetchApI().then((){ // access fetchApI over here });
    

提交回复
热议问题