Dart: Different types of functions in Dart To Help You Write Your Flutter app.
Dart: Different types of functions in Dart To Help You Write Your Flutter app. Tiya Chows Follow Sep 18 · 2 min read

A quick low down on the different types Dart functions you might come across.

Types of functions:

void functions e.g

void greeting() {

print(‘hello’);

}

2. functions with a return type e.g

String greeting() {

return ‘Hello’;

}

3. functions that take parameters

i. mandatory parameters e.g

void greeting(@required String greeting){

print(greeting);

}

ii. optional parameters

optional positional parameter e.g

void details([int telephone]) {...}

optional named parameter e.g

void details({String firstName, String lastName}) {...}

optional parameter with default values e.g

void details({int age: 30}) {...}

a function with all possible types of parameters:

void details (int id, [int telephone],{String firstName, String lastName}, {int age: 30}) {...}

and you could call it with:

details(1001) details(1001, 078787878787, firstName: John, lastName: Ham, age: 50)

4. Getters and Setters

Special methods that provide read and write access to an object’s properties.

class Car {

String make; Car({this.make}); String get make => make; void set make(String name) => make = name; }

to call:

Car myCar = Car(‘Porsche’); print(myCar.make);

Different Function declarations:

Regular function e.g

void greeting {

print(‘hello’);

}

2. Lambda function/arrow function is a short form of a regular function that can only return one expression. (Arrows instead of curly brackets). e.g
['Tiya Chows']
['Flutter App Development', 'Software Development', 'Software Engineering', 'Programming', 'Flutter']