Skip to main content

Flutter Dart Simple Queue Example

Queue is a type of data structure. Queue can performs data insertion operations from both sides front and end. Queue is based upon FIFO data insertion method. Here FIFO means first in first out.
Flutter Dart Simple Queue Example

Flutter Dart Simple Queue Example

1. Import dart:collection package in our flutter main.dart file.
import 'dart:collection'; 
2. Defining a Integer type of Queue in Dart.
final testQueue = Queue<int>();
3. Inserting item at first position of Queue in dart.
testQueue.addFirst(0);
4. Inserting item at last position of Queue in dart.
testQueue.addLast(6);
5. Inserting multiple items at once in middle of Queue in dart.
testQueue.addAll([1, 2, 3, 4, 5]);
6. Removing First and Last item from Queue in Dart.
  testQueue.removeFirst();
  testQueue.removeLast();
7. Removing specific item from Queue in Dart.
testQueue.remove(1);
8. Delete all items from Queue and clear.
testQueue.clear();
You can learn about more Queue functions HERE on Dart's official page.
Complete source code for main.dart file:
import 'dart:collection'; 

void main() { 
  final testQueue = Queue<int>();
  testQueue.addFirst(0);
  print(testQueue);
  testQueue.addLast(6);
  print(testQueue);
  testQueue.addAll([1, 2, 3, 4, 5]);
  print(testQueue);
  testQueue.removeFirst();
  testQueue.removeLast();
  print(testQueue);
  testQueue.remove(1);
  print(testQueue);
  testQueue.clear();
  print(testQueue);
}
Output:

Comments