Catch Exceptions in Flutter Like Never Before!

Поділитися
Вставка
  • Опубліковано 26 жов 2022
  • 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

КОМЕНТАРІ • 68

  • @RandalLSchwartz
    @RandalLSchwartz Рік тому +26

    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  Рік тому +4

      Thanks for the tip, Randal! Pinned your comment, hope it helps someone.

  • @abilucksanvijeyakumaren6317
    @abilucksanvijeyakumaren6317 10 місяців тому +3

    Starting very simple and walking through a clean explanation step by step. never seen before. immediately subscribed

  • @KDTechverse
    @KDTechverse 16 днів тому

    Great video ! Keep up the great work mate !

  • @RobertoGindro
    @RobertoGindro Рік тому +2

    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 Рік тому +2

      i think its called "Dart Data Class Generator" an extension for VSCode

    • @RobertoGindro
      @RobertoGindro Рік тому +1

      @@adisonmasih Thank-you very much!

    • @RandalLSchwartz
      @RandalLSchwartz Рік тому +1

      @@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.

  • @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 ?

  • @saabirmohamed636
    @saabirmohamed636 Рік тому

    Another Excellent one!

  • @yonathanhailemelekot5238
    @yonathanhailemelekot5238 Рік тому

    amazingly awesome tutorial

  • @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!

  • @user-st5uw3wn2m
    @user-st5uw3wn2m 6 місяців тому

    Awesome!

  • @MdSiam-kw5ox
    @MdSiam-kw5ox 10 місяців тому

    Thanks for the video. 👍

  • @hashankannangara8723
    @hashankannangara8723 Рік тому

    Nice tip😍 thanks 🙏

  • @esmatullahahmadzai1284
    @esmatullahahmadzai1284 7 місяців тому

    Salaam sir
    I hope you are doing well.
    Kindly make a video on CRUD operation with API, Riverpod, and exception handling.

  • @orbitsdev5904
    @orbitsdev5904 9 місяців тому

    shesssh thanks sir

  • @stevenng1040
    @stevenng1040 Місяць тому

    Is using tuple still relevant given that we can use Records?

  • @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  Рік тому +1

      You can't create iOS Apps with Windows Operating System.

  • @Saifullah-cr5vh
    @Saifullah-cr5vh 10 місяців тому

    Thank you Mr. Rivaan Ranawat.

  • @Safi_ul_lathif
    @Safi_ul_lathif 6 місяців тому

    Subscription added🎉

  • @adisonmasih
    @adisonmasih Рік тому +2

    What do you think about the new UA-cam desktop UI?

    • @Opeyemi.sanusi
      @Opeyemi.sanusi Рік тому +1

      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.

  • @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

  • @samuelyung1031
    @samuelyung1031 Рік тому +1

    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  Рік тому +3

      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.

  • @pedroluzio
    @pedroluzio Рік тому

    A good package for this is also Dartz.

    • @RivaanRanawat
      @RivaanRanawat  Рік тому +1

      Precisely! But the last update made on the package was 11 months ago so didn't show it in this vid.

    • @RandalLSchwartz
      @RandalLSchwartz Рік тому +1

      @@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  Рік тому +2

      @@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.

  • @maxgh8315
    @maxgh8315 Рік тому +1

    can you please create peer to peer payment app, with paypal, credicard, visacard and so on please?

  • @Berlin96
    @Berlin96 Рік тому

    Bhai single vender e commerce app development me ketna cost lage ga

  • @okeyshourovroy2769
    @okeyshourovroy2769 Рік тому

    Please make a flutter graphql refreshtoken implementation 🙏

  • @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.

  • @shanukumari6969
    @shanukumari6969 Рік тому

    Dear sir can you make a video on how we can create ott platform please sir it's an humble request please 🙏🏻🙏🏻

  • @londokuhle2350
    @londokuhle2350 7 місяців тому

    I LOVE YOU BROOooooo😅😅💖💖🙏🙏

  • @jefffbezos
    @jefffbezos Рік тому

    When full youtube clone is coming? Please tell.🙏🙏

    • @RivaanRanawat
      @RivaanRanawat  Рік тому +1

      Can't assure you with the date but it's in line.

  • @joelmathew3329
    @joelmathew3329 Рік тому

    Waiting for clones using serverpod as backend

  • @nabinsaud4688
    @nabinsaud4688 Рік тому

    Bro build a Basic project for beginner and make some videos on widget it will be great

    • @RivaanRanawat
      @RivaanRanawat  Рік тому +1

      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

  • @aadhiarun4977
    @aadhiarun4977 Рік тому +2

    First

  • @madhank93
    @madhank93 Рік тому

    This is very useful

  • @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;
    }