Android App Development
iOS App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Owner and Founder. Opencart
Top Partners
Either class of dartz library is used to return two type of data from a single function.
Suppose, there is an method which convert input String value in int and return it.
Here, we can only return a int value. If we get any error and handle it in our code, still we will have to return int value only. We are not able to send error message in this case.
If we wanna return two type of data, we can use Either class of dartz library. For this, we need to add dartz library in our project.
In above example, we can return int value as successful result and error message in failure case.
NOTE : To check latest package & learn more about dartz package, check following link : dartz
Import following package :
Now, wrap data which we wanna return, in Left & Right class and return them.
NOTE : Here, we wrap success result in Right class and failure result in Left class. You can change them. Also, you can wrap any object class as well.
Through fold method, we can handle result. For more methods of Either class, please check following link : Class-methods
You can check following link to check more blog related to flutter & dart : Blog
Hope, this blog will be helpful to you.
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Webkul is a truly trusted and supported IT Company to develop business ideas for e-commerce. They provide professional support after deploying the solution to production and be responsible to act for fixing the reported issues or system errors. We highly encourage to deal with Webkul for business development.
Hussein Zawia
Co-founder, 24Dokan
USA
India
Global
Name
Email
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.