What does copyWith() function do?

Viewed 1343

While learning flutter_bloc from bloclibrary website, I had to use a function with the constructor named copyWith(). Can anyone explain to me what exactly it does?

2 Answers

Usually, copyWith() creates a clone of the object with provided parameters overridden.

The copywith function creates a copy of poststate with some modification so that you don't need to create the whole state again.

The author said in his blog.

"We implemented copyWith so that we can copy an instance of PostState and update zero or more properties conveniently (this will come in handy later )".

For more info, you can read the following document.

https://github.com/felangel/bloc/blob/master/docs/cs/flutterinfinitelisttutorial.md

Related