No video

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

  Рет қаралды 78,619

Smartherd

Smartherd

Күн бұрын

Access 7000+ courses for 15 days FREE: pluralsight.px...
Dart flutter tutorial. Explore what are GETTERS and SETTERS with how to define Custom Getter and Setter in Dart. Also, explore how to define Private Instance Variable within Class using an underscore ( _ ) as a prefix before a variable name and make it private to its own library.
Dart Short Hand Syntax | Using FAT ARROW: • Dart Short Hand Syntax...
Next Video : • Dart INHERITANCE Expla...
Previous Video : • Dart Class, Objects, C...
Code Files: bit.ly/2JxWDgB .
.
Please donate and support my work
(If you think my free tutorials are better than paid ones :)
- Patreon: bit.ly/patreon...
- Paypal/Payoneer: sriyank123@gmail.com
- UPI (only for India): smartherd@okaxis
:: If you want to develop a website or a mobile app, email me your requirement at sriyank.siddhartha@gmail.com :: Free demos provided beforehand ::
- Access my premium courses: bit.ly/sriyank...
Free Programming courses:
- Ruby Programming: bit.ly/smyt-r
- Dart Programming: bit.ly/smyt-d
- Kotlin Programming: bit.ly/smyt-k
- Java Programming: bit.ly/smyt-j
- Kotlin Coroutines: bit.ly/smyt-coru
Free Flutter course:
- Flutter App Development: bit.ly/2Rg7EFR
Free Android courses:
- Android using Kotlin: bit.ly/smyt-ka
- Android using Java: bit.ly/smyt-ja
- Android Material Design: bit.ly/2SMJqU6
- Android Jetpack Architecture: bit.ly/yt-j
- Android Multiple Screen Support: bit.ly/smyt-mss
- Android Retrofit: bit.ly/2Ee6GHn
More free programming courses:
- bit.ly/smy-list
Check out my website:
- bit.ly/smartherd
Let's get in touch! [Sriyank Siddhartha]
LinkedIn: bit.ly/sriyank...
Facebook: bit.ly/smarthe...
Instagram: bit.ly/sriyank...
Twitter: bit.ly/sriyank...
Github: bit.ly/smarthe...
--- Thank you for your love and support ---

Пікірлер: 67
@shubhamdubey1996
@shubhamdubey1996 5 жыл бұрын
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 жыл бұрын
noted. such feedback really helps thanks
@thegreenboxindia3579
@thegreenboxindia3579 4 жыл бұрын
@@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 3 жыл бұрын
Exactly i was thinking the same, why should we use ???
@tevinmorake8924
@tevinmorake8924 3 жыл бұрын
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 KZbin Vlog channel: bit.ly/sriyank-vlog
@denizgur
@denizgur 4 жыл бұрын
OK this video was much better than the Dart tutorial I've purchased. Now I understand getters and setters. Thank you.
@dennisrodriguez9202
@dennisrodriguez9202 4 жыл бұрын
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!
@leandroacevedo3339
@leandroacevedo3339 4 жыл бұрын
Same thing happened to me! irónico, no?
@marufhassan634
@marufhassan634 Жыл бұрын
How your channel still doesn't have a million subscriber is beyond my understanding.
@ishaqkhan4508
@ishaqkhan4508 4 жыл бұрын
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.
@md.soleymankhan6550
@md.soleymankhan6550 3 жыл бұрын
Best dart tutorial ever.
@vinimaykaul
@vinimaykaul 4 жыл бұрын
By far the most explanatory video tutorial series. Excellent Job Guys.
@LearnWithYK
@LearnWithYK 2 жыл бұрын
Thanks and Congratulations for creating this wonderful series. You are, no doubt, an excellent teacher.
@JDArtagnanAO
@JDArtagnanAO 5 жыл бұрын
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
@taiwo763
@taiwo763 4 жыл бұрын
i had to subscribe cos of this tutorial. For the first time, it actually made sense
@user-mv4oh8yp1y
@user-mv4oh8yp1y 5 жыл бұрын
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 жыл бұрын
Hi sir, can you kindly help me explain the point no 2 that you mention. What is creating another field to change another field?
@user-mv4oh8yp1y
@user-mv4oh8yp1y 5 жыл бұрын
​@@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 жыл бұрын
@@TheRizse dart.dev/guides/language/effective-dart/usage#avoid-storing-what-you-can-calculate
@ranya6266
@ranya6266 Жыл бұрын
Thank you so much for making it sooooo EASY really appreciate your efforts :)
@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.
@iplayguitar1000
@iplayguitar1000 3 жыл бұрын
Thanks man. Better than the docs.
@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....
@FlutterShipp
@FlutterShipp Жыл бұрын
Great video
@shrikantakalantri1787
@shrikantakalantri1787 2 жыл бұрын
nice explanation
@adamtak3128
@adamtak3128 5 жыл бұрын
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 3 жыл бұрын
You will get the point during firebase anon authentication.
@masrursakib6528
@masrursakib6528 4 жыл бұрын
Awesome video, helped me with what I was looking for.
@muhammadjunaid3684
@muhammadjunaid3684 2 жыл бұрын
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.
@user-or7ji5hv8y
@user-or7ji5hv8y 3 жыл бұрын
always very well explained
@DholaSain
@DholaSain 2 жыл бұрын
thanks bro
@keithbacalso9433
@keithbacalso9433 2 жыл бұрын
awsome tutorial keep it up!
@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.
@rahulmullick7316
@rahulmullick7316 4 жыл бұрын
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....????
@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';
@QUniversity
@QUniversity 4 жыл бұрын
Great explanation.
@mockingbird3809
@mockingbird3809 5 жыл бұрын
Thank you so much for this amazing video
@leandroacevedo3339
@leandroacevedo3339 3 жыл бұрын
Bravo
@atefehmohammadpoor9177
@atefehmohammadpoor9177 4 жыл бұрын
thannnnks
@4funrc11
@4funrc11 4 жыл бұрын
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 - kzbin.info/www/bejne/fGWVmoCMlrN0gqM
@ccbe4858
@ccbe4858 4 жыл бұрын
I don't like fat arrow syntax. It saves a few lines of code, but looses readability.
@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.
@dexterousdivya
@dexterousdivya 5 ай бұрын
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; }
@thevoidyouseek
@thevoidyouseek 3 ай бұрын
thank you
@voodoo7183
@voodoo7183 5 жыл бұрын
Avoid the use of return types in setters such as in your example "void set percentage"
@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?
@noelxxiv9382
@noelxxiv9382 4 жыл бұрын
Can anyone explain what is the difference between a constructor and getter/setter?
@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.
@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!
@NikhilSharma-wx7kb
@NikhilSharma-wx7kb Жыл бұрын
I was wondering the same thing.
@zuhaib4030
@zuhaib4030 4 жыл бұрын
plz help me its isnt working trying tooo hard but its isn t can you help me out
@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.
@ahmdmnsor
@ahmdmnsor 4 жыл бұрын
what is the library it will be private to ?
@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".
@SagarSagar-ro3fj
@SagarSagar-ro3fj 5 жыл бұрын
If there is no private then y getter setters are used .?
@syntaxerror1044
@syntaxerror1044 4 жыл бұрын
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 жыл бұрын
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"?
АЗАРТНИК 4 |СЕЗОН 1 Серия
40:47
Inter Production
Рет қаралды 333 М.
Whoa
01:00
Justin Flom
Рет қаралды 46 МЛН
Just Give me my Money!
00:18
GL Show Russian
Рет қаралды 539 М.
Little brothers couldn't stay calm when they noticed a bin lorry #shorts
00:32
Fabiosa Best Lifehacks
Рет қаралды 21 МЛН
If __name__ == "__main__" for Python Developers
8:47
Python Simplified
Рет қаралды 398 М.
Getter and Setter In Dart - Learn Dart Programming
15:33
Dart Tutorial
Рет қаралды 2,5 М.
Learn to use Isolates in Flutter | Simplified
10:28
CodeX
Рет қаралды 26 М.
Bringing pattern matching to Dart
20:28
Flutter
Рет қаралды 38 М.
Generics: The most intimidating TypeScript feature
18:19
Matt Pocock
Рет қаралды 172 М.
25 learn dart for beginner - getter setter
12:56
Bitfumes - AI & LLMs
Рет қаралды 1 М.
АЗАРТНИК 4 |СЕЗОН 1 Серия
40:47
Inter Production
Рет қаралды 333 М.