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

The "Dart Overview" 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 introduces Dart, a programming language created by Google. It is a versatile language because the same codebase can be compiled into source code, bytecode, or machine code depending on the targeted platform. A question about Dart's optional null-safety feature is also covered in this segment.


Transcript from the "Dart Overview" Lesson

>> We're gonna use a language that probably isn't used before, okay? It's actually difficult to find a Dart developer out there that personal experience in Flutter, actually, okay? Dart is a language created by Google, okay? So Google created Dart as an open source language around ten years ago.

I remember being there in San Francisco in Google IO when it was announced. And it was kind of weird to hear about the new language, mostly because of why they created the language. So it's a statically typed language. So compared with JavaScript, it has that difference, means that we need to compile.

We are going to compile code and every variable has a type, it's not like JavaScript. But the original intention of Dart, was actually to replace JavaScript in the browser. So, that's ten years ago even more than ten years ago. So, I think whilst we're, unless you know, at this point it didn't work.

So that idea of replacing JavaScript with a new client side language didn't work. Fortunately, I will say. So, I remember there was only one version of Chrome the The Chrome Canary, that's the alpha version. There was one version supporting Dart directly client side, okay? But that idea didn't work.

But then Flutter appear a few years later. And Google said, okay, we have a language, let's use it. Okay, so now it's like the new life of Dart. Of course, you can do more things with Dart. But like server code or normal scripting, but most of the time today, we will use Dart with a Flutter.

So we didn't lose type inference. We will see these in a minute. So no worries. It's multi-platform so it has compiler for mostly all the platforms available today. Easy to learn, okay? So if you know Java or C sharp, it's actually pretty similar with some additions or with some addition from other languages, including JavaScript.

It has less ceremony. Less bureaucracy than for example, Java, okay? But it's still similar to Java, okay? It includes some other ideas such as promises, okay? It has a different name here. It's called Future. It's not 100% the same as the promise but it's kind of the same at this point.

And it includes optional new safety. So you can enable null-safety if you want to and I will explain what that is if this is the first time you're hearing about null-safety in a minute. So that's the idea of Dart as a language,okay? As I mentioned before it was originally for internal web and work to replace JavaScript fortunately it didn't work.

And today to carry intention the current target of Dart is to create in front-end apps including Flutter and AngularDart. So if you're an Angular developer you can decide to use Dart instead of TypeScript for example, okay? But anyway, that's not for today. Today, we are going to be covering Flutter.

And it's inspired by T Java JavaScript Erlang small talk even a little bit of Swift and Kotlin. We will be using Dart 2, 2 point something, okay? But that is different from dot 1. So it's actually not compatible. So the version that we will be using of the language is called Dark 2,okay?

And Dart compiles into native code and intermediate language and even compiled to JavaScript. And we are gonna see what that means in a minute. So it's actually one of the most multi platform languages out there because we can actually get Dart code and compile that into Intel 64 bits architecture, ARM.

We can also compile to a B machine that that can be executed in different operating system without recompiling. And we can compiled to JavaScript compile in quotes, right? So we can transpire if you want. We can get an output in JavaScript. So then you can run in the browser.

So, we are going to be using Dart 2, and if you wanna play with the language without installing any compiler, okay? You can go to, they'll let you play with Dart in the browser. Because it can compile to JavaScript, it's actually pretty simple to make a Dart compiler client inside, okay?

Make sense? So every Dart application has a main function, so similar to C or Java. So we are going to start with the main function. It has full object oriented programming with type inference, meaning that everything will be an object in Dart. So this is kind of similar to Java.

It's even more extreme than Java. Because in Java, like an int, with a lowercase is not actually an option. Well here everything is an object, okay? Everything comes from a class in Dart. No safety is available as an optional feature. And actually when we are making flatter applications today, it's enabled by default, like a year ago, it was actually disabled by default, no safety.

It feels easy to understand, and it has feature for many languages, such as Extension, Mixins, Futures that is async programming similar to promises. But when compiling to the web, this is important we need to remember, that the code is going to be executed in the JavaScript built on machine.

With all the advantages and disadvantages of that, okay? So meaning that the security of our objects might not be the same when we are running our Dart code in a native platform than on the web. Because on the web everything is being converted to JavaScript. And we know that JavaScript sometimes it doesn't contain hard limits for options for example, I can mess with the prototype of objects, I can change the type of variable, and transcript, the runtime will not complain.

If I have a variable defined as in the string and I changed the value to an integer, who is going to complain in the browser? No one, okay? So, have in mind that we have those differences when we are targeting different platforms. So in terms of where Dart goes, typically, we know that we have some languages such as JavaScript, where we ship source code.

We have some other languages, such as Java, where we ship bytecode. That is an intermediate language and then we have a built on machine. And we have compiled languages, such as Dart that actually compiles into machine code, okay? And that means that you need to compile for every different platform like ARM, Intel and other architectures that you have.

And for Intel, you have different architectures per operating system as well. But I already mentioned that Dart is I do enough so we can actually get into the three words at the same time. So you write Dart and you can compile to JavaScript, so you get an output JavaScript source code that is not intended for human interaction, right?

So we are not going to we touch or develop on top of that JavaScript code. It can compile into bytecode and that has its own built on machine and it isn't compiled to machine code. Well let me tell you this when we are building web apps actually we're going to shape the source code.

So if you're making with Dart, with Flutter web apps, that's our target. If we are targeting desktop operating systems such as Linux, Mac OS, or Windows, we will be shipping bytecode. And if we are targeting iOS or Android we're going to ship machine code directly. We then we then need to make this decision, okay?

This happens automatically behind the scenes but have that in mind the same codebase will actually get completely different outputs with completely different nature, okay? From the same codebase you have any questions? That's fine.
>> I was just wondering why Windows platforms when compiled to the machine code.
>> Actually with performance because on desktop they can perform.

So on desktop they can perform better with a brutal machine that it might not be so simple. Actually on iOS, for example, it's forbidden to have a built on machine. So if you're making an iOS application, you cannot include the IBM like with the just in time compiler is not possible.

So a technical issue, it's a commercial issue from the Apple platform. So I think that's the reason. So on mobile for performance and because of the restrictions of the app stores, they are actually compiling to machine code and not to the IBM. Question on the chat?
>> Can you make command line binaries?

>> So if you wanna do binaries, yeah, it's like in machine code. So, you can target machine code for different operating systems. So, in that case you need to pick the operating system. And I mean if you wanna create a Linux output and install like a CLI or something like that, yeah it's possible.

>> Someone was asking what did you mean by null-safety?
>> Okay, we will get into null-safety in a minute with some examples. But it's the ability on a language like Dart to actually express if we accept nulls or not any variable. So if you're writing Java or C sharp or even PHP, if you create a variable, okay, and you don't set the value to it, it stores no, okay?

So by default it's null. Well, actually when you have null-safety language with null-safety, it cannot be null unless you say so. So, you as a developer can actually make the decision if each variable if you accept nulls or not. So it had to do with the semantics of your code, and it will reduce the amount of bugs that you have in your code.

So today modern languages such as Dart ,Swift, Caitlyn ,Go and many others are actually supporting null-safety, okay? And this is also coming to other languages as well. C sharp has also null-safety, there is an optional way to do that as well, but it was like something that the others later on C Sharp, okay?

But we will see an example of that in a minute.

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