/hello-dart

Now it's time to get started with Dart and Programming

Primary LanguageDart

Getting Started with Dart Programming

Welcome to the world of Dart programming! This guide will help you get started with the basics of programming and Dart using DartPad.

Table of Contents

  1. Introduction to Programming
  2. Variables and Data Types
  3. Control Flow
  4. Functions
  5. Lists/Arrays
  6. User Input
  7. Setting Up DartPad
  8. Writing Your First Dart Program
  9. Data Types in Dart
  10. Control Flow in Dart
  11. Functions in Dart
  12. Lists in Dart
  13. User Interaction in Dart
  14. Simple Exercises
  15. Explore Dart Documentation

1. Introduction to Programming

Programming is the process of writing instructions for a computer to perform a task. Let's dive into the basics of programming!

2. Variables and Data Types

In Dart, variables store data. Data types include int, double, String, and bool.

void main() {
  // Variable declaration and initialization
  int age = 25;
  double height = 5.9;
  String name = "John";
  bool isStudent = true;

  // Outputting values
  print("Name: $name, Age: $age, Height: $height, Student: $isStudent");
}

3. Control Flow

Use if statements for decision-making and loops for repetition.

void main() {
  // Control flow with if statement
  bool isRaining = true;

  if (isRaining) {
    print("Bring an umbrella!");
  } else {
    print("Enjoy the weather!");
  }

  // Looping with for loop
  for (int i = 0; i < 5; i++) {
    print("Count: $i");
  }
}

4. Functions

Functions are blocks of code that perform a specific task. They can take parameters and return values.

void main() {
  // Function declaration and call
  greet("Alice");
}

// Function definition
void greet(String name) {
  print("Hello, $name!");
}

5. Lists/Arrays

Lists store multiple items. Access and modify list elements.

void main() {
  // List declaration and initialization
  List<String> fruits = ["Apple", "Banana", "Orange"];

  // Accessing list elements
  print("First fruit: ${fruits[0]}");

  // Modifying list
  fruits.add("Grapes");
  print("Fruits: $fruits");
}

6. User Input

Get user input and use it in your program.

void main() {
  // User input
  print("Enter your name:");
  String userName = stdin.readLineSync();
  print("Hello, $userName!");
}

7. Setting Up DartPad

  1. Open your web browser.
  2. Go to DartPad.

8. Writing Your First Dart Program

Open DartPad and write your first Dart program.

void main() {
  print("Hello, DartPad!");
}

Click "Run" to see the output.

9. Data Types in Dart

Understand Dart data types.

void main() {
  int age = 25;
  double height = 5.9;
  String name = "John";
  bool isStudent = true;
}

10. Control Flow in Dart

Use if statements and loops in Dart.

void main() {
  bool isRaining = true;

  if (isRaining) {
    print("Bring an umbrella!");
  } else {
    print("Enjoy the weather!");
  }

  for (int i = 0; i < 5; i++) {
    print("Count: $i");
  }
}

11. Functions in Dart

Learn how to declare and use functions in Dart.

void main() {
  greet("Alice");
}

void greet(String name) {
  print("Hello, $name!");
}

12. Lists in Dart

Explore lists in Dart.

void main() {
  List<String> fruits = ["Apple", "Banana", "Orange"];

  print("First fruit: ${fruits[0]}");

  fruits.add("Grapes");
  print("Fruits: $fruits");
}

13. User Interaction in Dart

Get user input and display results.

void main() {
  print("Enter your name:");
  String userName = stdin.readLineSync();
  print("Hello, $userName!");
}

14. Simple Exercises

Try these simple exercises to reinforce your learning:

  1. Write a program to calculate the sum of two numbers.
  2. Create a list of your favorite movies and print them.

15. Explore Dart Documentation

Visit the Dart documentation to learn more about Dart and explore additional features.

Happy coding!