Catch Exceptions in Flutter Like Never Before!

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 ก.ย. 2024
  • 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/San...
    More on FPDart: www.sandromagl...
    Andrea's FPDart Guide: codewithandrea...
    Resocoder's Dartz Guide: resocoder.com/...
    Connect With Me Here:
    Instagram: / optimalcoding
    GitHub: github.com/riv...
    Linkedin: / rivaan-ranawat
    Facebook: / rivaan.ranawat
    Mail: namanrivaan@gmail.com
    Medium: / namanrivaan
    Twitter: / ranawatrivaan
    #flutter #dart

ความคิดเห็น • 67

  • @RandalLSchwartz
    @RandalLSchwartz ปีที่แล้ว +27

    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 ปีที่แล้ว +3

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

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

  • @stevenng1040
    @stevenng1040 3 หลายเดือนก่อน

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

  • @maxgh8315
    @maxgh8315 ปีที่แล้ว +1

    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 :)

  • @adisonmasih
    @adisonmasih ปีที่แล้ว +2

    What do you think about the new TH-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.

  • @londokuhle2350
    @londokuhle2350 9 หลายเดือนก่อน

    I LOVE YOU BROOooooo😅😅💖💖🙏🙏

  • @esmatullahahmadzai1284
    @esmatullahahmadzai1284 10 หลายเดือนก่อน

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

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

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

  • @aadhiarun4977
    @aadhiarun4977 ปีที่แล้ว +2

    First

  • @KDTechverse
    @KDTechverse 2 หลายเดือนก่อน

    Great video ! Keep up the great work mate !

  • @Safi_ul_lathif
    @Safi_ul_lathif 9 หลายเดือนก่อน

    Subscription added🎉

    • @RivaanRanawat
      @RivaanRanawat  8 หลายเดือนก่อน

      Awesome, thank you!

  • @shanukumari6969
    @shanukumari6969 ปีที่แล้ว

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

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

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

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

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

  • @okeyshourovroy2769
    @okeyshourovroy2769 ปีที่แล้ว

    Please make a flutter graphql refreshtoken implementation 🙏

  • @joelmathew3329
    @joelmathew3329 ปีที่แล้ว

    Waiting for clones using serverpod as backend

    • @RivaanRanawat
      @RivaanRanawat  ปีที่แล้ว

      After it's v1 release, for sure!

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

  • @orbitsdev5904
    @orbitsdev5904 ปีที่แล้ว

    shesssh thanks sir

  • @MdSiam-kw5ox
    @MdSiam-kw5ox ปีที่แล้ว

    Thanks for the video. 👍

  • @Saifullah-cr5vh
    @Saifullah-cr5vh ปีที่แล้ว

    Thank you Mr. Rivaan Ranawat.

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

  • @saabirmohamed636
    @saabirmohamed636 ปีที่แล้ว

    Another Excellent one!

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

  • @yonathanhailemelekot5238
    @yonathanhailemelekot5238 ปีที่แล้ว

    amazingly awesome tutorial

  • @madhank93
    @madhank93 ปีที่แล้ว

    This is very useful

  • @hashankannangara8723
    @hashankannangara8723 ปีที่แล้ว

    Nice tip😍 thanks 🙏

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

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