Introduction to the Programming Language Used by Flutter
Flutter uses Dart as its programming language. Dart is used to write Flutter application logic, user interfaces, widgets, data models, API-related code, and application functionality. JustAcademy's Flutter curriculum introduces Dart as part of the foundation of Flutter development and covers programming fundamentals, object-oriented programming, collections, and asynchronous programming. :contentReference[oaicite:0]{index=0}
Explore JustAcademy's Flutter Training
Register for Flutter Course Demo
1. What is Dart?
Dart is a modern programming language used to develop applications with Flutter. In Flutter development, Dart is responsible for writing the application's logic and defining how the user interface behaves.
Dart provides programming features such as variables, data types, operators, conditions, loops, functions, classes, objects, collections, exception handling, and asynchronous programming.
According to JustAcademy's Flutter curriculum, Dart is introduced at the beginning of the Flutter learning path, followed by a dedicated Dart Programming Fundamentals module covering variables, data types, operators, control statements, functions, OOP, collections, and asynchronous programming. :contentReference[oaicite:1]{index=1}
Simple Dart Example
void main() {
print("Hello, Dart!");
}
The main() function is the starting point of a Dart program. The print() function displays information in the console.
2. Why Does Flutter Use Dart?
Flutter is designed for building applications from a shared codebase, and Dart provides the programming features needed to create Flutter applications.
Some important reasons Dart fits Flutter development include:
- Simple and readable syntax
- Object-oriented programming support
- Strong support for asynchronous programming
- Null safety
- Good support for UI development
- Support for modern application development patterns
- Integration with Flutter's widget-based development approach
JustAcademy's Flutter curriculum combines Dart programming with Flutter widgets, UI development, navigation, APIs, Firebase, state management, testing, and application deployment. :contentReference[oaicite:2]{index=2}
3. Dart and Flutter Relationship
Understanding the relationship between Dart and Flutter is important for beginners.
| Technology |
Role |
| Dart |
Programming language used to write application code |
| Flutter |
UI framework/toolkit used to build applications |
| Widgets |
Building blocks used to create Flutter interfaces |
| Flutter SDK |
Development tools and libraries required for Flutter development |
In simple terms:
Dart = Programming Language
Flutter = UI Framework
Widgets = UI Building Blocks
4. Features of Dart
4.1 Simple Syntax
Dart syntax is designed to be readable and familiar to developers who have worked with languages such as Java, JavaScript, C#, or similar C-style languages.
void main() {
String name = "Rahul";
int age = 22;
print(name);
print(age);
}
4.2 Object-Oriented Programming
Dart supports object-oriented programming concepts such as classes, objects, constructors, inheritance, abstraction, and polymorphism.
4.3 Null Safety
Dart provides null safety to help developers identify situations where a variable may contain null.
String name = "Flutter";
String? nickname;
print(name);
print(nickname);
The ? indicates that the variable can contain a null value.
4.4 Asynchronous Programming
Dart supports asynchronous programming through features such as Future, async, await, and Stream. These features are especially useful when working with APIs, databases, authentication, file operations, and other tasks that do not complete immediately.
5. Variables in Dart
Variables are used to store data in a Dart program.
String name = "Amit";
int age = 25;
double price = 999.50;
bool isLoggedIn = true;
Using var
var city = "Mumbai";
var age = 25;
Dart can infer the type of a variable when var is used.
Using dynamic
dynamic value = 100;
value = "Flutter";
value = true;
dynamic allows a variable to hold values of different types, although it should be used carefully because it provides less compile-time type checking.
6. Data Types in Dart
Common Dart data types include:
int – whole numbers
double – decimal numbers
num – numbers that can be integers or decimals
String – text
bool – true or false
List – ordered collection
Set – collection of unique values
Map – key-value collection
Object – base type for Dart objects
int quantity = 10;
double amount = 250.75;
String product = "Laptop";
bool available = true;
7. Operators in Dart
Dart supports several types of operators.
Arithmetic Operators
int a = 20;
int b = 10;
print(a + b);
print(a - b);
print(a * b);
print(a / b);
print(a % b);
Comparison Operators
print(a == b);
print(a != b);
print(a > b);
print(a < b);
print(a >= b);
print(a <= b);
Logical Operators
bool isAdult = true;
bool hasId = true;
print(isAdult && hasId);
print(isAdult || hasId);
print(!isAdult);
8. Conditional Statements
Conditional statements allow a program to make decisions.
if Statement
int age = 20;
if (age >= 18) {
print("Adult");
}
if-else Statement
int age = 16;
if (age >= 18) {
print("Eligible");
} else {
print("Not eligible");
}
else-if Statement
int marks = 75;
if (marks >= 90) {
print("Grade A+");
} else if (marks >= 75) {
print("Grade A");
} else if (marks >= 60) {
print("Grade B");
} else {
print("Need improvement");
}
9. Switch Statement
The switch statement can be used when a program needs to select between multiple cases.
String day = "Monday";
switch (day) {
case "Monday":
print("Start of the week");
break;
case "Friday":
print("Almost weekend");
break;
default:
print("Regular day");
}
10. Loops in Dart
Loops are used to execute a block of code repeatedly.
for Loop
for (int i = 1; i <= 5; i++) {
print(i);
}
while Loop
int i = 1;
while (i <= 5) {
print(i);
i++;
}
for-in Loop
List names = ["Amit", "Rahul", "Priya"];
for (String name in names) {
print(name);
}
11. Functions in Dart
Functions are reusable blocks of code that perform a particular task.
void greet() {
print("Welcome to Flutter");
}
void main() {
greet();
}
Function with Parameters
void greetUser(String name) {
print("Hello $name");
}
void main() {
greetUser("Amit");
}
Function with Return Value
int add(int a, int b) {
return a + b;
}
void main() {
int result = add(10, 20);
print(result);
}
12. Arrow Functions
Dart provides a short syntax for functions that contain a single expression.
int add(int a, int b) => a + b;
void main() {
print(add(10, 20));
}
Arrow functions are frequently useful in Flutter code where short callbacks or expressions are required.
13. Lists in Dart
A List stores multiple values in an ordered collection.
List fruits = [
"Apple",
"Banana",
"Mango"
];
print(fruits[0]);
Adding Items
fruits.add("Orange");
Removing Items
fruits.remove("Banana");
List Length
print(fruits.length);
14. Sets in Dart
A Set is a collection that stores unique values.
Set skills = {
"Dart",
"Flutter",
"Firebase"
};
skills.add("REST API");
print(skills);
15. Maps in Dart
A Map stores information in key-value pairs.
Map user = {
"name": "Rahul",
"age": 25,
"isActive": true
};
print(user["name"]);
print(user["age"]);
Maps are particularly useful when handling structured data such as JSON responses from APIs.
16. Object-Oriented Programming in Dart
Object-Oriented Programming, commonly called OOP, is an important part of Dart programming. JustAcademy's curriculum includes classes, objects, constructors, inheritance, polymorphism, and abstraction in its Dart fundamentals section. :contentReference[oaicite:3]{index=3}
Class and Object
class Student {
String name;
int age;
Student(this.name, this.age);
void display() {
print("Name: $name");
print("Age: $age");
}
}
void main() {
Student student = Student("Amit", 21);
student.display();
}
Important OOP Concepts
- Class: A blueprint for creating objects.
- Object: An instance of a class.
- Constructor: Used to initialize an object.
- Inheritance: Allows one class to derive features from another class.
- Polymorphism: Allows the same interface or method concept to behave differently in different contexts.
- Abstraction: Hides unnecessary implementation details and exposes required functionality.
17. Constructors in Dart
Constructors are used when creating objects.
class Product {
String name;
double price;
Product(this.name, this.price);
}
void main() {
Product product = Product("Mobile", 25000);
print(product.name);
print(product.price);
}
Named Constructor
class User {
String name;
User(this.name);
User.guest() : name = "Guest";
}
void main() {
User user = User.guest();
print(user.name);
}
18. Inheritance in Dart
Inheritance allows a child class to reuse functionality from a parent class.
class Animal {
void eat() {
print("Animal is eating");
}
}
class Dog extends Animal {
void bark() {
print("Dog is barking");
}
}
void main() {
Dog dog = Dog();
dog.eat();
dog.bark();
}
19. Exception Handling
Exception handling helps developers handle unexpected situations without unnecessarily stopping the entire application.
void main() {
try {
int result = 10 ~/ 0;
print(result);
} catch (e) {
print("An error occurred: $e");
}
}
Common exception-handling keywords include try, catch, finally, and throw.
20. Null Safety
Null safety helps developers explicitly identify variables that can or cannot contain a null value.
String name = "Flutter";
String? nickname;
print(name);
print(nickname);
Here, name must contain a String, while nickname can contain either a String or null.
Null-Aware Operator
String? name;
print(name ?? "Guest");
The ?? operator provides a fallback value when the expression on its left is null.
21. final and const
final
A final variable can be assigned once.
final String name = "Amit";
const
const is used for compile-time constant values.
const double pi = 3.14159;
22. Asynchronous Programming in Dart
Mobile applications frequently perform operations that take time, such as retrieving information from a server or reading data from storage. Dart provides asynchronous programming features for these situations.
JustAcademy's Flutter curriculum specifically includes Future and async/await as part of Dart programming fundamentals. :contentReference[oaicite:4]{index=4}
Future
Future getMessage() async {
return "Data loaded";
}
void main() async {
String message = await getMessage();
print(message);
}
async and await
Future loadData() async {
print("Loading...");
await Future.delayed(
Duration(seconds: 2),
);
print("Data loaded");
}
void main() async {
await loadData();
}
In Flutter applications, asynchronous programming is useful for API calls, Firebase operations, database operations, authentication, and other tasks that involve waiting for a result.
23. Streams in Dart
A Stream represents a sequence of asynchronous values over time.
Stream countNumbers() async* {
for (int i = 1; i <= 5; i++) {
yield i;
}
}
void main() async {
await for (int number in countNumbers()) {
print(number);
}
}
Streams can be useful when an application needs to respond to continuously changing or incoming data.
24. Dart and JSON Data
Flutter applications commonly communicate with APIs that return JSON data. Dart collections such as Maps and Lists can be used to represent JSON-like structures.
Map user = {
"id": 101,
"name": "Rahul",
"email": "[email protected]"
};
print(user["name"]);
In practical Flutter development, JSON data can be converted into Dart model objects for cleaner and more maintainable application code.
25. Dart for REST API Integration
Dart is used to write the logic required to communicate with REST APIs in Flutter applications.
A typical API workflow is:
- Send an HTTP request.
- Receive a response.
- Read the response data.
- Decode JSON when required.
- Convert data into Dart objects or collections.
- Display the data through Flutter widgets.
- Handle loading and error states.
API integration is included in JustAcademy's Flutter learning curriculum. :contentReference[oaicite:5]{index=5}
26. Dart in a Flutter Application
Dart is used throughout a Flutter project. For example, Dart code can define widgets, handle user interactions, manage application data, communicate with APIs, and implement business logic.
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text("Dart with Flutter"),
),
body: const Center(
child: Text(
"Hello Flutter!",
),
),
),
);
}
}
In this example, Dart provides the programming syntax while Flutter provides classes and widgets such as MaterialApp, Scaffold, AppBar, Center, and Text.
27. Dart Code Structure in Flutter
A typical Flutter application can contain Dart files such as:
lib/
├── main.dart
├── screens/
│ ├── home_screen.dart
│ └── login_screen.dart
├── widgets/
│ └── custom_button.dart
├── models/
│ └── user.dart
├── services/
│ └── api_service.dart
└── providers/
└── user_provider.dart
These files can contain different parts of the application's Dart code, helping developers organize larger Flutter projects.
28. Dart and Flutter Widgets
Flutter interfaces are created using widgets, and these widgets are written using Dart.
class WelcomeText extends StatelessWidget {
const WelcomeText({super.key});
@override
Widget build(BuildContext context) {
return const Text(
"Welcome to Flutter",
);
}
}
The class above is Dart code that defines a Flutter widget.
29. Dart Callback Example
Dart functions can be passed as values. This is useful for event handling and callbacks in Flutter.
void showMessage() {
print("Button clicked");
}
void executeFunction(void Function() callback) {
callback();
}
void main() {
executeFunction(showMessage);
}
Flutter uses callback functions extensively for actions such as button presses, gesture events, form changes, and other user interactions.
30. Dart Programming Topics to Learn Before Advanced Flutter
A strong Dart foundation should include the following topics:
| Topic |
What to Learn |
| Variables |
var, final, const, dynamic |
| Data Types |
String, int, double, bool, List, Set, Map |
| Operators |
Arithmetic, comparison, logical, assignment |
| Conditions |
if, else-if, else, switch |
| Loops |
for, while, do-while, for-in |
| Functions |
Parameters, return values, arrow functions |
| OOP |
Classes, objects, constructors, inheritance, abstraction, polymorphism |
| Collections |
List, Set, Map |
| Null Safety |
Nullable and non-nullable variables |
| Exception Handling |
try, catch, finally, throw |
| Async Programming |
Future, async, await, Stream |
31. Dart vs Flutter
| Feature |
Dart |
Flutter |
| Type |
Programming language |
UI framework/toolkit |
| Purpose |
Write application logic and program functionality |
Build application interfaces and application experiences |
| Variables |
Yes |
Uses Dart variables |
| Functions |
Yes |
Uses Dart functions |
| Classes |
Yes |
Flutter components are written using Dart classes |
| Widgets |
Not a UI framework |
Provides widgets for building interfaces |
| Async Programming |
Future, async/await, Stream |
Uses Dart asynchronous features |
32. Advantages of Learning Dart Before Flutter
- Helps beginners understand Flutter code more easily.
- Makes widget code easier to read and modify.
- Builds a foundation for application logic.
- Helps developers understand classes and objects.
- Improves understanding of collections and data structures.
- Makes asynchronous API and Firebase code easier to understand.
- Helps developers work with Flutter state management and application architecture.
- Supports cleaner and more maintainable Flutter code.
33. Example: Complete Dart Program
class Student {
String name;
int age;
List marks;
Student(this.name, this.age, this.marks);
double calculateAverage() {
int total = 0;
for (int mark in marks) {
total += mark;
}
return total / marks.length;
}
void displayDetails() {
print("Name: $name");
print("Age: $age");
print("Average: ${calculateAverage()}");
}
}
void main() {
Student student = Student(
"Rahul",
21,
[80, 75, 90],
);
student.displayDetails();
}
This example combines several Dart concepts, including classes, constructors, variables, lists, loops, functions, and string interpolation.
34. Dart Learning Roadmap for Flutter Developers
- Understand Dart syntax.
- Learn variables and data types.
- Practice operators.
- Learn if-else and switch.
- Practice loops.
- Understand functions and parameters.
- Learn List, Set, and Map.
- Study classes and objects.
- Learn constructors and inheritance.
- Understand abstraction and polymorphism.
- Learn null safety.
- Practice exception handling.
- Learn Future and async/await.
- Understand Streams.
- Practice JSON and API-related data handling.
- Start building Flutter widgets and applications.
35. How Dart Connects to the Flutter Learning Path
Dart is introduced early in JustAcademy's Flutter curriculum. The course then moves from Dart fundamentals into Flutter widgets and UI design, navigation, API integration, Firebase, state management, testing, deployment, projects, and advanced Flutter development. :contentReference[oaicite:6]{index=6}
| Stage |
Focus |
| 1 |
Dart programming fundamentals |
| 2 |
Flutter fundamentals and widgets |
| 3 |
UI layouts and navigation |
| 4 |
API and JSON integration |
| 5 |
Firebase and database integration |
| 6 |
State management |
| 7 |
Testing and debugging |
| 8 |
Real-world Flutter projects |
| 9 |
Deployment and advanced Flutter development |
36. Practical Exercises for Beginners
Exercise 1: Personal Information
Create a Dart program that stores and prints:
- Name
- Age
- City
- Email
- Mobile number
Exercise 2: Calculator
Create functions for:
- Addition
- Subtraction
- Multiplication
- Division
Exercise 3: Student Result
Create a Student class that stores student information and calculates the average marks.
Exercise 4: Product List
Create a List of products and use a loop to display every product.
Exercise 5: Async Data
Create an asynchronous function that waits for two seconds and then displays a message.
37. Quick Revision
| Question |
Answer |
| Which programming language does Flutter use? |
Dart |
| What is Dart? |
A programming language used to write Flutter applications. |
| What is a variable? |
A named storage location for a value. |
| What is a function? |
A reusable block of code. |
| What is a class? |
A blueprint used to create objects. |
| What is List? |
An ordered collection. |
| What is Map? |
A key-value collection. |
| What is null safety? |
A feature that helps manage nullable and non-nullable values. |
| What is Future? |
A representation of a value that becomes available asynchronously. |
| What are async and await? |
Keywords used to work with asynchronous operations. |
38. Key Takeaways
- Dart is the programming language used by Flutter.
- Dart provides the syntax and programming features used to build Flutter applications.
- Important Dart topics include variables, data types, operators, conditions, loops, and functions.
- Object-oriented programming is an important part of Dart development.
- List, Set, and Map are important Dart collections.
- Null safety helps developers work safely with nullable values.
- Future, async, await, and Stream are important for asynchronous programming.
- Dart code is used to create Flutter widgets and application logic.
- A strong Dart foundation makes it easier to learn Flutter development.
- JustAcademy's Flutter curriculum introduces Dart before progressing into widgets, UI, APIs, Firebase, state management, testing, deployment, and advanced development. :contentReference[oaicite:7]{index=7}
39. Learn Dart and Flutter with JustAcademy
JustAcademy's Flutter training includes Dart programming fundamentals as part of its Flutter learning path. The curriculum progresses from Dart and Flutter basics to widgets, UI development, API integration, Firebase, state management, testing, deployment, projects, and advanced Flutter concepts. :contentReference[oaicite:8]{index=8}
Visit JustAcademy Flutter Training
Register for the Flutter Course Demo
Conclusion
Dart is the foundation programming language behind Flutter application development. Before working extensively with Flutter widgets, navigation, APIs, Firebase, state management, and complete applications, developers should understand Dart fundamentals such as variables, data types, functions, collections, OOP, null safety, and asynchronous programming.
Learning Dart first provides the programming foundation required to understand and write Flutter code effectively. The next step is to apply these Dart concepts while learning Flutter widgets and building practical mobile applications.