This file contains hidden or 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() { | |
final String name = 'Joni'; // final variable can be set only once | |
const double pi = 3.14159265359; // compile-time constant | |
name = 'Jones'; // error | |
pi = 123; // error | |
print('name is $name'); | |
print('area of a circle with radius of 3 is ${pi * (3 * 3)}'); |
This file contains hidden or 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> itemParts = [ | |
'Raspberry Pi', | |
'Power Supply', | |
'Memory Card', | |
'Official Case', | |
]; | |
print(itemParts[1]); // 'Power Supply' | |
print(itemParts[3]); // 'Official Case' |
This file contains hidden or 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() { | |
String productName = 'Raspberry Pi'; | |
print(productName.length); | |
print(productName.toUpperCase()); | |
print(productName.substring(1, 10)); | |
String productImageName = productName.replaceAll(' ', '_').toLowerCase(); | |
print('$productImageName.jpg'); |
This file contains hidden or 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() { | |
// Declaring Variables | |
var productName = 'Raspberry Pi'; // type inference (String) | |
int itemQuantity = 42; // type annotation - better | |
double itemPrice = 3499.00; | |
bool isDiscounted = true; | |
double discount = .10; | |
print(productName); | |
print('Qty: $itemQuantity'); // string interpolation |
This file contains hidden or 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() { | |
final CardDeck newDeck = CardDeck.create(); | |
print(newDeck); | |
} | |
enum Suit { | |
diamond, |
NewerOlder