Check out a free preview of the full Cross-Platform Mobile Apps with Flutter course

The "Functions Q&A" Lesson is part of the full, Cross-Platform Mobile Apps with Flutter course featured in this preview video. Here's what you'd learn in this lesson:

Maximiliano answer questions about function parameter syntax, optional parameters and if void has a type.


Transcript from the "Functions Q&A" Lesson

>> Is void in object?
>> Void is a data type. So data types are not objects. So it's not an option, but you can't have a variable of type void. And so you cannot have a value of type void. So you can have void objects, but void by itself is a type types are not objects, at least not the normal objects.

So Int is not an object, you can have objects of type Int, okay? Makes sense.
>> What does it mean when there are square back brackets in the parameter list?
>> I'm not sure if we have one of those examples, but typically if you have a function call, and you have square brackets, typically that's a list.

So you're passing a list as an argument. Again, it depends on the case here we'll see a couple of these cases later in flutter, where some arguments will need a list but here as in JavaScript. When you see a square brackets you're looking at a list, so arrays, collections of data.

If you have a function returning a list, the type goes first. And it goes like this list, and then you use angle brackets, not square bracket. So if you wanna list of integers that creates a great, at least it will be like this and your return something like this.

There, I'm not sure if you understand where that sample is coming from.
>> Yeah, he said it's code that he was reading elsewhere and in the function signature, the parameters had string, string, string, and then bracket, string question mark or whatever.
>> Well, yeah, probably I have to see the code and try to think exactly what's going on, but because it can be many things, actually.

Yeah, we'll have to see the code. But anyway, every time you see this is typically we're talking about lists, maybe it can be a default value of a list. I don't know. It can be many things, all right? But have in mind that you don't have anything after the function name, all right?

So like this, so here it goes first, like in copying or Swift, you define the type after, here it's.
>> What are function parameters? So in create list you would go like string name.
>> We weren't doing this, but was not angled it just curly braces, okay?
>> Yeah, not curly braces, so it just be like a string name not what the brackets.

>> You're talking about this, something like this.
>> And then, yeah.
>> This is where you're saying something like this.
>> Yes string and then there was a question mark.
>> Yeah, this is making it like optional. Actually, we're not going to use this in flutter. So flutter doesn't use this pattern, okay?

Have you seen, now I understand what [LAUGH] what was the idea. So actually you can make this with positional arguments. So also like this.
>> Exactly, that's how it was working, yep.
>> Like that to be it. That's how it works. But most of the time, you're going to mix this between, so the premise that everything you put there must have the same signature.

And most of the time, what we want is to use curly braces because typically you have many arguments, some of them mandatory, some of them optional. So for example, in this case I'm making. A name require and then for example, you can have an optional age or something like that and for this, okay?

We have to use some kind of the map Syntax. There is actually curly braces. So we can actually mix requires with optionals. So do have any question on the chat?
>> You said, okay, so like required arguments with optional named arguments.
>> Yeah, we're not going to use that in flutter actually.

So there are many other things in that as the language that are typically useful for backend development, for example. But the flutter SDK is not using because of several reasons, so I tried to stay here today in the parts of the language that you will use in a flutter application.

But there are more things like mixing and other stuff that you can get into the dart website, That's a website used to, but now because we have the Dart dev, top-level domain, it's Dart or Dev. There is a nice step by step, playground based, let's say documentation there so we can go step by step with everything within that.

>> And then in arguments they cannot be renamed like named in the other language.
>> They're part of the signature. Okay, so you cannot rename them so I know what you're.
>> Because we did it like fun.
>> So what you're asking if? Okay, I got you.
>> If we have another name for the outside?

>> So you wanna use a different name?
>> For the outside.
>> For the argument and a different name for the local variable. Yeah, no like in Swift.
>> Yeah, in swifts though.
>> No.
>> Just check. Just asking.
>> No way to go up here.
>> [LAUGH] Okay.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now