0

I have a Future that is called in the initState(), it makes an http request and saves data in Model class.

It needs to be called very first because there are other streams waiting to for it to get the data so they can rebuild themselves.

But the problem is if I push and quickly pop the route few seconds later I can still see the Future printing response logs which I wrote to it to execute when it's completed. That means the process was active in the background right?

How do I structure my project so that as the route is popped it forcefully terminates the Future request?

@override
void initState() {
  // TODO: implement initState
  super.initState();
  wrapperMovieBloC();
}

void wrapperMovieBloC() async {
  //wait till get data is complete
  await movieBloc.getContentDetails();
  //now we have data such as rating,genres
  //I can invoke correspedoning methods which will rebuild themselves
  movieBloc.buildRatings();
  movieBloc.getGenreList();
}

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    movieBloc.dispose();
  }

I'm using BloC pattern not with any community based Bloc providers packages just trying to follow the main theory of bloc pattern.

Nadeem Siddique
  • 1,988
  • 4
  • 14
  • 20
  • Can you share more about your code(especially build method)? Are you using StreamBuilder? – Mehmet Esen May 15 '19 at 15:30
  • 2
    Possible duplicate of [is there any way to cancel a dart Future?](https://stackoverflow.com/questions/17552757/is-there-any-way-to-cancel-a-dart-future) – jamesdlin May 15 '19 at 15:56

0 Answers0