Dart Optional NAMED Parameters in Functions. Dart Tutorial for Flutter #6.5

  Рет қаралды 55,259

Smartherd

Smartherd

6 жыл бұрын

Access 7000+ courses for 15 days FREE: pluralsight.pxf.io/c/1291657/...
Dart beginners guide. Dart has various Function Parameters such as Required Parameters, Optional Positional Parameters, Optional Named Parameters and Optional Default Parameters. In this video we will explore Optional Named Parameters.
Next Video : • Dart Optional Default ...
Previous Video : • Dart Optional Position...
Code Files: bit.ly/2KhY4Cv .
.
Please donate and support my work
(If you think my free tutorials are better than paid ones :)
- Patreon: bit.ly/patreon-donate
- 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-courses
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-linkedin
Facebook: bit.ly/smartherd-facebook
Instagram: bit.ly/sriyank-instagram
Twitter: bit.ly/sriyank-twitter
Github: bit.ly/smartherd-github
--- Thank you for your love and support ---

Пікірлер: 53
@huzaifak_08
@huzaifak_08 Жыл бұрын
Use the Keyword 'required int breath' in named parameter , who is facing issue in latest version of dart
@MohammedAlmawali
@MohammedAlmawali 8 ай бұрын
me
@khoroshoigra8388
@khoroshoigra8388 3 жыл бұрын
I rushed my self to learn the flutter, for an exam about a job position in internal as mobile dev then luckily I found this great tutorial !!!!
@sdmagic
@sdmagic Жыл бұрын
As in the previous video, Dart 3.0 changes the rules. It only allows null for parameters that are a nullable type. So, in the example given, you must provide a default value for the named parameters. Thus, the function becomes: void findVolume(int length, {int breadth = 10, int height = 30}) {... With that said, you can still reorder the parameters in the caller. So, for the function I gave here, you can still call it this way: findVolume(10, height: 20, breadth: 5); And finally, Dart 3.0 will not allow a function that's declared to return an integer to return a null. So, int findVolume() won't work. You must use: void findVolume().
@nolssmit
@nolssmit Жыл бұрын
Updated (Dart 3) version: void main() { var result = getVolume(2, breadth: 3, height: 10); print("Volume is $result"); print(""); print("Circumference is ${getLength(2, height: 10, breadth: 3)}"); print(""); print("Circumference is ${getLength(2, breadth: 3)}"); } // Positional, (named and required parameters ... between curly brackets) int getVolume(int length, {required int breadth, required int height}) { print("height: $height breadth: $breadth length: $length"); return length * breadth * height; } // Positional, (named, required and optional parameters ... between curly brackets) int getLength(int length, {required int breadth, int height = 0}) { print("length: $length breadth: $breadth height: $height"); return length + breadth + height; }
@Quvothe
@Quvothe Жыл бұрын
Thank you!
@harrisoncorupe9178
@harrisoncorupe9178 2 жыл бұрын
Really good info. Just needs to be updated to reflect dart having null safety.
@saisasisai
@saisasisai 4 жыл бұрын
Nice 👌 Tutorial series ...!
@achmadrf1243
@achmadrf1243 3 жыл бұрын
Hi, i've an issue that the syntax doesn't work when i don't use required keyword next to the parameter. How to solve it?
@noob_gamer07
@noob_gamer07 5 жыл бұрын
if i make middle parameter as named parameter then it trouble shoot error
@whitehawk4671
@whitehawk4671 2 жыл бұрын
Hey @Smartherd why my IDE is saying to add a required keyword while writing named parameter??
@karthickrajalearn
@karthickrajalearn 4 жыл бұрын
In 1m 28sec Thanks for Tip Named Parameter Purpose : Prevent Errors if function has large numbers of parameters Adavantage : Sequence does not a problem
@hiteshgarg6303
@hiteshgarg6303 6 жыл бұрын
Please start flutter tutorial series also.
@smartherd
@smartherd 6 жыл бұрын
Soon after dart
@flutterwithjt9345
@flutterwithjt9345 3 жыл бұрын
Hi @Smartherd. Can we use both positional and named parameters at the same time for the same parameter?
@givenstudio6409
@givenstudio6409 5 ай бұрын
yes you can
@ranjeetbudhathoki1460
@ranjeetbudhathoki1460 5 жыл бұрын
why to use optional parameters?
@NasGameOrg
@NasGameOrg 2 жыл бұрын
int function,,, says error.. void acceptable only
@firasatali8395
@firasatali8395 Жыл бұрын
void main(){ findvolume(10, 20, 30); } int findvolume(int length, int breath, int height){ print("lenght is $length"); print("breath is $breath"); print("height is $height"); print("volume is ${length*breath*height}"); } I encountered an error : "The body might complete normally, causing 'null' to be returned, but the return type, 'int', is a potentially non-nullable type." so in beginning of the function had to remove "int". then it worked.
@nikhiljohnjose6739
@nikhiljohnjose6739 2 жыл бұрын
Hi, I tried the Volume code but in the function definition it says "the parameter 'height' can't have a value of null because of it's type". That's one error.. when I removed the int from before the breadth and height, it didn't mark them as errors but in the function body breadth and height would be marked error ("A value of type num can't be assigned to variable of type int). Please help :) P.S: In the last video on positional parameters there was a similar error.. I had to remove String from inside the brackets e.g: [String name3] -> was an error [name3] -> got solved
@TheChartwhisperers
@TheChartwhisperers 2 жыл бұрын
Add a required keyword e.g {required int height}
@imranullah7722
@imranullah7722 2 жыл бұрын
@@TheChartwhisperers but return type function is int also give error
@imranullah7722
@imranullah7722 2 жыл бұрын
watch this vedio you will b clear perfectly kzbin.info/www/bejne/bp-rqmmNp5eEn7c
@sourabhsingh7491
@sourabhsingh7491 Жыл бұрын
@@imranullah7722 use null null safety symbol after the datatype
@rananomantariq4593
@rananomantariq4593 2 жыл бұрын
hello hope your doing well can you pls tell us about function call backs in flutter or dart
@rananomantariq4593
@rananomantariq4593 2 жыл бұрын
or you can recomment a video pls hlp thank you
@avi8034
@avi8034 4 жыл бұрын
Since we have written ' int findVolume( ) ' , why we have not written a ' return length*breadth*height ' ? And my code was showing error when i printed it in the function itself then i printed it in main ( ) and it showed no error and got executed . Here is my code sir : void main ( ) { var result= findVolume(10, breadth:5, height:20); print("The Volume is $result"); } // Optional Named Parameters int findVolume(int length, {int breadth, int height} ) { return length*breadth*height; }
@attimeequalszero6750
@attimeequalszero6750 4 жыл бұрын
What is the error message shown?
@SeraphimTech_io
@SeraphimTech_io 6 жыл бұрын
Hi could you please start tutorial for python language? thx
@smartherd
@smartherd 6 жыл бұрын
Will ask Annie to make videos on python. It's in our queue
@SeraphimTech_io
@SeraphimTech_io 6 жыл бұрын
thanks so much master
@jashandeep5378
@jashandeep5378 Жыл бұрын
I am running on visual studio
@harshbarnwal1879
@harshbarnwal1879 4 жыл бұрын
from now in named parameters : is replaced by =
@ithelightr3020
@ithelightr3020 4 жыл бұрын
Thanks Harsh
@ithelightr3020
@ithelightr3020 4 жыл бұрын
But no thanks . It doesn't compile
@TheChartwhisperers
@TheChartwhisperers 2 жыл бұрын
It’s been reverted back to :
@tanaysingh9124
@tanaysingh9124 4 жыл бұрын
why you didn't use return here?
@attimeequalszero6750
@attimeequalszero6750 4 жыл бұрын
The function here is only printing the result and not returning any value back. The return type void would have been better in this example.
@shafi.z7
@shafi.z7 Жыл бұрын
Instead of int use var
@whatsaappstatus6452
@whatsaappstatus6452 3 жыл бұрын
While using int in named parameters its showing error . Plz make it var and it will work 👍
@kishansindhi6963
@kishansindhi6963 3 жыл бұрын
Its due diff in versions. You can see the video was uploaded in 2018. There will be such kind of errors.
@kishansindhi6963
@kishansindhi6963 3 жыл бұрын
for more detail check this video kzbin.info/www/bejne/gaOcpJmflNV6apI
@sifatcreator1175
@sifatcreator1175 Жыл бұрын
you don't show the default parameter
@adeeba_rafi
@adeeba_rafi 6 ай бұрын
If found error write required before int here is the correct code void main() { findVolume(2, 3,height: 9); } void findVolume(int length, int breadth, {required int height }) { // In named Parameter Sequence doesnot matter print(height); print(breadth); print(height); print("${length * breadth *height}"); }
@rockstreethomie
@rockstreethomie 2 жыл бұрын
named parameters not working
@TheChartwhisperers
@TheChartwhisperers 2 жыл бұрын
Add required e.g {required int height}
@delphinepauwels
@delphinepauwels 2 жыл бұрын
@@TheChartwhisperers but if I don't want a required parameter, but an optional one?
@jashandeep5378
@jashandeep5378 Жыл бұрын
void main() { Area1(10,2,height: 3); } void Area1(int lenth, int breath, {int height}){ int area=lenth*breath*height; print(area); } // Sir My Code is not working as this
@benjaminmariga3938
@benjaminmariga3938 Жыл бұрын
The error is occurring because you declared the height parameter as a non-nullable int type, but you're not providing a default value for it. To fix this issue, you have two options: A)you can provide a default value for the parameter example Area1(int lenth,int breadth,{int height=1})...... B)You make the parameter non-nullable Area1(int lenth,int breadth,{int? height}) //my code wasn't working and with these approaches it finally worked.Hope it helps
@benjaminmariga3938
@benjaminmariga3938 Жыл бұрын
void main() { int area = Area1(10, 2, height: 3); print(area); } int Area1(int lenth, int breath, {int? height}) { int area = lenth * breath * (height ??1); //I used the null-aware operator ?? to provide a default value of 1 when height is null return area;
@firasatali8395
@firasatali8395 Жыл бұрын
void main(){ findvolume(10, breath:20, height:30); } findvolume(int length, {int breath, int height}){ print("lenght is $length"); print("breath is $breath"); print("height is $height"); print("volume is ${length*breath*height}"); } ENCOUNTERED AND ERROR IN ABOVE CODE: "The parameter 'breath' can't have a value of 'null' because of its type, but the implicit default value is 'null'. Try adding either an explicit non-'null' default value or the 'required' modifier. " "The parameter 'height' can't have a value of 'null' because of its type, but the implicit default value is 'null'. Try adding either an explicit non-'null' default value or the 'required' modifier." SOLUTION: remove "int" with-in the curly brackets before "breath" and "height" Ex:- findvolume(int length, { breath, height}){
마시멜로우로 체감되는 요즘 물가
00:20
진영민yeongmin
Рет қаралды 29 МЛН
Red❤️+Green💚=
00:38
ISSEI / いっせい
Рет қаралды 65 МЛН
아이스크림으로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 57 МЛН
One moment can change your life ✨🔄
00:32
A4
Рет қаралды 19 МЛН
Positional Parameters in Dart  | Dart Tutorial #27
6:40
Flutter Teacher
Рет қаралды 1,2 М.
Dart constructor and parameters
6:21
dbestech
Рет қаралды 2,5 М.
마시멜로우로 체감되는 요즘 물가
00:20
진영민yeongmin
Рет қаралды 29 МЛН