The Fall and Rise of Dart, Google’s ‘JavaScript Killer’
I do not want to confuse this part with what I am writing. This section is a record of some of the points I made when I studied this programming language called DART. But later, I think it will all be related.
Let start the show !
forEach() in List
Here are the extension functions used in Kotlin. Let us write with an example.
Practice makes perfect.
List<String> greetings = ['Hello', "Good Morgan", "Ohayo Gozaimasu", "Namaste", "Ni Hao"];
for(var greet in greetings) {
print(greet);
}
greetings.forEach((element) => print(element));
As you can see, you can write forEach without having to write forLoop. Thats the point.
Dynamic Types
Dynamic Type tells the compiler to accept any variable type. Let’s check.
dynamic myNumber;
myNumber = "Hello World";
print(myNumber);
myNumber = 345;
print(myNumber);
myNumber = 45.60;
print(myNumber);
myNumber = true;
print(myNumber);
Named Parameters
Named Parameters are used in places where you need to include a name when assigning Variable Passing to functions.
For example:
helloWorld(name: "ENTER", rank: "CEO");
}
void helloWorld({String name, String rank}) {
print("Hello $name, $rank");
}
When setting variable passes, you must enter a name in front of it before using {} . name: “ENTER“, rank: “CEO” and so on.
Positional Optional Parameters
If you want to add optional parameters, you can specify [] . For example.
helloWorld("ENTER", "App");
helloWorld("KiFuuu", "Watch2Donate", "Burma");
}
void helloWorld(String name, String rank, [String address]) {
print("Hello $name, $rank");
if(address != null) {
print(address);
}
}
These sections are a compilation of notes I made while I was studying.
Let’s start now. Sharing is Caring!
typedef
typedef is a function-type alias. If we write with a little example, it will be much clearer.
Code
typedef Operation(int firstNum, int secondNum);
Add(int firstNum, int secondNum) {
print(firstNum + secondNum);
}
Subtract(int firstNum, int secondNum) {
print(firstNum - secondNum);
}
Multiply(int firstNum, int secondNum) {
print(firstNum * secondNum);
}
Divide(int firstNum, int secondNum) {
print(firstNum / secondNum);
}
main(List<String> arguments) {
Operation op;
op = Add;
op(45, 67);
op = Subtract;
op(60, 20);
op = Multiply;
op(45, 5);
op = Divide;
op(45, 5);
}
As described above, typedef Operation is defined by two passing values. It then uses that typedef to reconnect functions with the same passing values.
.. in dart
As I studied Moor, I came across the use of (..). When I studied it, I found a cascade notation. For example, Lets together practice & I think it will be more clear for you.
List list = [];
list.add(45);
list.add(60);
list.add(80);
list.add(56);
Instead of using the above, you can write as below.
List list = [];
list
..add(45)
..add(60)
..add(80)
..add(56);
You can also write the form shown below !
var l1 = new List<int>()..add(0)..addAll([1, 2, 3]);
()() in Dart
In the same vein, I came across the use of () () again. It will be easier to understand with a little example. Lets code together now !
main() {
var tc = TestCall();
tc.assign().call();
tc.assign()();
}
class TestCall {
int num;
TestCall assign() {
this.num = 56;
return this;
}
call() {
print(num);
}
}
Instead of writing .call (), you can line it up with () ().
Happy Coding all KiFuuu’s.
Sharing is Caring !
Programming for Our Future .
Thanks for visiting.
Thank you for the details explain.
You are the best 👍
Thanks for sharing
Thanks for your sharing.
Thanks for sharing
Thank for sharing
❤✅
Thank you so much for sharing your knowledge.
Thz bro
welcome Bro
Thanks for sharing
Thanks for knowledge sharing!
Thanks knight 🙂
Welcome Mousy 🙂
Thanks a bunch ☺️
Upload new contents.
Morning 🌻
thanks for sharing.
Qlik to Dune
When I ever see this article , I miss my university student life.
Nice article. I love it.Thanks.
Hola 😁
🌧️🌧️
Pro Author ,thanks for knowledge sharing.
done20
Thank for sharing