positional arguments dart
void main() {
print(fullname("yo", "hope you have amazing day"));
}
// this fancy [] will do the job
String fullname(String fname, String lname, [String age = '23']) {
return fname + lname + age;
}
positional arguments dart
void main() {
print(fullname("yo", "hope you have amazing day"));
}
// this fancy [] will do the job
String fullname(String fname, String lname, [String age = '23']) {
return fname + lname + age;
}
dart positional arguments vs named arguments
void main(){
var catBob = Cat('Bob', 'Grey');
// display object with positional argument
print(catBob.displayCat());
// display object with constructor and named arguments
print(Dog(breed: 'Bulldog', name: 'Greg', color: 'Purple').displayDog());
}
// Cat class - with simple constructor and positional arguments
class Cat{
// properties
String name;
String color;
// simple constructor
Cat(this.name, this.color);
// method to display cat
String displayCat() {
return 'my cat is ${name} and he is ${color}';
}
}
// Dog class - with constructor and named arguments
class Dog{
String name;
String breed;
String color;
// constructor with named arguments
Dog({this.name, this.breed, this.color});
// method to display cat
String displayDog() {
// interpolate 'breed, name, color' with ${ value }
return 'my ${breed} is ${name} and he is ${color}';
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us