serviceresult

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

serviceresult

result #
A class to intermediate returns from services with two types of possible returns, like either from Dartz, but with a more specific and simple aproach.
Example in Service:
Future<Result<UserModel>> getUserData (String userID)async{
try{
final response = await http.get(url+userID);
return Result<UserModel>(data: UserMode.fromJson(response.data),);
} catch(e){
return Result(error: ErrorResult(message: "User data not avaible"),);
}
}
copied to clipboard
Example in use (normaly in Controller)
getUserData (String userID)async{
Result<UserModel> result = await UsersService().getUserData(userID);
result.fold(
onSuccess: (data){
loggedUser = data;
notifyListeners();
//navigate to home or other actions
},
onError: (error){
//function to show the error, take the user to register ou logOut
}
);
}
copied to clipboard
**The class bring others methods to shortcut frequently actions:
successWithWarning(onSuccess) to call only a function on success and show a error on error;
showErrorDialog(context) to show a dialog of error;
Getting Started #
For help getting started with Flutter, view our
online documentation, which offers tutorials,
samples, guidance on mobile development, and a full API reference.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.

Related Products

More From This Creator