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('Hello Dart'); | |
} |
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() { | |
// Way 1 | |
print('----Declare Way 1----'); | |
var unlimited; | |
unlimited = 'unlimited'; | |
print(unlimited); | |
// 'unlimited' => 1000.00, ALLOWED | |
unlimited = 1000.0; | |
print(unlimited); | |
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:math'; | |
void main() { | |
const String USER_NAME = 'nikk'; | |
// USER_NAME = 'wenyan'; => Error | |
final String USER_ADDRESS = 'China'; | |
// USER_ADDRESS = 'United States'; => Error | |
// ------------------------------------ |
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() { | |
Car newMercedes = Car(brandName:'Benz', modelName:'G', currency:'USD', msrp:1000.0); | |
print('Car: ${newMercedes.brandName} ${newMercedes.modelName}'); | |
print('Price: ${newMercedes.currency} ${newMercedes.msrp}'); | |
print(''.padLeft(20, '-')); | |
Car newHonda = Car.shorter(brandName:'Honda', modelName:'Fit'); | |
print('Car: ${newHonda.brandName} ${newHonda.modelName}'); | |
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() { | |
// provide only required parameter | |
FunnyText uselessWidget1 = FunnyText('hello'); | |
// provide an empty named parameter | |
FunnyText uselessWidget2 = FunnyText('hello', style: TextStyle()); | |
// provide a complete named parameter to override DEFAULT value, which is 20.0 | |
FunnyText uselessWidget3 = FunnyText('hello', style: TextStyle(fontSize: 30.0)); | |
uselessWidget1.printFontSize(); // 20 | |
uselessWidget2.printFontSize(); // 20 |
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() { | |
// ? Operator | |
Coke myCoke = Coke(volume: 600); | |
// this is unsafe as anyone can change volume before printing. | |
// for example, myCoke = null | |
// then it gonna throw an error. | |
print(myCoke.volume); // 600 | |
// so let's use ? as null check operator to ensure this won't happen |
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() { | |
List<String> usernames = ['lana', 'del', 'rey', 'hope', 'sandoval']; | |
// add => bottom | |
usernames.add('nikk'); | |
print(usernames); //[lana, del, rey, hope, sandoval, nikk] | |
// add all | |
usernames.addAll(['wenyan', 'li']); | |
print(usernames); // [lana, del, rey, hope, sandoval, nikk, wenyan, li] |
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() { | |
// handle data | |
// use Class is kind of overkill from Design Perspective | |
var user = { | |
'name': 'Nikk.Li', | |
'age': 28, | |
'height': 171.0, | |
'weight': 63, | |
'children': null |
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() { | |
var orderType = OrderType.Domestic; | |
// ENUM item -> index | |
print(' '.padLeft(10,'-') + 'Enum index' + ' '.padRight(10,'-')); | |
print(orderType.index); | |
// ENUM item -> value | |
print(' '.padLeft(10,'-') + 'Enum value' + ' '.padRight(10,'-')); | |
print(orderType); | |
} |
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(' '.padLeft(10,'-') + 'Ternary Operator' + ' '.padRight(10,'-')); | |
bool expression = true; | |
// Logic -> used in business logic of binary/simple strategy; | |
expression ? { | |
print(true) | |
} : { | |
print(false) |
OlderNewer