Catch Exceptions in Flutter Like Never Before!

  Рет қаралды 20,155

Rivaan Ranawat

Rivaan Ranawat

Жыл бұрын

In this tutorial, learn how to efficiently catch and handle exceptions in your Flutter App. I will demonstrate some of the possible techniques one could have taken, problems with them and how our solution encounters all of these problems and makes our lives easier.
📌 Discord Server: / discord
Special Thanks: ‪@aadhiarun2230‬
📕 Additional Resources:
FPDart vs Dartz: github.com/SandroMaglione/fpd...
More on FPDart: www.sandromaglione.com/techbl...
Andrea's FPDart Guide: codewithandrea.com/articles/f...
Resocoder's Dartz Guide: resocoder.com/2019/12/14/func...
Connect With Me Here:
Instagram: / optimalcoding
GitHub: github.com/rivaanranawat
Linkedin: / rivaan-ranawat
Facebook: / rivaan.ranawat
Mail: namanrivaan@gmail.com
Medium: / namanrivaan
Twitter: / ranawatrivaan
#flutter #dart

Пікірлер: 67
@RandalLSchwartz
@RandalLSchwartz Жыл бұрын
I would define EitherUser as Either and FutureEitherUser as Future, so that Future is in the name. Or start using Task and those would be TaskEither instead.
@RivaanRanawat
@RivaanRanawat Жыл бұрын
Thanks for the tip, Randal! Pinned your comment, hope it helps someone.
@abilucksanvijeyakumaren6317
@abilucksanvijeyakumaren6317 10 ай бұрын
Starting very simple and walking through a clean explanation step by step. never seen before. immediately subscribed
@KDTechverse
@KDTechverse 27 күн бұрын
Great video ! Keep up the great work mate !
@pravinprince3221
@pravinprince3221 Жыл бұрын
Thank you for the wonderful video bro it is very helpful for me and my team, Thanks again bro
@RivaanRanawat
@RivaanRanawat Жыл бұрын
I'm glad it was helpful to you and your team Pravin!
@yonathanhailemelekot5238
@yonathanhailemelekot5238 Жыл бұрын
amazingly awesome tutorial
@RivaanRanawat
@RivaanRanawat Жыл бұрын
Thanks Yonathan!
@hashankannangara8723
@hashankannangara8723 Жыл бұрын
Nice tip😍 thanks 🙏
@RivaanRanawat
@RivaanRanawat Жыл бұрын
Thank you too!
@saabirmohamed636
@saabirmohamed636 Жыл бұрын
Another Excellent one!
@RivaanRanawat
@RivaanRanawat Жыл бұрын
Thanks Saabir!
@MdSiam-kw5ox
@MdSiam-kw5ox 11 ай бұрын
Thanks for the video. 👍
@RivaanRanawat
@RivaanRanawat 11 ай бұрын
My pleasure!
@RobertoGindro
@RobertoGindro Жыл бұрын
Thank-you very much! Can I ask you a question? At minute 04:02 I see a generator in Visual Studio Code (when you click on the lamp to generate the constructor) to generate JSON serialization, toString, copyWith. Is it a plugin? Thanks.
@adisonmasih
@adisonmasih Жыл бұрын
i think its called "Dart Data Class Generator" an extension for VSCode
@RobertoGindro
@RobertoGindro Жыл бұрын
@@adisonmasih Thank-you very much!
@RandalLSchwartz
@RandalLSchwartz Жыл бұрын
@@adisonmasih Yeah, and DDCG can go all the way from JSON to a nearly usable data class as well. It gets confused on unusual keys that aren't dart identifiers, but otherwise decent.
@esmatullahahmadzai1284
@esmatullahahmadzai1284 8 ай бұрын
Salaam sir I hope you are doing well. Kindly make a video on CRUD operation with API, Riverpod, and exception handling.
@Saifullah-cr5vh
@Saifullah-cr5vh 11 ай бұрын
Thank you Mr. Rivaan Ranawat.
@RivaanRanawat
@RivaanRanawat 11 ай бұрын
My pleasure!
@7anv1r71
@7anv1r71 Жыл бұрын
Will the new dart 3.0 change this fpdart approach? how can we use dart 3.0 to handle this kind of exception ?
@samuelyung1031
@samuelyung1031 Жыл бұрын
Hello Rivaan, thanks for putting this great content for free on the internet. I was wondering if you could recommend me some flutter and dart courses online, as I really want to learn but all of the available courses are not very extensive. Thank you.
@RivaanRanawat
@RivaanRanawat Жыл бұрын
Vandad's 37 hour Flutter Course on freeCodeCamp might be what you're looking for 😉
@samuelyung1031
@samuelyung1031 Жыл бұрын
@@RivaanRanawat I tried it at the start, but it went very slow. I'll try it out again. Thanks, you're a life-saver!
@RivaanRanawat
@RivaanRanawat Жыл бұрын
@@samuelyung1031 I'll be releasing Flutter Beginners Course within a month or so.
@orbitsdev5904
@orbitsdev5904 10 ай бұрын
shesssh thanks sir
@pedroluzio
@pedroluzio Жыл бұрын
A good package for this is also Dartz.
@RivaanRanawat
@RivaanRanawat Жыл бұрын
Precisely! But the last update made on the package was 11 months ago so didn't show it in this vid.
@RandalLSchwartz
@RandalLSchwartz Жыл бұрын
@@RivaanRanawat Dartz also has ZERO documentation. fpdart is not only completely documented, it comes with many examples, and a series of tutorials/blog articles. And it was updated *again* only a few days ago. I've migrated three projects from dartz to fpdart now, and am very happy.
@RivaanRanawat
@RivaanRanawat Жыл бұрын
@@RandalLSchwartz Oh yes, Forgot about mentioning the documentation. Resocoder's articles helped me use Dartz. Andrea's articles directed my attention towards fpdart and their documentation has been doing well for me in some of my projects.Thanks for letting me know about their documentation changes. Revisited pub.dev, seems they have added a new example of open meteo. Need to try out the package in newer projects as well, to test out the new extension methods they've added.
@Safi_ul_lathif
@Safi_ul_lathif 7 ай бұрын
Subscription added🎉
@RivaanRanawat
@RivaanRanawat 6 ай бұрын
Awesome, thank you!
@stevenng1040
@stevenng1040 Ай бұрын
Is using tuple still relevant given that we can use Records?
@adisonmasih
@adisonmasih Жыл бұрын
What do you think about the new KZbin desktop UI?
@Opeyemi.sanusi
@Opeyemi.sanusi Жыл бұрын
Saw a video on this but they haven’t rolled it out everywhere
@RivaanRanawat
@RivaanRanawat Жыл бұрын
Pretty cool imo. Always liked rounded corners. The dark black background gives me an improved immersive experience. The thumbnails stand out better. Would have loved getting comment box in the side panel though, similar to what happens in Live Stream.
@MPRGetProfit
@MPRGetProfit Жыл бұрын
Bro I'm using windows laptop I'm creating project iOS folder inside podfile not comming continuous or stop my project podfile is compulsory or not windows laptop
@RivaanRanawat
@RivaanRanawat Жыл бұрын
You can't create iOS Apps with Windows Operating System.
@okeyshourovroy2769
@okeyshourovroy2769 Жыл бұрын
Please make a flutter graphql refreshtoken implementation 🙏
@RivaanRanawat
@RivaanRanawat Жыл бұрын
In line.
@shanukumari6969
@shanukumari6969 Жыл бұрын
Dear sir can you make a video on how we can create ott platform please sir it's an humble request please 🙏🏻🙏🏻
@RivaanRanawat
@RivaanRanawat Жыл бұрын
Noted!
@yadhusanil7077
@yadhusanil7077 Жыл бұрын
bro , isleft and isright method is not available 🤷‍♂ is there any other method to find ,i searched a lot ,not able to find , plz help
@RivaanRanawat
@RivaanRanawat Жыл бұрын
Are you using fpdart package?
@yadhusanil7077
@yadhusanil7077 Жыл бұрын
@@RivaanRanawat no dartz
@londokuhle2350
@londokuhle2350 7 ай бұрын
I LOVE YOU BROOooooo😅😅💖💖🙏🙏
@nabinsaud4688
@nabinsaud4688 Жыл бұрын
Bro build a Basic project for beginner and make some videos on widget it will be great
@RivaanRanawat
@RivaanRanawat Жыл бұрын
Will make Beginner Friendly projects soon, thanks for the suggestion!
@nabinsaud4688
@nabinsaud4688 Жыл бұрын
@@RivaanRanawat Thankyou for reaching out to my comment and i think i will learn more from you
@maxgh8315
@maxgh8315 Жыл бұрын
can you please create peer to peer payment app, with paypal, credicard, visacard and so on please?
@maxgh8315
@maxgh8315 Жыл бұрын
very helpful video by the way
@RivaanRanawat
@RivaanRanawat Жыл бұрын
Noted, thank you :)
@joelmathew3329
@joelmathew3329 Жыл бұрын
Waiting for clones using serverpod as backend
@RivaanRanawat
@RivaanRanawat Жыл бұрын
After it's v1 release, for sure!
@Berlin96
@Berlin96 Жыл бұрын
Bhai single vender e commerce app development me ketna cost lage ga
@RivaanRanawat
@RivaanRanawat Жыл бұрын
DM me on Discord at rivaanranawat#9083
@pawanbhardwaj6889
@pawanbhardwaj6889 Жыл бұрын
We can have chat, if this position is still there
@MPRGyanStudio888
@MPRGyanStudio888 Жыл бұрын
Bro twitter tutorial how many days to take time currect time telmi bro
@RivaanRanawat
@RivaanRanawat Жыл бұрын
Should take about a month. Not more than that, if all goes according to plan.
@jefffbezos
@jefffbezos Жыл бұрын
When full youtube clone is coming? Please tell.🙏🙏
@RivaanRanawat
@RivaanRanawat Жыл бұрын
Can't assure you with the date but it's in line.
@aadhiarun4977
@aadhiarun4977 Жыл бұрын
First
@aadhiarun4977
@aadhiarun4977 Жыл бұрын
second
@madhank93
@madhank93 Жыл бұрын
This is very useful
@RivaanRanawat
@RivaanRanawat Жыл бұрын
Glad it was!
@devhammed
@devhammed Жыл бұрын
I am using this pattern too except I actually wrote my own code for it inspired by Rust's Result enum type that has Ok or Err members: import 'package:meta/meta.dart'; /// Base Result class /// /// Receives two values [E] and [T] /// as [E] is an error and [T] is a success. @sealed abstract class Result { /// Default constructor. const Result(); Ok get _asOk => this as Ok; Err get _asErr => this as Err; T get _okValue => _asOk._value; E get _errValue => _asErr._value; /// Returns `true` if the result is [Ok]. bool get isOk => this is Ok; /// Returns `true` if the result is [Err]. bool get isErr => !isOk; /// Converts from `Result` to `T?`. /// /// Converts `this` into a nullable value, consuming `this`, /// and discarding the error, if any. T? ok() => isOk ? _okValue : null; /// Converts from `Result` to `E?`. /// /// Converts `this` into a nullable value, consuming `this`, /// and discarding the success value, if any. E? err() => isOk ? null : _errValue; /// Maps a `Result` to `Result` by applying a function to a /// contained [Ok] value, leaving an [Err] value untouched. /// /// This function can be used to compose the results of two functions. Result map(U Function(T value) cb) => isOk ? Ok(cb(_okValue)) : Err(_errValue); /// Maps a `Result` to `Result` by applying a function to a /// contained [Err] value, leaving an [Ok] value untouched. /// /// This function can be used to pass through a successful result while /// handling an error. Result mapErr(F Function(E err) cb) => isOk ? Ok(_okValue) : Err(cb(_errValue)); /// Returns the provided default (if [Err]), or /// applies a function to the contained value (if [Ok]), /// /// Arguments passed to `mapOr` are eagerly evaluated; if you are passing /// the result of a function call, it is recommended to use [mapOrElse], /// which is lazily evaluated. U mapOr(U Function(T value) cb, U defaultValue) => isOk ? cb(_okValue) : defaultValue; /// Maps a `Result` to `U` by applying fallback function `defaultF` to /// a contained [Err] value, or function `f` to a contained [Ok] value. /// /// This function can be used to unpack a successful result /// while handling an error. U mapOrElse(U Function(T value) cb, U Function(E err) errCb) => isOk ? cb(_okValue) : errCb(_errValue); /// Returns an iterable over the possibly contained value. /// /// The iterable yields one value if the result is [Ok], otherwise none. Iterable iter() => isOk ? [_okValue] : const []; /// Returns the contained [Ok] value, consuming the `this` value. /// /// Throw an error if the value is an [Err], with an error message including /// the passed message, and the content of the [Err]. T expect(String msg) => isOk ? _okValue : throw ResultUnwrapError(msg, obj: _errValue); /// Returns the contained [Ok] value, consuming the `this` value. /// /// Because this function may throw an error, its use is generally /// discouraged. /// Instead, prefer to handle the [Err] case explicitly, /// or call [unwrapOr] or [unwrapOrElse]. T unwrap() => isOk ? _okValue : throw ResultUnwrapError( 'called `Result#unwrap` on an `Err` value', obj: _errValue, ); /// Returns the contained [Err] value, consuming the `this` value. /// /// Throw an error if the value is an [Ok], with an error message including /// the passed message, and the content of the [Ok]. E expectErr(String msg) => isOk ? throw ResultUnwrapError(msg, obj: _okValue) : _errValue; /// Returns the contained [Err] value, consuming the `this` value. /// /// Exceptions if the value is an [Ok], with a custom error message provided /// by the [Ok]'s value. E unwrapErr() => isOk ? throw ResultUnwrapError( 'called `Result#unwrapErr` on an `Ok` value', obj: _okValue, ) : _errValue; /// Returns `res` if the result is [Ok], otherwise returns the [Err] value of /// `this`. Result and(Result res) => isOk ? res : Err(_errValue); /// Calls `op` if the result is [Ok], otherwise returns the [Err] value of /// `this`. /// /// This function can be used for control flow based on `Result` values. Result andThen(Result Function(T value) cb) => isOk ? cb(_okValue) : Err(_errValue); /// Returns `res` if the result is [Err], otherwise returns the [Ok] value of /// `this`. /// /// Arguments passed to `or` are eagerly evaluated; if you are passing the /// result of a function call, it is recommended to use [orElse], which is /// lazily evaluated. Result or(Result res) => isOk ? Ok(_okValue) : res; /// Calls `op` if the result is [Err], otherwise returns the [Ok] value of /// `this`. /// /// This function can be used for control flow based on result values. Result orElse(Result Function(E err) cb) => isOk ? Ok(_okValue) : cb(_errValue); /// Returns the contained [Ok] value or a provided default. /// /// Arguments passed to `unwrapOr` are eagerly evaluated; if you are passing /// the result of a function call, it is recommended to use /// [unwrapOrElse], which is lazily evaluated. T unwrapOr(T defaultValue) => isOk ? _okValue : defaultValue; /// Returns the contained [Ok] value or computes it from a closure. T unwrapOrElse(T Function(E err) cb) => isOk ? _okValue : cb(_errValue); } /// `Ok` is a type that represents success and contains a `T` type success /// value. @sealed class Ok extends Result { const Ok(this._value); final T _value; @override bool operator ==(Object other) { if (identical(this, other)) { return true; } return other is Ok && other._value == _value; } @override int get hashCode => _value.hashCode; @override String toString() => 'Ok(${_value.toString()})'; } /// `Err` is a type that represents failure and contains a `E` type error value. @sealed class Err extends Result { const Err(this._value); final E _value; @override bool operator ==(Object other) { if (identical(this, other)) { return true; } return other is Err && other._value == _value; } @override int get hashCode => _value.hashCode; @override String toString() => 'Err(${_value.toString()})'; } /// Error thrown by the runtime system when `unwrap` fails. @sealed class ResultUnwrapError extends Error { ResultUnwrapError( this.message, { this.obj, }); final String message; final Object? obj; @override String toString() => obj != null ? '$message: $obj' : message; }
Flutter Navigator 2.0 Tutorial for Beginners - Go Router
11:28
Rivaan Ranawat
Рет қаралды 19 М.
What it feels like cleaning up after a toddler.
00:40
Daniel LaBelle
Рет қаралды 87 МЛН
Double Stacked Pizza @Lionfield @ChefRush
00:33
albert_cancook
Рет қаралды 113 МЛН
Leetcode 134. Gas Station (Java)
9:53
Everyday Leetcode
Рет қаралды 3
Proper Error Handling in Flutter & Dart (#1 - Principles)
31:30
Reso Coder
Рет қаралды 53 М.
Advanced Exceptions Handling in Flutter - Artem Goncharov
38:00
Google Developers Space
Рет қаралды 2,3 М.
All Rust features explained
21:30
Let's Get Rusty
Рет қаралды 296 М.
Flutter Integration Testing Tutorial For Beginners - Practical Guide
17:06
What's New in Dart 3?
30:09
Rivaan Ranawat
Рет қаралды 28 М.
What it feels like cleaning up after a toddler.
00:40
Daniel LaBelle
Рет қаралды 87 МЛН