Last active
February 26, 2020 11:21
-
-
Save digitaljoni/d194e98bb77c4510c2cf76d344b0641d to your computer and use it in GitHub Desktop.
Dart Code Sample #1
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 | |
| 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