Programming in Dart: Functions & Closures

Jun 21 2022 · Dart 2.16, Flutter, DartPad

Part 2: Learn Anonymous Functions & Closures

13. Challenge: Write an Anonymous Method

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 12. Map & Filter Collections Next episode: 14. Create a Closure

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

By now, you should feel comfortable writing anonymous methods so why not practice with a challenge? In your challenge, I want you to create a list of scores of forty three, eighty six, ninety nine, and three. Put those scores in a list.

  var numbers = [43, 86, 99, 3];
var even = numbers.firstWhere();
var even = numbers.firstWhere((item) {

});
var even = numbers.firstWhere((item) {
    if (item % 2 == 0) {
        return true;
    } else {
        return false;
    }
});
print(even);
var even = numbers.firstWhere((item) {
    return (item % 2 == 0);
});
var even = numbers.firstWhere((item) => item % 2 == 0);