Dart Basics | raywenderlich.com

Get an introduction to the basics of the Dart programming language, used for development with the Flutter SDK for mobile, web, and beyond.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4482551-dart-basics

Minor edit tweak: text reads " You can also combine strings use the + operator:“, should read " You can also combine strings using the + operator:”

Thanks for pointing that out @daviderb! It’s been fixed.

another small typo:
numbers.forEach((number) => print(num));
should be:
numbers.forEach((number) => print(number));

Thanks @akumaikaruga! It’s fixed now.

Thanks a lot, it was easy to catch-up with dart basics :slight_smile:
Keep up the good work

Arrow Syntax

When a Dart function, either named or anonymous consists, consists of just one line of code, you can reduce the function body using the Dart arrow syntax .

Isn’t there one too many “consists” ?

Minor point …

You can call forEach on the list and pass in an anonymous function that triples each number in the list and prints out that value:

numbers.forEach((number) {
var tripled = number * 3;
print(tripled);
// 3
// 6
// 9
});

=========================

I would not say “and pass in an anonymous function”, I would say “and uses an anonymous function” or “and uses a simple closure” unless it was re-written like …

var tripled = (number) => number * 3;

numbers.forEach((number) {
print(tripled(number));
// 3
// 6
// 9
});

Minor point …

Thanks for finding that @knowself! Fixed.

@esraa.ibrahim Really glad you like it! Cheers! :]

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!