0% found this document useful (0 votes)
27 views20 pages

Dart Presentation

Dart is a programming language designed for fast app development, particularly in Flutter for cross-platform applications. The document covers Dart basics, including data types, conditional statements, loops, functions, classes, inheritance, exception handling, and more advanced topics like async/await and null safety. It provides practical examples throughout to illustrate the concepts discussed.

Uploaded by

4007 Dhiviyan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views20 pages

Dart Presentation

Dart is a programming language designed for fast app development, particularly in Flutter for cross-platform applications. The document covers Dart basics, including data types, conditional statements, loops, functions, classes, inheritance, exception handling, and more advanced topics like async/await and null safety. It provides practical examples throughout to illustrate the concepts discussed.

Uploaded by

4007 Dhiviyan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Dart Programming

A Practical Guide with Examples


Introduction to Dart
• Dart is a programming language optimized for
building fast apps. It is used in Flutter for
cross-platform development.
Dart Basics
• • Dart is statically typed
• • Everything is an object
• • Supports both compiled and interpreted
execution
Hello World Example
• void main() {
• print('Hello, Dart!');
• }
Variables & Data Types
• int age = 21;
• double price = 10.5;
• bool isActive = true;
• String name = 'Leena';
Conditional Statements
• if (age > 18) {
• print('Adult');
• } else {
• print('Minor');
• }
Loops
• for (int i = 0; i < 5; i++) {
• print(i);
• }
Functions
• int add(int a, int b) {
• return a + b;
• }
• void main() {
• print(add(2, 3));
• }
Named & Optional Parameters
• void greet({String name = 'User'}) {
• print('Hello, $name');
• }
• main() {
• greet(name: 'Leena');
• }
Classes & Objects
• class Person {
• String name;
• Person(this.name);
• }
• void main() {
• var p = Person('Leena');
• print(p.name);
• }
Inheritance
• class Animal {
• void makeSound() => print('Animal sound');
• }
• class Dog extends Animal {}
• void main() {
• Dog d = Dog();
• d.makeSound();
• }
Exception Handling
• try {
• int result = 10 ~/ 0;
• } catch (e) {
• print('Error: $e');
• }
Lists & Maps
• List<int> numbers = [1, 2, 3];
• Map<String, int> scores = {'Alice': 90, 'Bob':
85};
Future & Async/Await
• Future<String> fetchData() async {
• await Future.delayed(Duration(seconds: 2));
• return 'Data Loaded';
• }
• void main() async {
• print(await fetchData());
• }
Streams in Dart
• Stream<int> countStream() async* {
• for (int i = 1; i <= 3; i++) {
• yield i;
• }
• }
• void main() {
• countStream().listen((data) => print(data));
• }
Generics in Dart
• class Box<T> {
• T value;
• Box(this.value);
• }
• void main() {
• Box<int> box = Box(10);
• print(box.value);
• }
Null Safety
• int? nullableVar;
• print(nullableVar); // Output: null
Using Packages
• import 'package:http/http.dart' as http;
• Future<void> getData() async {
• var response = await
http.get(Uri.parse('https://api.example.com'));
• }
Real-world Example
• A Dart program fetching user data from an API
and displaying it.
Thank You!

Questions?

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy