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

后端 未结 8 1779
没有蜡笔的小新
没有蜡笔的小新 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

    The problem can be that you are trying to access a variable/array that is not ready yet (maybe because the future/api call is not finished)

    A quick workaround could be to check the length of the array or check for null, example:

    Text( (myArray?.length > 0 ? myArray[0] : '') );
    

提交回复
热议问题