├── .DS_Store
├── README.md
└── essential-dart-concepts
├── .DS_Store
├── branches.dart
├── classes.dart
├── control_flow.dart
├── data_types.dart
├── functions.dart
├── hello_world.dart
└── lists-samples
├── IntList.dart
└── Prices.dart
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dnfradejas/dart-experiments/ae1ab7687718148dd2c081d1b37cbc4969342385/.DS_Store
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Dart Installation Process
2 | This presents the installation process of Dart in Windows devices. Please make sure to follow them carefully.
3 |
4 |
5 | ## Install chocolately
6 | * Run PowerShell in ``admin`` and type: ``Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))``
7 | * Check the if choco has been successfully installed: ``choco --version``
8 |
9 | ## Install Dart
10 | * Run PowerShell in ``admin`` and type: ``choco install dart-sdk``
11 | * Check if dart has been successfully installed ``dart --version``
12 | Note: When checking dart version, it shouldn't be in the admin mode.
13 |
14 | ## Install Dart in VSCode
15 | * Navigate to extensions and downlad Dart.
16 |
17 |
--------------------------------------------------------------------------------
/essential-dart-concepts/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dnfradejas/dart-experiments/ae1ab7687718148dd2c081d1b37cbc4969342385/essential-dart-concepts/.DS_Store
--------------------------------------------------------------------------------
/essential-dart-concepts/branches.dart:
--------------------------------------------------------------------------------
1 | // // Branches
2 | // This page shows how you can control the flow of your Dart code using branches:
3 |
4 | // if statements and elements
5 | // if-case statements and elements
6 | // switch statements and expressions
7 |
8 | // If
9 | // Dart supports if statements with optional else clauses.
10 | // The condition in parentheses after if must be an expression that evaluates to a boolean:
11 |
12 | // void main(){
13 | // var year = 2021;
14 | // if (year >= 2001) {
15 | // print('21st century');
16 | // } else if (year >= 1901) {
17 | // print('20th century');
18 | // }
19 | // }
20 |
21 | // =========================================================================================================
22 | // // Switch expressions
23 | // // A switch statement evaluates a value expression against a series of cases. Each case clause is a pattern for the value to match against.
24 | // // You can use any kind of pattern for a case.
25 | // void main(){
26 | // var command = 'OPEN';
27 | // switch (command) {
28 | // case 'CLOSED':
29 | // print('closed');
30 | // break;
31 | // case 'PENDING':
32 | // print('pending');
33 | // break;
34 | // case 'APPROVED':
35 | // print('approved');
36 | // break;
37 | // case 'DENIED':
38 | // print('denied');
39 | // break;
40 | // case 'OPEN':
41 | // print('open');
42 | // break;
43 | // default:
44 | // print('invalid');
45 | // }
46 | // }
--------------------------------------------------------------------------------
/essential-dart-concepts/classes.dart:
--------------------------------------------------------------------------------
1 | // // Creating Basic Classes in Dart
2 |
3 | // void main() {
4 | // Person learner = Person("Ms Johnson", 25);
5 | // print(learner.name);
6 | // }
7 |
8 | // class Person {
9 |
10 | // // Properties
11 | // String? name;
12 | // int? age;
13 |
14 | // // Constructor
15 | // Person(this.name, this.age);
16 | // }
17 |
18 |
19 | // // other implementation of Class
20 | // void main() {
21 | // Person learner = Person(name: "Ms Johnson", age: 25,);
22 | // Person learner2 = Person(name: "Ms Johnson", age: 25,);
23 | // Person learner3 = Person.withIdentity(name: "Ms Johnson", age: 25, identificationNumber: "1234567890");
24 |
25 | // learner2.updateLivingStatus = false;
26 | // print(learner2.livingStatus);
27 | // }
28 |
29 | // class Person {
30 |
31 | // // Properties
32 | // final String name; // doesn't change the value of the variable
33 | // int? age;
34 | // bool _isAlive = true;
35 | // late final String identificationNumber; // late keyword is used to delay the initialization of a variable
36 |
37 | // // Getter
38 | // bool get livingStatus{
39 | // return _isAlive;
40 | // }
41 |
42 | // // Setter
43 | // set updateLivingStatus(bool status) {
44 | // _isAlive = status;
45 | // }
46 |
47 | // // Constructor
48 | // Person({required this.name, this.age});
49 |
50 | // Person.withIdentity({required this.name, this.age, required this.identificationNumber});
51 | // }
--------------------------------------------------------------------------------
/essential-dart-concepts/control_flow.dart:
--------------------------------------------------------------------------------
1 | // // Loops
2 | // // This page shows how you can control the flow of your Dart code using loops and supporting statements:
3 |
4 | // // For loops
5 | // // You can iterate with the standard for loop. For example:
6 | // void main()
7 | // {
8 | // for (var i = 0; i < 5; i++){
9 | // print([i]);
10 | // }
11 | // }
12 |
13 | // =========================================================================================================
14 | // void main(){
15 | // var callbacks = [];
16 | // for (var i = 0; i < 2; i++) {
17 | // callbacks.add(() => print(i));
18 | // }
19 |
20 | // for (final c in callbacks) {
21 | // c();
22 | // }
23 | // }
24 | // =========================================================================================================
25 | // // While and do-while
26 | // // A while loop evaluates the condition before the loop:
27 | // void main(){
28 | // while(!isDone()){
29 | // doSomething();
30 | // }
31 | // }
32 |
33 | // =========================================================================================================
34 | // // A do-while loop evaluates the condition after the loop:
35 | // void main(){
36 | // do {
37 | // printLine();
38 | // }
39 | // } while (!atEndOfPage())
40 |
41 | // =========================================================================================================
42 | // // Use break to stop looping
43 | // void main(){
44 | // while (true) {
45 | // if (shutDownRequested()) break;
46 | // processIncomingRequests();
47 | // }
48 |
49 | // // Use Continue to skip to the next loop iteration
50 | // void main(){
51 | // for (int i = 0; i < candidates.length; i++) {
52 | // var candidate = candidates[i];
53 | // if (candidate.yearsExperience < 5) {
54 | // continue;
55 | // }
56 | // candidate.interview();
57 | // }
--------------------------------------------------------------------------------
/essential-dart-concepts/data_types.dart:
--------------------------------------------------------------------------------
1 | // Dart Supports Nine Data Types
2 | // 1. Numbers
3 | // 2. Strings
4 | // 3. Booleans
5 | // 4. Lists
6 | // 5. Maps
7 | // 6. Runes
8 | // 7. Symbols
9 | // 8. Null
10 |
11 | //INTEGER - represents integer values
12 | int someNumber = 10;
13 |
14 | //DOUBLE - represents floating point values
15 | double someDouble = 10.10;
16 |
17 | //NUMBERS - represents both integer and double values
18 | num someNum = 10;
19 |
20 | // EXAMPLE
21 | void main(){
22 | int someNum = 7;
23 | print(someNum.isEven);
24 |
25 | double someDouble = 10.10;
26 | print(someDouble.round());
27 | }
28 |
29 | //=========================================================================================================
30 | //STRINGS
31 | // Strings are a sequence of characters. They are used to represent text.
32 |
33 | // void main(){
34 | // int appleCount = 15;
35 | // String msg = 'I have $appleCount apples';
36 |
37 | // print(msg);
38 | // }
39 |
40 | // String Util Methods
41 | // void main(){
42 |
43 | // // convert code to upperCase
44 | // print('Dart'.toUpperCase());
45 |
46 | // // check if a string contains a substring
47 | // print('Dart'.contains('ar'));
48 |
49 | // // check if string starts with a substring
50 | // print('Dart'.startsWith('Da'));
51 |
52 | // // check if string is empty
53 | // print('Dart'.isEmpty);
54 |
55 | // }
56 |
57 | //=========================================================================================================
58 | //BOOLEANS
59 | // Booleans are used to represent true or false values.
60 |
61 | // void main(){
62 | // bool isLocationEnabled = false;
63 |
64 | // if(isLocationEnabled){
65 | // print('Location Enabled');
66 | // } else {
67 | // print('Location Disabled');
68 | // }
69 | // }
70 |
71 | //=========================================================================================================
72 | //LISTS
73 | // Lists are used to store multiple values in a single variable.
74 |
75 | // void main(){
76 |
77 | // // // create a list of book titles
78 | // // List bookTitles = ['Atomic Habits', 'Deep Work', 'Digital Minimalism'];
79 | // // bookTitles.add(2);
80 |
81 | // // // limit the type of values that can be added to the list
82 | // // List bookTitles = ['Atomic Habits', 'Deep Work', 'Digital Minimalism'];
83 |
84 | // // print(bookTitles);
85 |
86 | // // // check length of bookTitles
87 | // // print(bookTitles.length);
88 |
89 | // // // erase the contents of bookTitles
90 | // // bookTitles.clear();
91 | // }
92 |
93 | //=========================================================================================================
94 | //MAPS
95 | // Maps are used to store key-value pairs.
96 |
97 | // void main(){
98 |
99 | // // create a map of book titles and their authors dynamically
100 | // Map bookTitles = {
101 | // 1: 'Atomic Habits',
102 | // 2: 'Deep Work',
103 | // 3: 'Digital Minimalism'
104 | // };
105 |
106 | // // add a new key-value pair to the map
107 | // bookTitles[4] = 'The Power of Habit';
108 |
109 | // // add data that allow null values
110 | // Map bookTitles2 = {
111 | // 1: 'Atomic Habits',
112 | // 2: 'Deep Work',
113 | // 3: null
114 | // };
115 |
116 | // // add data that allow null values (both data types)
117 | // Map? bookTitles3 = {
118 | // 1: 'Atomic Habits',
119 | // 2: 'Deep Work',
120 | // 3: null
121 | // };
122 |
123 | // }
124 |
125 | //=========================================================================================================
126 | // VAR vs DYNAMIC
127 |
128 | // void main(){
129 |
130 | // // you can change the data type dynamically
131 | // dynamic price = 10.10;
132 | // print(price.runtimeType);
133 | // price = "Rs. 40.5";
134 | // print(price.runtimeType);
135 |
136 | // // you can't change the data type dynamically
137 | // var price2 = 10.10;
138 | // print(price2.runtimeType);
139 | // // price2 = "Rs. 40.5"; // Error
140 |
141 | // }
--------------------------------------------------------------------------------
/essential-dart-concepts/functions.dart:
--------------------------------------------------------------------------------
1 | // Anatomy of a Function
2 |
3 | // String openPage (int pageNo) {return ("Page contents")}
4 |
5 | // // Calling a function
6 | // // openPage(2);
7 |
8 | // =========================================================================================================
9 |
10 | // void main(){
11 | // printCost(2000, "Atomic Habits");
12 | // }
13 |
14 | // void printCost(double price, String bookName){
15 | // print("The price of $bookName is $price");
16 | // }
17 |
18 |
19 | // // other implementation
20 | // void main(){
21 | // printCost(price: 2000, itemName: "Atomic Habits");
22 | // }
23 |
24 | // void printCost({required double price, String? itemName}){
25 | // print("The price of $itemName is $price");
26 | // }
27 |
28 | // =========================================================================================================
29 | // // Value returning functions
30 | // int area(length, width){
31 | // return length * width;
32 | // }
33 | // // converted to arrow function
34 | // int area2(length, width) => length * width;
35 | // =========================================================================================================
--------------------------------------------------------------------------------
/essential-dart-concepts/hello_world.dart:
--------------------------------------------------------------------------------
1 | void main(){
2 | print("Hello World");
3 | }
--------------------------------------------------------------------------------
/essential-dart-concepts/lists-samples/IntList.dart:
--------------------------------------------------------------------------------
1 | import "dart:io";
2 |
3 | void main(){
4 | List numbers = [];
5 |
6 | for(int i = 0; i < 5; i++){
7 | stdout.write("Please enter number ${i+1}: ");
8 | numbers.add(int.parse(stdin.readLineSync()!));
9 | }
10 |
11 | // Dispaly integers from first to last
12 | for(int j = 0; j< numbers.length; j++){
13 | stdout.write("${numbers[j]} ");
14 | }
15 |
16 | print(" "); // add space
17 |
18 | // Display the integers from last to first
19 | for(int z = numbers.length - 1; z >= 0; z--){
20 | stdout.write("${numbers[z]} ");
21 | }
22 | }
--------------------------------------------------------------------------------
/essential-dart-concepts/lists-samples/Prices.dart:
--------------------------------------------------------------------------------
1 | import 'dart:io';
2 | void main(){
3 | List prices = [500, 600, 530, 340, 1000, 700, 250, 5000, 1500, 4000];
4 |
5 | double sumPrice = 0;
6 | double avePrice = 0;
7 |
8 | // Calculate the sum of all prices
9 | for(int i=0; i < prices.length; i++){
10 | sumPrice += prices[i];
11 | }
12 |
13 | // Display to sum of all prices
14 | print("The sum of all products is: ${sumPrice}");
15 |
16 | // Display all values less than 500
17 | stdout.write("The values less than 500 are: ");
18 | for (final val in prices){
19 | if(val < 500)
20 | stdout.write(" ${val}");
21 | }
22 |
23 | // Calculate the average of the prices
24 | avePrice = sumPrice / prices.length;
25 |
26 | // Display all values higher than the avePrice
27 | stdout.write("The values greater than the average are: ");
28 | for (final z in prices){
29 | if(z < avePrice){
30 | stdout.write(" ${z}");
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------