Last active
February 8, 2020 11:36
-
-
Save vishweshsoni/acdfc36dc3125cb40c3daba809eee2d1 to your computer and use it in GitHub Desktop.
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() { | |
// // print(printInteger(10)); | |
// var cc=log(44.2); | |
// print(cc.runtimeType); | |
// } | |
// printInteger(int number) | |
// { | |
// return number; | |
// } | |
// dynamic log(dynamic obj){ | |
// print(obj.toString()); | |
// return obj; | |
// } | |
//Abstract class method | |
// void main(){ | |
// Gist g= Gist(); | |
// g.meCall(); | |
// } | |
// abstract class Vish{ | |
// void meCall(); | |
// } | |
// class Gist extends Vish{ | |
// void meCall(){ | |
// print("hi"); | |
// } | |
// } | |
// //difference between dynamic and object | |
// dynamic a; | |
// Object b; | |
// void main(){ | |
// a = ""; | |
// b = ""; | |
// printLengths(); | |
// } | |
// printLengths() { | |
// // no warning | |
// print(a.length); | |
// // warning: | |
// // The getter 'length' is not defined for the class 'Object' | |
// print(b.length); | |
// } | |
//Diff between var final and dynamic | |
// void main() { | |
// dynamic v = 123; | |
// v = 456; | |
// v = 'abc'; | |
// var v1 = 123; // v is of type int. | |
// v1 = 456; // changing value of v from 123 to 456. | |
// v1 = 'abc'; // ERROR: can't change type of v from int to String. | |
// final v2 = 123; // v is of type int. | |
// v2 = 456; // ERROR: can't change value of v from 123 to 456. | |
// v2 = 'abc'; | |
// } | |
//Without giving the type to the function we can still return the type. | |
// void main(){ | |
// print(isFunction(10)); | |
// } | |
// isFunction(int i){ | |
// return i is int; | |
// } | |
//Default parameter in the function named | |
// void main() | |
// { | |
// doStuff();} | |
// void doStuff( | |
// {List<int> list = const [1, 2, 3], | |
// // Map<String, String> gifts = const { | |
// 'first': 'paper', | |
// 'second': 'cotton', | |
// 'third': 'leather' | |
// }}) { | |
// print('list: $list'); | |
// print('gifts: $gifts'); | |
// } | |
// bool topLevel = true; | |
// void main() { | |
// var insideMain = true; | |
// void myFunction() { | |
// var insideFunction = true; | |
// void nestedFunction() { | |
// var insideNestedFunction = true; | |
// assert(topLevel); | |
// assert(insideMain); | |
// assert(insideFunction); | |
// assert(insideNestedFunction); | |
// } | |
// } | |
// } | |
//factory pattern | |
// class GetWidget{ | |
// String name; | |
// factory GetWidget(String n){ | |
// if(n=="Container"){ | |
// return GetWidget.container(); | |
// } | |
// else if(n=="Align"){ | |
// return GetWidget.align(); | |
// } | |
// } | |
// GetWidget.container(){ | |
// name= "Scaffold.container()"; | |
// } | |
// GetWidget.align(){ | |
// name= "Scaffold.Align()"; | |
// } | |
// } | |
// void main(){ | |
// GetWidget g= new GetWidget("Container"); | |
// print(g.name); | |
// } | |
//use factory method when you want to return existing instance of class insted of //creating new one | |
//-Singleton | |
//-want to return subclass instance insted of class itself | |
// class Person { | |
// // In the interface, but visible only in this library. | |
// final _name; | |
// // Not in the interface, since this is a constructor. | |
// Person(this._name); | |
// // In the interface. | |
// String greet(String who) => 'Hello, $who. I am $_name.'; | |
// } | |
// // An implementation of the Person interface. | |
// class Impostor implements Person { | |
// get _name => ''; | |
// String greet(String who) => 'Hi $who. Do you know who I am?'; | |
// } | |
// String greetBob(Person person) => person.greet('Bob'); | |
// void main() { | |
// print(greetBob(Person('Kathy'))); | |
// print(greetBob(Impostor())); | |
// } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment