dispose method
Removes the listener and fails any pending waiters.
Safe to call multiple times. Safe to call after the underlying Shard
has already been disposed — the listener removal is skipped in that
case because ChangeNotifier.removeListener after dispose() throws.
Implementation
Future<void> dispose() async {
if (_isDisposed) return;
_isDisposed = true;
if (!_shard.isDisposed) {
_shard.removeListener(_onChange);
}
for (final w in _waiters) {
if (!w.completer.isCompleted) {
w.completer.completeError(
StateError('ShardTester disposed while waiting'),
);
}
}
_waiters.clear();
}