BAD STATE NO ELEMENT

1,633 views
Skip to first unread message

Emily Walton

unread,
Feb 25, 2021, 7:18:28 AM2/25/21
to Flutter Development (flutter-dev)
In this code I am trying to load a list from the database but the error shows bad state no element the first time I run it but when I hot reload the error disappears. Please help how can I solve this problem
List<ItemClass> getPathList(int id) {
print('Entered in get Path List');
int tempId = id;
List<ItemClass> tempPathList = List<ItemClass>();
List<ItemClass> tempo = List<ItemClass>();

while (tempId != 0) {
getItemFromId(id);
tempo = this.itemFromIdList;
THIS LINE CAUSING PROBLEM ItemClass temp = (tempo)?.first ?? [];<<<<<<<--------

tempPathList.add(temp);
tempId = temp.parent;

}

return tempPathList;
}

Emily Walton

unread,
Feb 25, 2021, 7:22:19 AM2/25/21
to Flutter Development (flutter-dev)
Future<void> getItemFromId(int id) async {
final Future<Database> dbFuture = databaseHelper.initializeDatabase();
dbFuture.then((database) {
Future<List<ItemClass>> itemListFromIdFuture =
databaseHelper.getItemListFromId(id);

itemListFromIdFuture.then((itemList) {
this.itemFromIdList = itemList;

//this.fullCount = itemList.length;
});
});
}
This is the code for getItemFromId which retrieves the itemList

--
You received this message because you are subscribed to a topic in the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/flutter-dev/AS81gxKXuc4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/cf849a84-b5a1-406d-a8e4-5a3a7f7e36e3n%40googlegroups.com.

Suzuki Tomohiro

unread,
Feb 25, 2021, 7:49:25 AM2/25/21
to Emily Walton, Flutter Development (flutter-dev)
Set a breakpoint at the line that causes the problem.

I think you will see “tempo” is an empty list when the problem happens.



You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/CAKM8LdC6L%2BxG0V-qLdUHH-%3D%2B-YujXQD2Ov5YE70Vephk6kSScQ%40mail.gmail.com.

Suzuki Tomohiro

unread,
Feb 25, 2021, 8:29:34 AM2/25/21
to Flutter Development (flutter-dev)
(Please respond to the mailing list)

What was the value of “tempo” when you use the breakpoint?
Both failed case and successful case.

On Thu, Feb 25, 2021 at 08:23 Emily Walton <whyth...@gmail.com> wrote:
yes i was suspecting that already but how do i solve this issue. Because when I hot reload, it gets filled up and hence no error.

Suzuki Tomohiro

unread,
Feb 25, 2021, 9:09:05 AM2/25/21
to Flutter Development (flutter-dev)
(Please respond to the mailing list; otherwise I stop responding to you)

Good. You know the problem is. “tempo” was empty.

Would you check why it becomes empty?
Or, if it’s ok to be empty, how should it behave when it’s zero?


On Thu, Feb 25, 2021 at 09:01 Emily Walton <whyth...@gmail.com> wrote:
earlier the length was 0 when it was not working and when it works after hot reload then the length is 1

Benedicte Roussel

unread,
Feb 25, 2021, 9:49:36 AM2/25/21
to Suzuki Tomohiro, Flutter Development (flutter-dev)

Doesn't t (tempo)?  Means it can be null while you want it to be !=0? 

Le jeu., févr. 25, 2021 à 15:09, Suzuki Tomohiro
<suz...@gmail.com> a écrit :

Emily Walton

unread,
Feb 25, 2021, 10:58:01 PM2/25/21
to Flutter Development (flutter-dev)
I thought (tempo)? will help to make tempo =[] if it is null. The main problem here is I want to update the-> this.itemFromIdList without reloading or resetting the state. 

Suzuki Tomohiro

unread,
Feb 26, 2021, 8:30:04 AM2/26/21
to Emily Walton, Flutter Development (flutter-dev)
Null and an empty list are different. As per your observation, your error was caused by an empty list.

Bened

unread,
Feb 26, 2021, 1:10:44 PM2/26/21
to Flutter Development (flutter-dev)
tempo =[]  the time it loads

Bened

unread,
Feb 26, 2021, 2:56:35 PM2/26/21
to Flutter Development (flutter-dev)
think you should focus on how to write correct Future (async)

MANDEEP BIYANI

unread,
Feb 27, 2021, 4:02:01 AM2/27/21
to Bened, Flutter Development (flutter-dev)
I want to know how i can make custom tabbar. Just ike this

tababt.PNG

Benedicte Roussel

unread,
Feb 27, 2021, 5:45:59 AM2/27/21
to MANDEEP BIYANI, Flutter Development (flutter-dev)
@biyani, you are in the thread of Emily. Try to open your own question. That looks like custom shapes with some icons stacked. 
please open your own thread

Benedicte Roussel

unread,
Feb 27, 2021, 5:59:03 AM2/27/21
to MANDEEP BIYANI, Flutter Development (flutter-dev)
Reply all
Reply to author
Forward
0 new messages