Browser to Beyond: A Front-End Developer's Path to Mobile Development
Notes on Dart
Introduction
Hey there ๐, it's me again ๐. Today, I will be sharing my notes on Dart. Not the practical aspects, just the theory. Okay, let's begin!
What is Dart?
"Dart programming is a computer language used for creating software applications. It is easy to learn and understand because it uses simple syntax and structure. Dart is object-oriented, meaning it focuses on creating reusable pieces of code called objects. It is used for building web, mobile, and desktop applications."
The above definition establishes the following facts:
Dart is a computer language used to tell a computer what to do and how to do it.
Dart is easy to learn, understand and use. Which is expected being that Dart is a high-level language.
Dart is object-oriented, meaning that Dart allows us to build reusable parts, like using one headgear (gele) to make different styles.
Dart can be used to make apps for your phone, laptop, MacBook, and for the web.
The History of Dart
Dart was first introduced in 2011 at a conference for smart people called the GOTO Conference, held in Aarhus, Denmark, from October 10โ12, 2011.
Dart was designed by Lars Bak and Kasper Lund and developed by Google.
The first version of Dart Dart 1.0
was released on November 14, 2013. Unfortunately, Dart didn't get the warm welcome it deserved. Why? The guardians of the web were worried that Dart might harm our beloved web because of its plans to include a Dart VM in Chrome. However, in 2015, those plans were dropped with the release of Dart 1.9
. The focus shifted from including a Dart VM in Chrome to compiling Dart code to JavaScript
(The official language of the Web). Now, the guardians of the web can finally rest easy.
August 2018 saw the release of Dart 2.0
, which featured language changes including a type system, making Dart easier to use. Dart 2.6
introduced a new extension, dart2native
. This extended native compilation to the Linux
, macOS
, and Windows
desktop platforms. It allowed people to make apps not just for phones but also for computers like Windows
and Mac
.
May 2023 witnessed another massive update, Dart 3.0
. This update made sure that Dart was super safe and added new features to make it even more powerful.
One of the coolest things is that now Dart, Dart 3.22
can turn its code into something called WebAssembly
, which is like making it work super fast on websites. Another dose of rest to the guardians of the web.
Overall, Dart keeps getting better and better, helping people make cool mobile apps and websites!
The Relationship Between Flutter and Dart
Do you know the old saying, "beside every successful man there is a woman"? Well, I think that saying applies quite well to Flutter and Dart. Flutter is great, no debate, but I think Dart can easily beat her chest and say, "I made you! You are nothing without me." Haha, I guess the Nollywood drama in me just couldn't resist!
On a more serious note, when Flutter was developed, the Flutter team tried out many languages and decided Dart was the best match. They work well together, just like an old married couple who understand each other and sync up perfectly.
How do they work together?
Think of Dart and Flutter like a fun team working together to help you create cool things.
Dart: is like a special language that we use to tell the computer what to do.
Flutter: is like a box of supplies that helps you draw and build beautiful pictures, games, or apps. It takes the instructions you wrote with Dart and turns them into something you can see and use on your phone or computer.
Here is an example using a chef and recipe book analogy:
Dart: Imagine a chef trying to make a new dish. Dart would be the recipe book that contains instructions to follow, like "add a pinch of salt" or "pour water into a bowl," etc.
Flutter: Now, imagine Flutter is the chef in the kitchen with access to utensils, appliances, and ingredients. The chef reads the instructions in the recipe book (Dart) and follows each instruction religiously in order to make the dish.
Basically, when you want to make an app, you write down what you want it to do using Dart. Then, Flutter takes those instructions and helps you build the app so it looks nice and works well on your phone or computer. They work together to make creating apps easier.
Features of Dart
Dart has a whole lot of features. Below are some of the characteristics of Dart:
Familiar Syntax: Dart's syntax is similar to languages like Java and C, making it easier for developers familiar with these languages to adapt. Some say it's also similar to JavaScript. ๐ค I guess I'll find out.
Ahead of Time (AOT) Compilation: Dart can compile code directly into native machine code for faster performance in apps.
Code Reuse: Dart allows developers to reuse code between mobile and web apps, potentially saving development time.
Open Source: Dart is freely available and comes with tools for compiling and running Dart code. It's widely used and has a permissive license.
Type Safe: Dart ensures that variables have values that match their declared types, ensuring reliability in code.
Hello Dart: First Dart Code
It is no news that when learning a new language, the first line of code you will be tasked to write is "Hello, World!" Sometimes I wonder why that is. ๐ค Why not "Goodbye, World"?. In the spirit of breaking from tradition, let's write our first "Hello Dart" code.
void main() {
print("Hello, Dart!");
}
Code Explanation
void main() {
:- This line defines the main function. In Dart, the main function is the starting point of any application. The word
void
means that this function doesn't return any value.
- This line defines the main function. In Dart, the main function is the starting point of any application. The word
print("Hello, Dart!");
:
Inside the main function, we have a
print
statement.print
is a built-in Dart function that outputs text to the console.The text
"Hello, Dart!"
is a string, which is a sequence of characters enclosed in double quotes.
3. }
: This curly brace closes the main function, indicating the end of the code that runs when the program starts.
In summary, this code defines a simple Dart program that, when run, will print "Hello, Dart!"
to the screen. It is important to note that Dart files should end with the .dart extension, e.g., Blogs.dart
.
Conclusion
And there you have it! We've taken a deep dive into the world of Dart, exploring its history, features, and its married-like relationship with Flutter. Dart's simplicity, object-oriented nature, and versatility make it a powerful tool for developing applications across various platforms. Whether you're building for the web, mobile, or desktop, Dart has got you covered.
I hope you found these notes helpful and that they inspire you to explore Dart further.
If you enjoyed this article, please like, comment, and share. Don't forget to subscribe to my newsletter to stay updated with my future articles. Let's continue this journey together! Until next time, Happy Darting!๐.