[
Provider<FirebaseAuthService>(
create: (_) => FirebaseAuthService(),
),
Provider<ImagePickerService>(
create: (_) => ImagePickerService(),
),
],
What does this syntax (=>
) mean?
_MyAppState createState() => _MyAppState();
Dart arrow function The arrow function allows us to create a simplyfied function consisting of a single expression. We can omit the curly brackets and the return keyword.
Lambda functions are a short and simple way to express tiny functions. Lambda functions are also known as arrow functions. Like any other function, a Lambda function cannot execute a block of code.
The => e syntax is shorthand for a function body of the form {return e;}. Notice how the return type is omitted. Dart is an optionally typed language, so the programmer is free to omit static type declarations.
From the documentation:
For functions that contain just one expression, you can use a shorthand syntax. The
=>
expr syntax is a shorthand for{ return expr; }
. The=>
notation is sometimes referred to as arrow syntax.Note: Only an expression—not a statement—can appear between the arrow (=>) and the semicolon (;). For example, you can’t put an if statement there, but you can use a conditional expression.
Code example:
The following function:
int sum(int x, int y) {
return x + y;
}
Is the same as:
int sum(int x, int y) => x + y;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With