DisposableBuildContext<T extends State<StatefulWidget>> constructor

DisposableBuildContext<T extends State<StatefulWidget>>(
  1. T _state
)

Creates an object that provides access to a BuildContext without leaking a State.

Creators must call dispose when the State is disposed.

State.mounted must be true.

Implementation

DisposableBuildContext(T this._state)
    : assert(_state.mounted, 'A DisposableBuildContext was given a BuildContext for an Element that is not mounted.')  {
  // TODO(polina-c): stop duplicating code across disposables
  // https://github.com/flutter/flutter/issues/137435
  if (kFlutterMemoryAllocationsEnabled) {
    FlutterMemoryAllocations.instance.dispatchObjectCreated(
      library: 'package:flutter/widgets.dart',
      className: '$DisposableBuildContext',
      object: this,
    );
  }
}