Dart Tutorial
Recent content on Dart Tutorial
- Website
- dart-tutorial.dev · all feeds from this site
- Feed URL
https://www.dart-tutorial.dev/index.xml
Read it in your FeedListing reader
Or add to: Feedly Inoreader Raw feed
Latest posts
-
Dart Programming Examples: 30 Simple Programs with Output
These are the small programs every beginner writes, solved in clear, modern Dart. Each one shows the code and the output. Press Run to try it in the browser, then change it : use other numbers, add a feature, break it on purpose and read the error. That is the fastest way to…
-
Dart List Methods: Complete Guide with Easy Examples
The Lists lesson introduced the List type. This page collects the list methods you will reach for every day, grouped by what you want to do, each with a short program and its output. Press Run on any example, change the numbers, and run it again. Quick reference table Method…
-
Classes and Objects in Dart
A class is a blueprint. An object is a thing built from that blueprint. The class Car describes what every car has and can do; your car and your neighbor’s car are two objects of that class. Defining a class class Dog { // Fields: the data each dog has. String name ; int age ;…
-
Exception Handling in Dart: try, catch, on and finally
An exception is Dart’s way of signalling that something went wrong while the program was running. If nobody handles it, the program stops. An unhandled exception void main () { var number = int . parse ( 'twelve' ); print ( number ); // never reached } Unhandled exception:…
-
Formatting and Linting Dart Code: dart format and dart analyze
Two tools keep a Dart codebase healthy without any effort from you. The formatter decides how code looks. The analyzer finds mistakes and questionable code before you run it. dart format The formatter rewrites your files in the standard Dart style: indentation, spacing, line…
-
Functions in Dart: Defining, Calling and Returning Values
You have been using functions since the first lesson: main is one, and so is print . Now you will write your own. Defining and calling a function void greet () { print ( 'Hello!' ); } void main () { greet (); greet (); } Hello! Hello! The definition says what the function does.…
-
if, else if and else in Dart
An if statement runs a block of code only when a condition is true . if void main () { var temperature = 31 ; if ( temperature > 30 ) { print ( 'It is hot today.' ); } } It is hot today. if and else else runs when the condition is false . Exactly one of the two blocks runs. void…
-
Imports in Dart: import, as, show and hide
In Dart, every .dart file is a library . To use something defined in another library, you import it. Three kinds of import // 1. A library built into the Dart SDK import 'dart:math' ; // 2. A library from a package (your own project or one from pub.dev) import…
-
Asynchronous Programming in Dart: An Introduction
Synchronous code: one thing at a time Normal code is synchronous . Each line finishes before the next starts. void main () { print ( 'Order coffee' ); print ( 'Make coffee' ); print ( 'Drink coffee' ); } That is fine when every step is instant. Now imagine a step that takes…
-
Working with JSON in Dart: Encode, Decode and Model Classes
JSON is the format most web APIs use to exchange data. It is plain text made of objects ( {} ), arrays ( [] ), strings, numbers, booleans and null . Dart’s dart:convert library translates between JSON text and Dart values. JSON Dart object { } Map array [ ] List string String…
-
Null Safety in Dart: Nullable and Non-Nullable Types
null means “no value”. It is useful: a user may have no middle name, a search may find nothing. The danger comes from forgetting that a value might be missing and using it anyway. Dart’s answer is sound null safety : every type is non-nullable unless you say otherwise, and the…
-
Dart Collections: List, Set and Map Overview
Dart has three core collection types. Picking the right one makes your code shorter and faster. Type Ordered? Duplicates? Find items by Literal List Yes Allowed Position (index) [1, 2, 3] Set Insertion order Not allowed The value itself {1, 2, 3} Map Insertion order Keys are…
-
Reading Files in Dart
To work with a file, create a File object from its path. This does not open or create anything. It is only a reference to a location on disk. For the examples, assume a file notes.txt with this content: Buy milk Call Hari Finish the Dart tutorial Read the whole file as a string…
-
Records in Dart: Return Multiple Values Without a Class
A record is a small, fixed-size bundle of values. It is the quickest way to group a few things together, and the standard way to return more than one value from a function without writing a class. Creating a record Write the values in round brackets, separated by commas. void…
-
Variables in Dart: var, Explicit Types and dynamic
A variable is a name that refers to a value. You create one, give it a value, and use the name wherever you need that value. Declaring a variable with var void main () { var city = 'Kathmandu' ; var population = 1442000 ; var isCapital = true ; print ( ' $ city , population $…
-
What Is Dart? An Introduction to the Dart Language
Dart is a programming language created by Google. It was first shown in 2011, and today it is best known as the language behind Flutter , the toolkit used to build apps for Android, iOS, web, Windows, macOS and Linux from one codebase. You can also use Dart on its own for…
-
Constructors in Dart: Default, Named, Initializer Lists and Redirecting
A constructor creates an object and makes sure its fields have values. Dart offers several styles, and the short ones cover most needs. The default constructor If you write no constructor, Dart gives you one with no parameters. Fields then need default values. class Light { bool…
-
Creating Your Own Libraries in Dart
As a project grows, one file becomes hundreds of lines and then thousands. Splitting code into libraries keeps each piece small, lets you hide implementation details, and makes the code reusable. A file is a library You already know how to make a library: create a .dart file. //…
-
Custom Exceptions in Dart
The built-in exception types are general. Your app has its own failures: “insufficient balance”, “user not found”, “session expired”. A custom exception gives each of them a name, so callers can handle them precisely and carry useful data along. A minimal custom exception…
-
Data Types in Dart: A Complete Overview
Every value in Dart has a type, and the type decides what you can do with the value. You can add two numbers, but you cannot add a number to a true . The built-in types Type Holds Example int Whole numbers 42 , -7 double Numbers with a decimal point 3.14 , -0.5 num Either an int…