Lists
List.generate(int length, E Function(int) generator, {bool growable = true}) |
List .generate(3, (int index) => index * index); // [0, 1, 4] |
List.filled(int length, dynamic fill, {bool growable = false}) |
List .filled(3, 0, growable: true); // [0, 0, 0] |
List.add(List<dynamic> value); |
List.add('Madonna'); |
List.addAll(Iterable<List<dynamic>> iterable); |
List.addAll([12,23,1235,532]); |
List.insert(int index, List<dynamic> element); |
List.insert(2,'HummingBird'); |
List.insertAll(int index, Iterable<List<dynamic>> iterable); |
List.insertAll(3,[12,23,1235,532]); |
Sets
var variable_name = <variable_type>{}; |
var nima = <String>{'nimakarimian'}; |
Set <variable_type> variable_name = {}; |
Set<String> nima = {'nimakarimian'}; |
Set.add(dynamic value); |
Set.add(35); |
Set.addAll(Iterable<dynamic> elements); |
Set.addAll(1,2,3,4,5,7,6); |
Set.elementAt(index); |
It returns the element at the corresponding index. |
Set.length; |
returns the length of the set and the output is of integer type |
Set.contains(element_name); |
Returns boolean value if the element is present in the set |
Set.remove(element_name); |
Removes the Element from the Set |
Set.forEach(...); |
It runs the command defined inside forEach() function for all the elements inside the set. |
Set.clear(); |
It deletes all the elements inside the set |
List<type> list_variable_name = set_variable_name.toList(); |
List<int> idList = idListSet.toList(); |
Set.map(); |
converts the set into the map. |
Set1.union(Set2); |
Set1.intersection(Set2); |
Set2.difference(Set1); |
Sets in Dart is a special case in List where all the inputs are unique i.e it doesn’t contain any repeated input meanwhile Variable_type must be specific!
Maps
var map_name = { key1 : value1, key2 : value2, ..., key n : value n } |
var map_name = new Map(); |
map_name [ key ] = value; |
Maps are dictionary-like data types that exist in key-value form (know as lock-key).
Queues
Queue variable_name = new Queue();has unnecessary new keyword |
Queue Variable_name; |
// With type notation(E) Queue<E> variable_name = new Queue<E>.from(list_name); |
// Without type notation var variable_name = new Queue.from(list_name); |
queue_name.add(element); |
queue_name.addAll(collection_name) |
queue_name.addFirst(element) |
Adds the element from front inside the queue. |
queue_name.addLast(element) |
Adds the element from back in the queue. |
queue_name.clear() |
Removes all the elements from the queue. |
queue_name.first() |
Returns the first element from the queue. |
queue_name.forEach(f(element)) |
Invokes action on each element of this iterable in iteration order. |
queue_name.isEmpty |
Returns boolean true if the queue is empty else return false. |
queue_name.length |
Returns the length of the queue. |
queue_name.removeFirst() |
Removes the first element from the queue. |
queue_name.removeLast() |
Removes the last element from the queue. |
Dart also provides the user to manipulate a collection of data in the form of a queue. A queue is a FIFO (First In First Out) data structure where the element that is added first will be deleted first.
Enums
enum variable_name{ // Insert the data members as shown member1, member2, member3, ...., memberN } |
Limitation of Enumerated Data Type: It cannot be subclassed or mixed in. It is not possible to explicitly instantiate an enum. |
Enumerated types (also known as enumerations or enums) are primarily used to define named constant values. The enum keyword is used to define an enumeration type in Dart. The use case of enumeration is to store finite data members under the same type definition.
|
Created By
https://www.nimakarimian.ir
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by nimakarimian