debugAssertNotDisposed method

  1. @protected
bool debugAssertNotDisposed()
inherited

Throws when the controller is used after disposal (debug builds only).

In debug mode, throws a FlutterPageableException describing the controller types plus creation, disposal, last-operation, and offending-call stacks. In release mode asserts are skipped and this returns true without checking. Always returns true so it can be used as a bare statement.

Implementation

@protected
bool debugAssertNotDisposed() {
  trackOperation('debugAssertNotDisposed');
  assert(() {
    if (_isDisposed) {
      final useAfterDisposeAt = DateTime.now();
      final useAfterDisposeStack = StackTrace.current;
      throw FlutterPageableException(
        'The PageableController [$runtimeType] for Item($Item - ${getItemType()}***${getItemType().runtimeType}) '
        'and PageKey($PageKey - ${getPageKeyType()}***${getPageKeyType().runtimeType}) was used after being '
        'disposed.\nOnce you have called dispose() on a PageableController, it can no longer be '
        'used.\nIf you’re using a Future, it probably completed after '
        'the disposal of the owning widget.\nMake sure dispose() has not '
        'been called yet before using the PageableController.\n'
        'Lifecycle details:\n'
        '- Created at: ${_createdAt.toIso8601String()}\n'
        '- Disposed at: ${_disposedAt?.toIso8601String() ?? 'unknown'}\n'
        '- Last operation: ${_lastOperation ?? 'unknown'} at ${_lastOperationAt?.toIso8601String() ?? 'unknown'}\n'
        '- Time from create to dispose: ${_formatAge(_createdAt, _disposedAt)}\n'
        '- Time from dispose to invalid use: ${_formatAge(_disposedAt ?? _createdAt, useAfterDisposeAt)}\n'
        'Creation stack:\n$_creationStackTrace\n'
        'Dispose stack:\n${_disposeStackTrace ?? 'unknown'}\n'
        'Last operation stack:\n${_lastOperationStackTrace ?? 'unknown'}\n'
        'Use-after-dispose stack:\n$useAfterDisposeStack',
      );
    }
    return true;
  }());
  return true;
}