createLocalImageConfiguration function

ImageConfiguration createLocalImageConfiguration (BuildContext context, { Size size })

Creates an ImageConfiguration based on the given BuildContext (and optionally size).

This is the object that must be passed to BoxPainter.paint and to ImageProvider.resolve.

If this is not called from a build method, then it should be reinvoked whenever the dependencies change, e.g. by calling it from State.didChangeDependencies, so that any changes in the environment are picked up (e.g. if the device pixel ratio changes).

See also:

  • ImageProvider, which has an example showing how this might be used.

Implementation

ImageConfiguration createLocalImageConfiguration(BuildContext context, { Size size }) {
  return new ImageConfiguration(
    bundle: DefaultAssetBundle.of(context),
    devicePixelRatio: MediaQuery.of(context, nullOk: true)?.devicePixelRatio ?? 1.0,
    locale: Localizations.localeOf(context, nullOk: true),
    textDirection: Directionality.of(context),
    size: size,
    platform: defaultTargetPlatform,
  );
}