# Getting a error during build this project

**URL:** <https://forums.kodeco.com/t/getting-a-error-during-build-this-project/117381>\
**Category:** Android\
**Created:** [August 13, 2020, 11:01am UTC](https://forums.kodeco.com/t/getting-a-error-during-build-this-project/117381 "2020-08-13T11:01:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pavel\_android](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/pavel_android/32/81494_2.png) [@pavel\_android](https://forums.kodeco.com/u/pavel_android)\
**Post date:** [August 13, 2020, 11:01am UTC](https://forums.kodeco.com/t/getting-a-error-during-build-this-project/117381/1 "2020-08-13T11:01:02Z")

</div>

When i run this application and enter location then I got an error in my log cat which is " Bad state: Cannot add event after closing".

LocationScreen.build. (package:restaurant\_finder/UI/location\_screen.dart:58:44)

It indicates the code  
onChanged: (query) =\> bloc.submitQuery(query),

in LocationScreen class.

So how i can fix this issue.

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [April 8, 2021, 12:36am UTC](https://forums.kodeco.com/t/getting-a-error-during-build-this-project/117381/3 "2021-04-08T00:36:25Z")

</div>



---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [April 8, 2021, 12:36am UTC](https://forums.kodeco.com/t/getting-a-error-during-build-this-project/117381/4 "2021-04-08T00:36:38Z")

</div>

@pavel_android Do you still have issues with this?

---

<div class="post-metadata">

**Author:** ![elsworthnetwor](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/elsworthnetwor/32/110455_2.png) [@elsworthnetwor](https://forums.kodeco.com/u/elsworthnetwor)\
**Post date:** [July 26, 2024, 2:25pm UTC](https://forums.kodeco.com/t/getting-a-error-during-build-this-project/117381/5 "2024-07-26T14:25:22Z")

</div>

> [@pavel\_android](#):
>
> When i run this application and enter location then I got an error in my log cat which is " Bad state: Cannot add event after closing".
> 
> LocationScreen.build. (package:restaurant\_finder/UI/location\_screen.dart:58:44)
> 
> It indicates the code  
> onChanged: (query) =\> bloc.submitQuery(query),
> 
> in LocationScreen class.
> 
> So how i can fix this issue.

The error “Bad state: Cannot add event after closing” indicates that the bloc has been closed and is no longer accepting events. Ensure that the bloc is still active when `submitQuery` is called. One way to fix this is by checking if the bloc is closed before calling `submitQuery`:

```auto
onChanged: (query) {
  if (!bloc.isClosed) {
    bloc.submitQuery(query);
  }
},

```

This should prevent the error by ensuring events are only added when the bloc is active [check here](https://lacalculadora-alicia.es/).
