flutter_persistent_queue
flutter_persistent_queue copied to clipboard
can we remove selected item from list of items stored in queue ?
@sumitbhanushali not directly, the implementation is "first-in first-out". However it can be done like this:
import 'dart:math';
import 'package:flutter_persistent_queue/flutter_persistent_queue.dart';
Future<void> example() async {
final seed = Random();
final pq = PersistentQueue('issue');
pq.clear();
// load queue with 5 random values from 0 to 1
for (final value in List.generate(5, (_) => seed.nextDouble())) {
await pq.push(value);
}
// extract values from queue and replace 3rd number with -1
final values = await pq.clear();
values[2] = -1;
// reload queue with updated values
for (final value in values) {
await pq.push(value);
}
// verify if replacement worked correctly
final updatedValues = await pq.toList();
assert(updatedValues[2] == -1);
}