Dart GETTER and SETTER | Private Instance variables. Dart Programming for Flutter #9.1

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ต.ค. 2024

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

  • @shubhamdubey1996
    @shubhamdubey1996 5 ปีที่แล้ว +45

    I'm following this whole Dart tutorial Series from the beginning and You're a good teacher (No Doubt).
    I also want you to add some extra information like why we need this particular thing?
    For example In this video you taught 'How to use Getter and Setter' but What you missed is Why we need to use Getter and Setter while we can assign the values directly.
    Yes! We can google it, But these extra information that is also with real life example will make your videos/lectures Stand Out.
    Thank you for Such informative and easily understandable videos :)

    • @smartherd
      @smartherd  5 ปีที่แล้ว +16

      noted. such feedback really helps thanks

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

      @@smartherd Actually even i would roco that, you teach well at a steady pace, just the above point might help you more. Even i googled a lot of stuff on y, how i got it from u. But good work.

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

      Exactly i was thinking the same, why should we use ???

  • @tevinmorake8924
    @tevinmorake8924 3 ปีที่แล้ว +4

    Well done! I think everyone here can agree that you deserve more recognition for the awesome tutorial series you've given us. Thanks

    • @smartherd
      @smartherd  3 ปีที่แล้ว

      Thanks man
      :: Also, check out my personal TH-cam Vlog channel: bit.ly/sriyank-vlog

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

    OK this video was much better than the Dart tutorial I've purchased. Now I understand getters and setters. Thank you.

  • @dennisrodriguez9202
    @dennisrodriguez9202 4 ปีที่แล้ว +3

    Thanks bro my native language isn't English but I came here cuz I was watching a Spanish video and I had understood nothing, but ur video yas! love u!

  • @ishaqkhan4508
    @ishaqkhan4508 4 ปีที่แล้ว +6

    bro you should make a seperate video for why we need getter and setter?thanks for ur efforts though

    • @noelxxiv9382
      @noelxxiv9382 4 ปีที่แล้ว

      Exactly, i think it is used to do a computation of percentage in this case. as constructors cannot return any values.
      **This is my real lay understanding . First language I m learning is dart.

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

    By far the most explanatory video tutorial series. Excellent Job Guys.

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

    Thanks and Congratulations for creating this wonderful series. You are, no doubt, an excellent teacher.

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

    How your channel still doesn't have a million subscriber is beyond my understanding.

  • @王甯-h2x
    @王甯-h2x 5 ปีที่แล้ว +9

    In best practice:
    1. It should be `set int someField`, not `void set int someField`.
    2. You should not create a field to change another field, in your case `percentage -> percent`.

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

      Hi sir, can you kindly help me explain the point no 2 that you mention. What is creating another field to change another field?

    • @王甯-h2x
      @王甯-h2x 5 ปีที่แล้ว +4

      ​@@TheRizse The idea is that every field has built-in getter & setter, so no need to recreate the wheel.
      From official docs: dart.dev/guides/language/effective-dart/usage#dont-wrap-a-field-in-a-getter-and-setter-unnecessarily
      See also: [Language Tour - Methods - Getters and setters]: dart.dev/guides/language/language-tour#methods

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

      @@TheRizse dart.dev/guides/language/effective-dart/usage#avoid-storing-what-you-can-calculate

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

    First of all I already subscribed to your very good channel. to solve the division problem (marksecured ~ / 500) * 100 without having to change the type of variable to Double, simply change the order of execution of the calculation to (marksecured * 100) ~ / 500

  • @md.soleymankhan6550
    @md.soleymankhan6550 4 ปีที่แล้ว +2

    Best dart tutorial ever.

  • @taiwo763
    @taiwo763 4 ปีที่แล้ว

    i had to subscribe cos of this tutorial. For the first time, it actually made sense

  • @mohamednizam5298
    @mohamednizam5298 4 ปีที่แล้ว

    A very good tut on dart as an intro to flutter . just further clarification on getter and setter as to the actual use of it. Still cant understand its purpose. thanks again on this tut.

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

    Thank you so much for making it sooooo EASY really appreciate your efforts :)

  • @whitehawk4671
    @whitehawk4671 2 ปีที่แล้ว

    in case you forgot how to write getter and setter, go to Code(only for intellij) and the click on generate, to generate getter and setter you can also use alt+insert to get it directly....

  • @adamtak3128
    @adamtak3128 5 ปีที่แล้ว +4

    You explained the syntax but not what getters and setters are for. What's the purpose or having private variables and setter/getter? Can't that exact thing just be done with a method instead?

    • @md.soleymankhan6550
      @md.soleymankhan6550 4 ปีที่แล้ว

      You will get the point during firebase anon authentication.

  • @iplayguitar1000
    @iplayguitar1000 3 ปีที่แล้ว

    Thanks man. Better than the docs.

  • @masrursakib6528
    @masrursakib6528 4 ปีที่แล้ว

    Awesome video, helped me with what I was looking for.

  • @user-or7ji5hv8y
    @user-or7ji5hv8y 3 ปีที่แล้ว

    always very well explained

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

    Great video

  • @shrikantakalantri1787
    @shrikantakalantri1787 2 ปีที่แล้ว

    nice explanation

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

    I don't like fat arrow syntax. It saves a few lines of code, but looses readability.

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

    Avoid the use of return types in setters such as in your example "void set percentage"

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

    Lost in trying to determine which exact video that is supposedly linked to using => (fat arrow) in this video's description.

    • @mainulhoque8816
      @mainulhoque8816 4 ปีที่แล้ว

      4FunRC here you go - th-cam.com/video/F42iMVaNALA/w-d-xo.html

  • @keithbacalso9433
    @keithbacalso9433 2 ปีที่แล้ว

    awsome tutorial keep it up!

  • @tGoldenPhoenix
    @tGoldenPhoenix 20 วันที่ผ่านมา

    Thank you!

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

    Well, I have a question.
    If setters can alter the members/fields of a class. Then why do we use setters in the first place instead of regular (public) fields. Because, in both scenarios we can change/modify the fields and we are losing control over the data. Aren't we??
    Thanks in advance.

  • @jajasaria
    @jajasaria 5 ปีที่แล้ว

    love your videos. May i know where did you get the reference of all of your lesson? I like the objectives part, you nailed the difference of each type.

  • @QUniversity
    @QUniversity 4 ปีที่แล้ว

    Great explanation.

  • @pratik1853
    @pratik1853 2 ปีที่แล้ว

    use late keyword before such as late String name; to print in new dartpad

    • @pratik1853
      @pratik1853 2 ปีที่แล้ว

      or assign values such as String name='abc';

  • @mockingbird3809
    @mockingbird3809 5 ปีที่แล้ว

    Thank you so much for this amazing video

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

    sir mein bahat baar pada hu yea privet public protected but mujhe yea samajh abhi tak nehi aya why these are came into action...cause every local variable have not accessed out side function or class...then why....????

  • @DholaSain
    @DholaSain 2 ปีที่แล้ว

    thanks bro

  • @noelxxiv9382
    @noelxxiv9382 4 ปีที่แล้ว

    Can anyone explain what is the difference between a constructor and getter/setter?

  • @TouhidSunny
    @TouhidSunny 4 ปีที่แล้ว

    your example is like a stateless widget. but in flutter if i use stateful widget then i cant access the percentage method from main. if i declare it in widget then ok. but in state i cant access it. please tell me the reason.

  • @pratyakshpandey2248
    @pratyakshpandey2248 3 ปีที่แล้ว

    Just want to ask what is difference between getter, setter and constructor? I mean, we could have just made a function percentage of datatype double and then directly return the value of percentage. So, I want to know the real difference between getter, setter and dart!

  • @mizanur_sajid
    @mizanur_sajid 3 ปีที่แล้ว

    - 2:28 if you face any error with the (String name) then just make it like this >> (String? name)

    • @kishansindhi6963
      @kishansindhi6963 3 ปีที่แล้ว

      What about
      double get percentage => return percent;
      can you please help me with it?

  • @pawan2647
    @pawan2647 5 ปีที่แล้ว

    bro cant we use normal functions to get and set the value, plus arent there any concept of private data members which are private to the class only.

  • @noreplay6418
    @noreplay6418 4 ปีที่แล้ว

    why i get this warning when i try to create a getter and setter for private variable
    Avoid wrapping fields in getters and setters just to be "safe".

  • @ahmdmnsor
    @ahmdmnsor 4 ปีที่แล้ว

    what is the library it will be private to ?

  • @leandroacevedo3339
    @leandroacevedo3339 3 ปีที่แล้ว

    Bravo

  • @dexterousdivya
    @dexterousdivya 6 หลายเดือนก่อน +1

    Here is the latest code for Dart 3
    // OBJECTIVES
    // 1. Default Getter and Setter
    // 2. Custom Getter and Setter
    // 3. Private Instance Variable
    void main() {
    var s1 = Student();
    s1.name = "Peter"; // Calling default Setter to set value
    print(s1.name); // Calling defailt Getter to get value
    s1.percentage = 438.0; // Calling Custom Setter to set value
    print(s1.percentage); //Calling Custom Getter to get value
    }
    class Student {
    String? name; // Instance variable with default getter and setter
    late double _percent; // Private Instance variable for its own library
    // Instance variable with Custom Setter
    void set percentage(double marksSecured) => _percent = (marksSecured / 500) * 100;
    // Instance variable with Custom Getter
    double get percentage => _percent;
    }

  • @atefehmohammadpoor9177
    @atefehmohammadpoor9177 4 ปีที่แล้ว

    thannnnks

  • @SagarSagar-ro3fj
    @SagarSagar-ro3fj 5 ปีที่แล้ว

    If there is no private then y getter setters are used .?

  • @z-medianetwork408
    @z-medianetwork408 6 ปีที่แล้ว

    I made an app in android studio. When I run on real device from pc, it installs apk & run well with splash screen. But when I run it again from the real device icon, it doesn't show the splash screen but displays white screen. Why? Please help. Thanks.

  • @zuhaib4030
    @zuhaib4030 4 ปีที่แล้ว

    plz help me its isnt working trying tooo hard but its isn t can you help me out

  • @syntaxerror1044
    @syntaxerror1044 5 ปีที่แล้ว

    Hello...While trying to understand Getter and Setter, I stumbled upon this piece of code from an article from 2012.
    I pasted the same code into my editor but it gave me error and i was wondering if this code is using old syntax as it is from 2012.
    Anyone??
    void main() {
    var obj = new GetnSetMet();
    obj.firstName="Google";
    obj.lastName="Dart!";
    print(obj.FullName);
    }
    class GetnSetMet{
    String f_name,l_name;
    String get firstName() => f_name;
    set firstName(String value) => f_name = value;
    String get lastName() => l_name;
    set lastName(String value) => l_name = value;
    String get FullName() => firstName.concat(lastName);

    }

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

    i am getting errors one after another. I guess I am in the new version dart. I have came here by completing all the previous videos before of this course, but this made me sad, your course is not completely valid with the latest dart sdks.

  • @suleman4183
    @suleman4183 4 ปีที่แล้ว

    You putting great effort, but beginner just cannot understand these tutorials you're using too much jargon and you're not explaining enough a why certain thing do this or do that.

  • @shumailasami6765
    @shumailasami6765 6 ปีที่แล้ว

    what about method overloading?

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

      In dart, method overloading not allowed

  • @mahmudizukri
    @mahmudizukri 4 ปีที่แล้ว

    Subtitle please

  • @mashakozlova9425
    @mashakozlova9425 4 ปีที่แล้ว

    "methods" man "methods". not "methord" and why do you talk about yourself as "we"?