Hello! Here I begin my journey with Flutter (again!) but this time I'm going to use this platform here to help me keep track of my studies.
First of all, I'm following Flutterando's Roadmap to guide me here. Second, I'm doing Deivid Wilyan's course for newbies in Dart. Both are written and spoken in Portuguese (since it's my mother toungue) but if anyone here recommends other courses in English, I'm going to check for sure and add it to my studies.
So. Basics... I've done the basics before but it's been three months since I last studied Dart, so I definitely need some review. Today I basically covered variables, loops, If/else, switch. Plus, I reviewed OOP(which I think I'm okay with since I've been studying it with Kotlin for a while), Null safety and the async part with Future, await and async key words.
Coding notes:
This is just to keep to myself and not loose and also for those who wants to see a bit of what I am coding.
void main() {
// 1 - Introduction to variables
String variableName = "Evelyn";
print(variableName);
int value = 10;
print(value);
bool isTrue = true;
print(isTrue);
List<String> listOfWords = ["Evelyn", "Fernandes"];
print(listOfWords[0]);
print('${listOfWords[0]} - ${listOfWords[1]}');
// 2 - Null-safety
String? name; // can be null
name = "ABC";
print(name); //garants that this variable won't be a null one
late String lastName; // value is going to be given later in the app
lastName = "Fernandes";
print(lastName);
// 3 - If and Switch
bool goAhead = true;
if (goAhead) {
print("Walk");
} else {
print("Stop");
}
if (10 > 5) {
print("10 is greater than 5");
}
int valueInt = 6;
switch (valueInt) {
case 0:
print("ZERO");
break;
case 1:
print("ONE");
break;
case 2:
print("TWO");
break;
default:
print("NUMBER");
}
// 4 - Loops
for (int i = 1; i <= 10; i++) {
print(i * 2);
}
int counter = 10;
while (counter != 1) {
counter--;
print("Loop -> $counter");
}
// 5 - Methods and classes
Cellphone evelynPhone = Cellphone("blue", 4, 5.5, 0.500);
Cellphone isaPhone = Cellphone("black", 10, 6.0, 0.700);
print(evelynPhone.color);
print(isaPhone.toString());
double result = evelynPhone.phoneValue(750);
print(result);
// 6 - Object Orientation
Car alfaRomeo = Car("Alfa Romeo");
Car mclaren = Car("McLaren");
alfaRomeo.model;
// 7 - Inheritance, Polimorfism, Abstration (no Interface)
Isa isa1 = Isa();
print(isa1.speak());
Payment payment1 = PayWithCreditCard();
payment1.pay();
payment1 = PayWithPix();
payment1.pay();
}
abstract class Payment {
void pay();
}
class PayWithCreditCard implements Payment {
void pay() {
print("Paying with credit card");
}
}
class PayWithPix implements Payment {
void pay() {
print("Paying with pix");
}
}
class Dad {
String speak() {
return "Hello, world!";
}
}
class Isa extends Dad {}
abstract class Being {
String communicate();
}
class Alien implements Being {
String communicate() {
return "Hello, humans!";
}
}
class Human implements Being {
String communicate() {
return "Hello! Good morning!";
}
}
class Car {
final String model;
String _secret =
"Much money"; // can't access this property in other Dart files
int _value = 10000;
int get carValue => _value; // getter
void setValue(int value) => _value = value; // arrow function
Car(this.model);
}
class Cellphone {
final String color;
final int qtProc;
final double size;
final double weight;
Cellphone(this.color, this.qtProc, this.size, this.weight);
String toString() {
return "Color: $color, qtProc: $qtProc,Size: $size , Weight: $weight";
}
double phoneValue(double value) {
return value * qtProc;
}
}
void main() {
// 8 - Future, Async and Await
String name = 'Evelyn';
Future<String> cepFuture = getCepByName('Dep. Salvador DaLi');
late String cep;
// cep.then((result) => cepValue = result);
cep = await cepFuture;
print(cep);
}
//external service
Future<String> getCepByName(String name) {
//mock request
return Future.value('89457890');
}