Creates a new QueueSignal and subscribes to it.
A QueueSignal wraps a Dart Queue, providing reactive tracking for queue operations like adding items to the end or removing items from the front. Perfect for task pipelines, notification streams, or undo histories.
Parameters#
- value: The initial queue items.
- options: The options for the signal.
- keys: A list of objects to watch. If any key changes, the queue signal is re-created.
Example#
import 'dart:collection';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:signals_hooks/signals_hooks.dart';
class NotificationQueueWidget extends HookWidget {
const NotificationQueueWidget({super.key});
@override
Widget build(BuildContext context) {
final notifications = useQueueSignal<String>(Queue());
return Column(
children: [
ElevatedButton(
onPressed: () => notifications.addLast('Alert at ${DateTime.now()}'),
child: const Text('Enqueue Alert'),
),
if (notifications.isNotEmpty)
ElevatedButton(
onPressed: () => notifications.removeFirst(),
child: const Text('Dismiss Oldest Alert'),
),
Expanded(
child: ListView(
children: notifications.map((note) => ListTile(title: Text(note))).toList(),
),
),
],
);
}
}