Skip to content

Instantly share code, notes, and snippets.

@digitaljoni
Last active February 26, 2020 11:21
Show Gist options
  • Select an option

  • Save digitaljoni/d194e98bb77c4510c2cf76d344b0641d to your computer and use it in GitHub Desktop.

Select an option

Save digitaljoni/d194e98bb77c4510c2cf76d344b0641d to your computer and use it in GitHub Desktop.
Dart Code Sample #1
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
if (isDiscounted) {
print('Discounted Price: ${itemPrice - (itemPrice * discount)}');
} else {
print('Retail Price: $itemPrice');
}
List<String> itemParts = [
'Raspberry Pi',
'Power Supply',
'Memory Card',
'Official Case',
];
print('Kit includes:');
for (int i = 0; i < itemParts.length; i++) {
print('$i. ${itemParts[i]}');
}
Map<String, String> itemModels = {
'a32082': '3 Model B',
'a020d3': '3 Model B+',
'c03111': '4 Model B',
};
print('Models available:');
for (String key in itemModels.keys) {
print('$key - ${itemModels[key]}');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment