Equitable Package in a flutter

Shirsh Shukla
3 min readMar 18, 2022

That compares two objects easily without writing so much boilerplate code

Hello, and welcome to this interesting article where we will learn about the equitable package in Flutter.
So let’s start, the first thing that arises in our mind is why we need this package.

The main goal of the Equitable package is to reduce the boilerplate code required to compare objects.

So basically when our project if we need to compare two variables that variable may be a String, Int, Flot, etc. we can easily compare those things,
but,

if we need to compare two objects so we face so many problems because we need to write so many conditional codes as required for that.

So in this situation, our mind got of the easiest and most reliable solution for flutter development is that equitable package.

Let’s see this by a simple example

So as you see the above example, first of all, I am extending my class UserDetail by Equatable, then putting username and id parameters inside of props function.
the main thing in this code is I am putting username and id parameters inside of props function,

I am doing this thing because,
after adding this parameter (username and id) inside there. Equatable
compare all of these two-parameter values when I am creating any object by using the help of this class.

like inside of compareData method I am creating three objects and comparing all those.

also, one more thing I need to add up in this point is if you need to compare only some parameters not all then, only add that parameter inside of the props method of your model class.

another thing that package also provides is stringify method, if you enable true in this method helps you as want to override toString the method in your objects.
Also, one more additional thing is that If your class is already extending anything then you can use EquatableMixin mixin.

let’s see both of these two advantages by a simple example.

it’s very simple and better to understand right, so as using this package you can easily achieve comparing two objects and check whether they are equal or not.

If you got something wrong? Mention it in the comments. I would love to improve. your support means a lot to me! If you enjoy the content, I’d be grateful if you could consider subscribing to my YouTube channel as well.

I am Shirsh Shukla, a creative Developer, and a Technology lover. You can find me on LinkedIn or maybe follow me on Twitter or just walk over my portfolio for more details. And of course, you can follow me on GitHub as well.

Have a nice day!🙂

--

--

Shirsh Shukla

SDE at Reliance Jio | Mobile Application Developer | Speaker | Technical Writer | community member at Stack Overflow | Organizer @FlutterIndore