Welcome to the Dart Basics repository! This repository is designed to help you get started with Dart, a powerful language used for building web, mobile, and desktop applications. 🚀
hello_world.dart
: A simple "Hello, World!" program.variables.dart
: Learn about Dart variables and data types.functions.dart
: Basic function usage and examples.control_flow.dart
: Control structures likeif-else
, loops, and more.classes_objects.dart
: Introduction to object-oriented programming in Dart.
- Make sure you have the Dart SDK installed. Install here.
- Clone this repository:
git clone https://github.com/ministerko/Dart.git
cd dart-basics
- Run a specific Dart file:
dart run hello_world.dart
Variables in Dart can be declared with var
or by specifying the type explicitly:
var name = 'Kelvin'; // Inferred as String
int age = 25; // Explicit type declaration
Functions can return values or just perform actions:
void greet() {
print('Hello, Dart! 👋');
}
int add(int a, int b) {
return a + b;
}
int age = 20;
if (age >= 18) {
print('You are an adult! 🎉');
} else {
print('You are still a minor. 🌱');
}
for (int i = 0; i < 5; i++) {
print('Dart is awesome! 😎');
}
Dart supports object-oriented programming with classes:
class Person {
String name;
int age;
// Constructor
Person(this.name, this.age);
void displayInfo() {
print('Name: $name');
print('Age: $age');
}
}
void main() {
Person person1 = Person('Kelvin', 25);
person1.displayInfo();
}
Dart ensures null safety, so you have to initialize non-nullable variables:
String name = 'Kelvin'; // Cannot be null
If a variable can be null, you use a nullable type:
String? optionalName;
optionalName = null; // Allowed
This project is licensed under the MIT License - see the LICENSE file for details.