Catch Exceptions in Flutter Like Never Before!

Поділитися
Вставка
  • Опубліковано 23 гру 2024

КОМЕНТАРІ • 68

  • @RandalLSchwartz
    @RandalLSchwartz 2 роки тому +28

    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  2 роки тому +4

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

  • @abilucksanvijeyakumaren6317
    @abilucksanvijeyakumaren6317 Рік тому +4

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

  • @RobertoGindro
    @RobertoGindro 2 роки тому +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 роки тому +2

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

    • @RobertoGindro
      @RobertoGindro 2 роки тому +1

      @@adisonmasih Thank-you very much!

    • @RandalLSchwartz
      @RandalLSchwartz 2 роки тому +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.

  • @KDTechverse
    @KDTechverse 5 місяців тому

    Great video ! Keep up the great work mate !

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

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

  • @adisonmasih
    @adisonmasih 2 роки тому +2

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

    • @Opeyemi.sanusi
      @Opeyemi.sanusi 2 роки тому +1

      Saw a video on this but they haven’t rolled it out everywhere

    • @RivaanRanawat
      @RivaanRanawat  2 роки тому

      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.

  • @Saifullah-cr5vh
    @Saifullah-cr5vh Рік тому

    Thank you Mr. Rivaan Ranawat.

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

  • @MdSiam-kw5ox
    @MdSiam-kw5ox Рік тому

    Thanks for the video. 👍

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

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

  • @yonathanhailemelekot5238
    @yonathanhailemelekot5238 2 роки тому

    amazingly awesome tutorial

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

    Subscription added🎉

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

  • @hashankannangara8723
    @hashankannangara8723 2 роки тому

    Nice tip😍 thanks 🙏

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

  • @Berlin96
    @Berlin96 2 роки тому

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

  • @maxgh8315
    @maxgh8315 2 роки тому +1

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

  • @madhank93
    @madhank93 2 роки тому

    This is very useful

  • @samuelyung1031
    @samuelyung1031 2 роки тому +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  2 роки тому +3

      Vandad's 37 hour Flutter Course on freeCodeCamp might be what you're looking for 😉

    • @samuelyung1031
      @samuelyung1031 2 роки тому

      @@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 2 роки тому

    A good package for this is also Dartz.

    • @RivaanRanawat
      @RivaanRanawat  2 роки тому +1

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

    • @RandalLSchwartz
      @RandalLSchwartz 2 роки тому +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 роки тому +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.

  • @MPRGyanStudio888
    @MPRGyanStudio888 2 роки тому

    Bro twitter tutorial how many days to take time currect time telmi bro

    • @RivaanRanawat
      @RivaanRanawat  2 роки тому

      Should take about a month. Not more than that, if all goes according to plan.

  • @okeyshourovroy2769
    @okeyshourovroy2769 2 роки тому

    Please make a flutter graphql refreshtoken implementation 🙏

  • @jefffbezos
    @jefffbezos 2 роки тому

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

    • @RivaanRanawat
      @RivaanRanawat  2 роки тому +1

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

  • @shanukumari6969
    @shanukumari6969 2 роки тому

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

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

    shesssh thanks sir

  • @joelmathew3329
    @joelmathew3329 2 роки тому

    Waiting for clones using serverpod as backend

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

    I LOVE YOU BROOooooo😅😅💖💖🙏🙏

  • @nabinsaud4688
    @nabinsaud4688 2 роки тому

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

    • @RivaanRanawat
      @RivaanRanawat  2 роки тому +1

      Will make Beginner Friendly projects soon, thanks for the suggestion!

    • @nabinsaud4688
      @nabinsaud4688 2 роки тому

      @@RivaanRanawat Thankyou for reaching out to my comment and i think i will learn more from you

  • @aadhiarun4977
    @aadhiarun4977 2 роки тому +2

    First

  • @hitmax-l5m
    @hitmax-l5m День тому

    This is dumb code, fire an exception and catch it couple lines below in the same method. Don’t do this anymore please

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