flutter_persistent_queue icon indicating copy to clipboard operation
flutter_persistent_queue copied to clipboard

can we remove selected item from list of items stored in queue ?

Open sumitbhanushali opened this issue 5 years ago • 1 comments

sumitbhanushali avatar Aug 28 '20 20:08 sumitbhanushali

@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);
}

oakromulo avatar Aug 31 '20 14:08 oakromulo