This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// OOP Principles Example in Dart with Pokemon Context | |
// 1. Classes and Objects | |
abstract class Pokemon { | |
String name; | |
int level; | |
Pokemon(this.name, this.level); | |
// 3. Abstraction (Abstract method representing a move) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// OOP Principles Example in Dart with Pokemon Context | |
// 1. Classes and Objects | |
abstract class Pokemon { | |
String name; | |
int level; | |
Pokemon(this.name, this.level); | |
// 3. Abstraction (Abstract method representing a move) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main(){ | |
performTasks(); | |
} | |
void performTasks () async{ | |
task1(); | |
String task2Result= await task2(); | |
task3(task2Result); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Product{ | |
String _name; | |
num _price; | |
String _expDate; | |
Product(this._name,this._price,this._expDate); | |
void printDetails(){ | |
print('Name: $_name'); | |
print('Price: $_price'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Object { | |
int id = 0; | |
String name='abc'; | |
Object(this.id); | |
@override | |
String toString()=> id.toString() + name; | |
} | |
void main() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// classes and objects example | |
/* | |
class Car{ | |
int numberOfDoors=5; | |
void drive(){ | |
print('wheels start turning'); | |
} | |
} | |
void main(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Enumerated types, often called enumerations or enums, | |
// are a special kind of class used to represent a fixed number of constant values. | |
//Declare an enumerated type using the enum keyword: | |
enum Color { red, green, blue } | |
//To get a list of all of the values in the enum, use the enum’s values constant. | |
List<Color> colors = Color.values; | |
void main() { | |
//You can use trailing commas when declaring an enumerated type. | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
int sumEven(List li) { | |
int sum = 0; | |
for (var i in li) { | |
if (i % 2 == 0) { | |
sum = sum + i; | |
} | |
} | |
return sum; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Chapter 5: Control Flow Statements | |
void main() { | |
//if statment | |
var testList = [2, 4, 8, 16, 32]; | |
print(testList); | |
if (testList.isNotEmpty) { | |
print("Emptying List"); | |
testList.clear(); | |
} | |
print(testList); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { @override | |
Widget build(BuildContext context) { | |
return MaterialApp( home: MyHomePage(), | |
); } | |
} | |
class MyHomePage extends StatefulWidget { MyHomePage(); | |
@override | |
createState() => _MyHomePageState(); |
NewerOlder