Programming in Dart: Functions & Closures
You’ll continue to build on the lessons taught in the Programming in Dart series by learning how to write functions to maximize code reuse as well as to filter and map collections. You’ll also be introduced to self-contained functions called closures to take your Dart code to the next level. By Brian Douglas Moakley.
This is part of the Flutter Fundamentals learning path. View path.
Who is this for?
This course is written for people who are new to programming! If you don’t know the difference between a function or an object, you’ve come to the right place.
Before starting, you should have watched Programming in Dart: Fundamentals and Programming in Dart: Control Flow & Collections. This course will build on those foundational concepts and expand on your understanding of the Dart programming language.
- Optional & named parameters
- Function variables
- Alias functions
- Arrow notation
- Anonymous functions
Part 1: Meet the Function
Gain an understanding of functions in Dart and then receive an overview of all the various concepts that will be covered in the first part of the course.
Meet the function! Learn how to define functions and then how to use them throughout your code.
Make your functions easier to use by providing options to the function caller. Of course, doing so requires you to write your parameters in a special way.
Named parameters make your function easier to use and easier to read. Learn how to define named parameters to make your code self documenting.
Now that you have a good idea about functions, your first challenge in this course is to write your very own function. Don’t worry - it’s not too hard.
Store a Function
One of the coolest parts of functions is storing them and passing them around like any other variable. This episode will get you started.
Learn how to define an alias to functions to make your them easier to both use & read.
Use Arrow Notation
Dart provides a nice little shortcut when writing functions called arrow notation. While it makes your functions easier to read, it raises questions about the void return type.
This episode wraps up the first part of this course, but things are just getting started. You’ll get a review of what was covered.
Part 2: Learn Anonymous Functions & Closures
In this next part, you’ll learn about creating anonymous functions and closures and the capabilities that they provide to your code.
Learn the basics of writing anonymous functions as well as why you’d even want to use them in the first place.
Put anonymous functions to use by using the map function and the filter function on Lists to both transform and filter values.
In this first challenge of the part, you’ll put your knowledge of anonymous methods to the test by filtering out a list.
Create a Closure
Understand the basics of closures - why you’d use them and how they can maintain their own internal state.
Learn the theory behind the idea of generics; why it is useful and how it can make your easier to maintain.
Understand the basics of writing generic functions. That is, writing a function that can be used by many different types.
Now that you understand generics, you’ll put your new knowledge to the test by writing a method that filters a collection of numbers.
With this course complete, learn about some next steps as well as some additional resources to continue your Dart learning journey.