Skip to content

Composed primarily of basic syntax and example explanations

Notifications You must be signed in to change notification settings

devkan/dart-tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dart Basics: Syntax, Variables, Data Types, and Functions

Welcome to the Dart Basics guide, designed for those who are venturing into the world of Dart programming. This README aims to provide you with a foundational understanding of Dart's syntax, variables, data types, and functions through basic syntax and practical examples. Whether you're developing for web, server, or mobile applications using the Flutter framework, understanding these core concepts is essential for your journey as a Dart developer.

Table of Contents

Introduction

Dart is a versatile, open-source programming language developed by Google. It's optimized for building high-quality, natively compiled applications for mobile, web, and desktop from a single codebase. Dart combines the power of object-oriented and functional programming, with features designed for the development of modern applications.

Variables and Data Types

Variables

In Dart, variables store references to data. They are declared using the var keyword for variable data types, or explicitly with their types.

var name = 'John Doe'; // Inferred as String
int age = 30; // Explicitly typed as int

Data Types

Dart supports both built-in data types and user-defined types. The primary data types include:

  • int and double for numbers
  • String for text
  • bool for boolean values
  • List and Map for collections
String greeting = "Hello, World!";
int year = 2024;
double height = 1.88;
bool isVisible = true;
List<String> names = ['Alice', 'Bob', 'Charlie'];
Map<String, int> ageMap = {'Alice': 30, 'Bob': 25};

Functions

Functions in Dart are objects and can be defined using the Function keyword or shorthand syntax. They can return values, or be void.

void sayHello(String name) {
  print('Hello, $name!');
}

int add(int a, int b) {
  return a + b;
}

Examples

Let's combine what we've learned into a simple example:

void main() {
  var name = 'Dart Programmer';
  sayHello(name);
  print('Sum of 3 and 5 is ${add(3, 5)}');
}

void sayHello(String name) {
  print('Hello, $name!');
}

int add(int a, int b) {
  return a + b;
}

Conclusion

This guide provides a snapshot of Dart's fundamental concepts, including variables, data types, and functions. Mastery of these basics is crucial as you delve deeper into Dart programming, especially if you're aiming to develop Flutter applications.

Additional Resources

For more detailed information and advanced topics, consider the following resources:

Happy coding, and welcome to the vibrant Dart community!

About

Composed primarily of basic syntax and example explanations

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages