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() { | |
// Shuffle the numbers randomly and print them just once | |
List<int> numbers = [4, 59, 135, 7264, 135, 59]; | |
List<int> newNumbers = numbers.toSet().toList(); | |
print('Numbers without repetition: $newNumbers'); | |
newNumbers.shuffle(); | |
print('Shuffle numbers: $newNumbers'); | |
// Add a name 'Daniel' to the list and shuffle it | |
List<String> names = ['Max', 'Ed', 'Sara', 'Peter']; |
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<Cart> carts = [ | |
Cart(date: '19/8/2020', item: 'shirt', price: 20), | |
Cart(date: '19/8/2020', item: 'glasses', price: 10), | |
Cart(date: '18/8/2020', item: 'pants', price: 30), | |
Cart(date: '18/8/2020', item: 'shirt', price: 15), | |
Cart(date: '17/8/2020', item: 'hat', price: 5) | |
]; | |
int totalPriceByDate(String date) { |
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<Car> myCars = [ | |
Car(brand: 'BMW', color: 'Red'), | |
Car(brand: 'BMW', color: 'Black'), | |
Car(brand: 'Mercedes', color: 'White'), | |
Car(brand: 'Mercedes', color: 'Green'), | |
Car(brand: 'Mercedes', color: 'Brawn') | |
]; | |
var carBrands = myCars.map((e) => e.brand).toSet().toList(); |
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() { | |
// Subtract all numbers and print the result | |
List<int> numbers = [4000, 59, 135, 1000]; | |
var subtract = numbers.reduce((a, b) => a - b); | |
print(subtract); | |
// Concatenate the names and print all as a word | |
List<String> names = ['Max', 'Ed', 'Sara', 'Peter']; | |
String combinedNames = names.reduce((first, second) => first + second); | |
print(combinedNames); |
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 'package:flutter/material.dart'; | |
import 'package:get/get.dart'; | |
void main() => runApp(GetMaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: First(), | |
)); | |
class House { | |
String location; |
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() { | |
// Double all numbers in the list and print them | |
List<int> numbers = [4, 59, 135, 7264]; | |
var powNumbers = numbers.map((num) => num * 2); | |
print(powNumbers); | |
// print the length of each name | |
List<String> names = ['Max', 'Ed', 'Sara', 'Peter']; | |
var lengthNames = names.map((name) => name.length); | |
print(lengthNames); |
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() { | |
// Sort numbers from largest to the smallest | |
List<int> numbers = [4, 59, 135, 7264]; | |
numbers.sort(); | |
print(numbers.reversed); | |
// Sort names from shortest to longest | |
List<String> names = ['Max', 'Ed', 'Sara', 'Peter']; | |
names.sort((a, b) => a.length.compareTo(b.length)); | |
print(names); |
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() { | |
// Put first letter of each name together and print it as string. | |
List<String> names = ['Max', 'John', 'Sara', 'Peter']; | |
// With forEach method | |
List<String> letters = []; | |
names.forEach((name) => letters.add(name.split('').first)); | |
print(letters.join('')); | |
// With fold method |
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() { | |
// Find all names that has letter a | |
List<String> names = ['Max', 'John', 'Sara', 'Peter']; | |
names.forEach((name) => print(name)); | |
// Find the sum of all number | |
List<int> numbers = [4, 59, 135, 7264]; | |
int sum = 0; | |
numbers.forEach((num) => sum += num); |
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() { | |
// Find all names that has letter a | |
List<String> names = ['Max', 'John', 'Sara', 'Peter']; | |
Iterable<String> visibleNames = names.where( | |
(name) => name.contains('a'), | |
); | |
print(visibleNames); | |
//Find all even numbers | |
List<int> numbers = [13, 2890, 95234, 79357, 300]; |
NewerOlder