🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Dart Programming.pptx

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Document Details

TollFreeObsidian8214

Uploaded by TollFreeObsidian8214

Sorsogon State University

Tags

Dart programming object-oriented programming mobile development software development

Full Transcript

INTRODUCTION TO DART PROGRAMMING BSCS PROFESSIONAL TRACK 1 (MOBILE SYSTEM DEVELOPMENT) PREPARED BY: KENNETH L. GISALAN INSTRUCTOR 1 WHAT IS DART PROGRAMMING LANGUAGE? Dart is a general-purpose, object-oriented programming language wi...

INTRODUCTION TO DART PROGRAMMING BSCS PROFESSIONAL TRACK 1 (MOBILE SYSTEM DEVELOPMENT) PREPARED BY: KENNETH L. GISALAN INSTRUCTOR 1 WHAT IS DART PROGRAMMING LANGUAGE? Dart is a general-purpose, object-oriented programming language with C-style syntax created by Google in 2011. Dart programming is used to construct frontend UIs for online and mobile apps. It is actively developed, compiled to native machine code for mobile apps, and strongly typed. It is influenced by the other programming languages such as Java, JavaScript, and C#. Because Dart is a compiled language, we cannot directly run our code; instead, the compiler parses it and converts it to machine code. WHAT IS DART PROGRAMMING LANGUAGE? Dart is a client-optimized programming language for creating quick apps on any platform. Its purpose is to provide the most productive programming language for cross-platform development and a flexible execution runtime platform for app frameworks. Dart is also the basis for Flutter. Dart offers the language and runtimes that power Flutter apps, but it also helps with many essential development responsibilities, including code formatting, analysis, and testing. CHARACTERISTICS OF DART Open Source Dart is an open source programming language, which is free to use. Google created it, is compliant with the ECMA standard, and is licensed under the BSD license. Platform Independent Dart is platform-independent, supporting all major operating systems such as Windows, Linux, and Macintosh. Dart has its Virtual Machine (VM), known as the Dart VM, which allows us to run Dart code on any operating system. CHARACTERISTICS OF DART Object-Oriented Dart is an object-oriented programming language that supports all OOPs concepts, including classes, inheritance, interfaces, and optional typing. Concurrency Dart is an asynchronous programming language that allows multithreading through Isolates. Isolates are independent entities tied to threads but do not share memory and communicate across processes via message passing. To ensure successful communication, the message should be serialized. The message is serialized by utilizing a snapshot created by the provided object and CHARACTERISTICS OF DART Extensive Libraries Dart has numerous important inbuilt libraries such as SDK (Software Development Kit), core, math, async, convert, html, IO, and so on. It also allows us to structure our Dart code into libraries with correct namespacing. The import statement will enable it to be reused. Easy to Learn As we established in the last part, learning Dart is not a Hercules task because its syntax is similar to Java, C#, JavaScript, kotlin, and other programming languages. If we CHARACTERISTICS OF DART Flexible Compilation Dart allows us to compile code in various ways that are both flexible and quick. It supports two compilation processes: AOT and JIT. The Dart code is sent in another language that contemporary web-brewers can execute. Type Safe Dart is a type-safe language, which implies that it utilizes both static types checking and runtime checks to ensure that a variable’s value always matches the variable’s static type, also known as sound typing. CHARACTERISTICS OF DART Objects The Dart considers everything to be an item. An object is a value that is assigned to the variable. Dart also considers functions, integers, and texts to be objects. All objects derive from the Object class. Browser Support The Dart supports all recent web browsers. It includes the dart2js compiler, which translates Dart code into efficient JavaScript code suited for all types of web browsers. CHARACTERISTICS OF DART Community Dart has a sizable global community. So, if we have difficulty when coding, we may efficiently locate assistance. The devoted development team is working hard to improve its functioning. Browser Support The Dart supports all recent web browsers. It includes the dart2js compiler, which translates Dart code into efficient JavaScript code suited for all types of web browsers. INSTALLING DART STEP 1 Open a browser and navigate to the following URL to download the SDK. It will take us to the specified page. Please follow the link below. http://www.gekorm.com/dart- windows/ STEP 2 Launch the Dart installer (the.exe file we downloaded in the previous step) and click the Next button. STEP 3 It gives us a choice to choose the Dart installation path. After we’ve decided on a path, click the Next button. STEP 4 Once the download is complete, change the PATH environment variable in the system properties to “C:\Program Files\Dart\ dart-sdk\bin.” STEP 5 Now, open the terminal and type dart --version to confirm the Dart installation. RUNNING YOUR FIRST DART PROGRAM FIRST DART PROGRAM Dart is simple to learn if you are familiar with Java, C++, JavaScript, and other programming languages. The simplest “Hello World” program demonstrates the programming language’s basic grammar. It’s a method of testing the system and the working environment. You can run your first Dart Program in different ways such as using Command Line, Browser or IDE like Visual Studio Code. FIRST DART PROGRAM To run your first Dart program using Visual Studio Code: Open Visual studio Code and Install Dart and Code Runner Extension. FIRST DART PROGRAM To create your first program, press CTRL+SHIFT+P, select Dart: New Project, select Console Application, Select or Create a Folder where you want to save your Dart project and finally, Enter a name for your new Dart project. DART BASIC SYNTAX COMMENTS IN DART The collection of statements disregarded by the Dart compiler during program execution is known as comments. It is used to make the source code more readable. In general, comments provide a concise overview of what is happening in the code. COMMENTS IN DART Dart supports three types of comments: + Single-line Comment //This is a comment COMMENTS IN DART Dart supports three types of comments: + Multi-Line Comments COMMENTS IN DART Dart supports three types of comments: + Documentation Comments Document comments are used to create documentation or reference a project/software package. It can be a single or multiline comment beginning with /// or /*. KEYWORDS IN DART Dart Keywords are reserved words with particular significance for the compiler. It can’t be used as a variable, class, or function name. Keywords are case sensitive; therefore, they must type exactly as defined. DATA TYPES IN DART The most significant fundamental characteristics of a programming language are its data types. The data type of a variable in Dart is specified by its value. Strings Maps Number Runes Boolean Symbols Lists VARIABLES IN DART A variable is used to hold a value and refer to a computer’s memory region. When we declare a variable, the Dart compiler allocates memory space. The kind of variable determines the size of the memory block. VARIABLES IN DART Variable Creation Rule: 1. The variable does not allow whitespace, mathematical symbols, runes, Unicode characters, and keywords. 2. The variable’s initial character should be an alphabet ([A to Z], [a to z]). As the initial character, digits are not permitted. 3. Variables have a case sensitivity. Variable age and AGE, for example, are addressed differently. 4. Except for the underscore (_) and the dollar symbol ($), special characters such as #, @, &, and * are not permitted. 5. The variable name should be readable by the program. VARIABLES IN DART Dart Variable Declaration A variable must declare before it can use in a program. To declare a variable in Dart, use the var keyword. Because Dart is an infer type language, the Dart compiler automatically determines the type of data based on the value assigned to the variable. var = ; VARIABLES IN DART Type Annotations As previously said, the Dart is an infer language, but it also has type annotation. The type of value the variable can store is suggested when it is declared. var = ; VARIABLES IN DART Declaring the Variable as Having Multiple Values Dart allows us to specify multiple values of the same type to variables. We can perform this in a single sentence, with commas between each value. ; VARIABLES IN DART Default Value When a variable is declared but not initialized, the Dart compiler assigns a default value (Null). Even the numeric type variables are allocated a null value at first. VARIABLES IN DART Final and Const We use final and const when we don’t want to update a variable in the future. It can use instead of or in addition to var. When the variable is a compile-time constant, the variable can only be set once. OPERATORS IN DART Dart has many built-in operators for performing many sorts of tasks. Operators can be unary or binary, which means that unary operators take only one operand and binary operators take two operands. There are several kinds of operators. OPERATORS IN DART Arithmetic Operators in Dart OPERATORS IN DART Unary Operators (Post and Pre) OPERATORS IN DART Assignment Operator OPERATORS IN DART Assignment Operator OPERATORS IN DART Relational Operator OPERATORS IN DART Type Test Operators OPERATORS IN DART Logical Operators OPERATORS IN DART Bitwise Operators OPERATORS IN DART Conditional Operators (?:) The Conditional Operator is comparable to the if-else statement and provides similar functionality. It is the if-else statement’s second form. It is also known as a “Ternary Operator.” condition? exp1 : exp2 (If the specified condition is TRUE, it returns exp1, else it returns exp2. ) exp1? ? expr2 (If exp1 is not null, it returns its value; otherwise, it returns the value of exp2.) DATA TYPES AND CONTROL FLOW STATEMENTS DATA TYPES DART CONSTANTS A Dart Constant is an immutable object, which means it cannot be updated or modified while the application is running. It cannot be reassigned once we assign a value to a constant variable. DATA TYPES Parse() Method in Dart The parse() method is used to convert a numeric string to a number. DATA TYPES Number Properties DATA TYPES Number Methods DATA TYPES String Concatenation Tocombine the two strings, use the + or += operator. String Interpolation Stringinterpolation is a method that allows you to alter a string and produce a new string by adding another value. It can evaluate a string, including placeholders, variables, and interpolated expressions. String interpolation is accomplished DATA TYPES String Properties DATA TYPES String Methods DATA TYPES LISTS IN DART DartLists are similar to arrays in that they are an ordered collection of things. The array is the most popular and widely used collection in any other programming language. The Dart list resembles JavaScript array literals. DATA TYPES The dart list is divided into two categories: Fixed Length List - The length of the fixed-length lists is provided. At runtime, we are unable to change the size. Growable List - A Growable list is declared without specifying a size. One can change the Growable list’s size at runtime. The syntax for declaring a Growable list is shown below. DATA TYPES List Properties DATA TYPES Inserting an Element into a List Dart supports four methods for inserting elements into lists. These procedures are given below: add() - list_name.add(value) addAll() - list_name.addAll(va1,val2…valN) insert() - DATA TYPES Updating List Dartallows us to update the list, and we may edit it by simply accessing its element and assigning it a new value. list_names[index] = new_value; DATA TYPES replaceRange() The replaceRange() method in Dart is used to update list items within a defined range. It updates the element values using the specified range. list_names.replaceRange(int start_val, int end_ val, iterable); DATA TYPES Removing List Elements Dart provides the following methods for removing list items: remove() - list_names.remove(value) removeAt() - list_name.removeAt(int index) removeLast() - CONTROL FLOW STATEMENTS FLOW STATEMENT CATEGORIES DART DECISION-MAKING STATEMENTS IF STATEMENTS When the supplied condition returns true, the If statement lets us run a code block. We have a case in Dart programming where we want to run a block of code when it meets the specified criteria. The condition analyses the Boolean values TRUE or FALSE and decides based on these Boolean values. DART DECISION-MAKING STATEMENTS IF-ELSE STATEMENT When the specified condition is true, the if-block in Dart is performed. The else-block is run if the provided condition is false. The else block is linked to the if-block. DART DECISION-MAKING STATEMENTS IF ELSE-IF STATEMENT The if else-if statement in Dart allows us to verify a series of test expressions and execute various statements. It is utilized when we have to choose amongst more than two options. DART DECISION-MAKING STATEMENTS Nested If-Else Statement A nested if-else statement in Dart implies one if-else statement within another. It is useful when we need to make a sequence of decisions. DART DECISION-MAKING STATEMENTS SWITCH CASE STATEMENT To eliminate the lengthy chain of the if-else statement, the Dart Switch case statement is utilized. It is a shortened version of a nested if-else statement. The variable’s value is compared to the various cases, and if a match is found, a block of statements associated with that case is executed. Each instance is compared to the provided value until a match is found. When a match is detected, the block of code to be run is identified. DART DECISION-MAKING STATEMENTS SWITCH CASE STATEMENT LOOPS IN DART For Loop To begin the loop execution, an initial variable is required. It runs a section of code until it matches the criteria supplied. When the Loop is run, the iterator’s value changes after each iteration and the test expression is evaluated. This method is repeated until the specified test expression returns true. The for Loop is ended when the test expression is false. LOOPS IN DART For in Loop The for in Loop differssomewhat from the for Loop. It just uses a dart object or expression as an iterator and iterates through the elements one at a time. The element’s value is tied to var, which is valid and accessible to the loop body. The Loop will run until there are no more elements in the iterator. LOOPS IN DART For in Loop The for in Loop differs somewhat from the for Loop. It just uses a dart object or expression as an iterator and iterates through the elements one at a time. The element’s value is tied to var, which is valid and accessible to the loop body. The Loop will run until there are no more elements in the iterator. LOOPS IN DART While Loop When the number of executions of a code is unknown, the while loop is employed. It will run as long as the requirement is met. It first verifies the supplied condition and then executes the while loop’s lines. The while loop is most commonly used to generate an endless loop. LOOPS IN DART Infinite While Loop When the while loop operates indefinitely, it is referred to as an infinite while loop. Let’s look at an infinite loop example. LOOPS IN DART Logical Operator While Loop while (n15 && n2>10) – This code will be executed if both criteria are met. while (n15 || n2>10) – This code is executed if one of the conditions is met. while (!n1 = 10) – This function will be executed if n1 is not equal to 10. LOOPS IN DART Do-While Loop The do-while Loop is identical to the while loop, except it runs the loop statement before checking the specified condition. LOOPS IN DART Selection of the Loop Analyze the problem to determine if a pre-test or post-test Loop is required. A pre-test loop tests the condition before entering the Loop. The condition is tested after entering the Loop in the post-test Loop. We may use the while or for Loop if we need a pre-test loop. If we need a post-test loop, use the do-while BOOLEAN IN DART Selection of the Loop The Dart Boolean data type determines if a statement is true or false. True and false are the Boolean type’s two values, both compile-time constants. In Dart, the numeric values 1 and 0 do not describe whether something is true or false. The term bool is used to express a Boolean value. The syntax for defining the Boolean variable is as follows. BOOLEAN IN DART The Dart Boolean data type determines if a statement is true or false. True and false are the Boolean type’s two values, both compile-time constants. In Dart, the numeric values 1 and 0 do not describe whether something is true or false. The term bool is used to express a Boolean value. The syntax for defining the Boolean variable is as follows. BOOLEAN IN DART The Dart Boolean data type determines if a statement is true or false. True and false are the Boolean type’s two values, both compile-time constants. In Dart, the numeric values 1 and 0 do not describe whether something is true or false. The term bool is used to express a Boolean value. The syntax for defining the Boolean variable is as follows. FUNCTIONS AND OBJECT-ORIENTED PROGRAMMING FUNCTION IN DART A Dart function is a collection of programs that work together to complete a specified purpose. It is used to divide big amounts of code into smaller modules that may be reused as needed. Functions make the software more readable and debug. It improves the modular approach and code reusability. CALLING A FUNCTION After creating a function, we may call or invoke it within the main() function body. A function is called simply by its name, with or without an argument list, if any. RETURN A VALUE FROM THE FUNCTION To return a value, use the return keyword. The return statement is not required. There can only be one return statement in a function. ANONYMOUS FUNCTION IN DART An anonymous function performs the same as a regular function, except it lacks a name. An optional type annotation can have zero or any number of parameters. THE MAIN() FUNCTION Dart’s top-level function is the main() function. It is the Dart programming language’s most significant and critical function. The main() function initiates the execution of the programming. In a program, the main() function can only use once. WHAT IS RECURSION? Dart Recursion is a way in which a function calls itself a subroutine. It is used to tackle challenging problems by breaking them down into smaller parts. When a function is called again or recursively, this is referred to as recursion. OBJECT-ORIENTED CONCEPTS IN DART CLASS Dart classes are the blueprints for the linked objects. A Class is a user-defined data type that outlines its attributes and behavior. To obtain all of the class’s properties, we must first construct an object. OBJECT An object is a real-life entity such as a table, a person, a car, etc. The object has two properties: its state and its behavior. INHERITANCE Dart supports inheritance, which allows us to create new classes from existing ones. The class to be extended is referred to as the parent/superclass, and the newly created class is referred to as the child/subclass. Dart offers the extended keyword for inheriting parent class attributes in child classes. POLYMORPHISM Polymorphism is a notion in object-oriented programming in which one entity has several forms. There are two forms of polymorphism: runtime polymorphism and compile-time polymorphism. For instance, a function with the same name but a distinct behavior or class. Another example is the shape() class and all the classes that inherit from Rectangle, Triangle, and Circle. INTERFACES The interface is specified as a class blueprint. We may define methods and variables within the interface the same way we do in the class, but the interface only allows for abstract method creation. We can only declare the function signature, not the function body. The interface can be implemented by another class. It is mostly used to hide data. ABSTRACT CLASS An abstract class has one or more abstract methods. The abstract class may declare by using the abstract keyword followed by the class definition.

Use Quizgecko on...
Browser
Browser