Learn Just Enough Dart For Flutter: Part 2

A beginner’s guide to learning dart and flutter

Manthan Gupta
TheLeanProgrammer
2 min readApr 21, 2020

--

In Part 1 you all learned about print function, variables, and types, and operators and I hope you now have a clear understanding of the same. So, let’s move forward and learn some more interesting things and get you equipped so that you can start coding some awesome apps in Flutter.

Let’s get started with Functions

Functions

Functions are the building blocks of readable, maintainable, and reusable code. A function is a set of statements to perform a specific task. Functions organize the program into logical blocks of code. Once defined, the functions can be called as many times as you want to perform the task.

What if you want to pass some values in the function?

Parameterized Function

Parameters are a mechanism to pass values to functions. Let’s take an example that you want to print the factorial of a number. You will have to write the code 3 times if you want to calculate the factorial of 3 numbers. But if you write a function for it then you just reduced your work. Here the parameter you will pass is the number whose factorial is to be calculated.

Now you see how easy it is?

There is shorthand for writing these functions

What if you want to make it optional to enter a certain parameter when the function is called?

Named Parameters

Named parameters can be specified by having the parameters of the function inside curly braces {}. Any parameter inside the curly braces is not compulsory to enter.

Now, what if you want to have a default value for a parameter?

Default Parameter Values

You can give a default value to named parameters. So, when you call the function and you don't assign a value to that parameter then the default value will be given to it.

That’s all for this part 2. You can find the link to the next part here. I hope you all liked this part! If you did so then smash that clap button so that it disappears from Medium. Also, don’t forget to leave constructive comments if you think there is room for improvement.

You can follow me on LinkedIn, Github, and Twitter.

Click here to read the previous one.

Don’t forget to follow The Lean Programmer Publication for more such articles, and subscribe to our newsletter tinyletter.com/TheLeanProgrammer

--

--