What is the Dart Return Values in Dart?

Dart Return Values

Sometimes we may want a function to return some value to the point it where it is called from. In Dart, there is return keyword allows a function to return value. The return statement is optional, if not specified the function returns null. There can be only one return statement in a function.

Dart Function With Return Value

Syntax:-

12345return_type func_name(){   //Statement(s)   return value;}

func_name :- It is replaced with the name of the function.
return_type :- It represents return_type of the function. The return_type can be any valid data type. The data type of the value returned must match the return type of the function.

Example:-

1234567String sayHelloWorld() {   return “Hello, World!”;}void main(){   print(“flutterfever.com – Dart Function With Return Statement.”);  print(sayHelloWorld());}

Output:-

flutterfever.com – Dart Function With Return Statement.

Hello, World!

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More