createLocalImageConfiguration function

ImageConfiguration createLocalImageConfiguration(
  1. BuildContext context,
  2. {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 ImageConfiguration(
    bundle: DefaultAssetBundle.of(context),
    devicePixelRatio: MediaQuery.maybeDevicePixelRatioOf(context) ?? 1.0,
    locale: Localizations.maybeLocaleOf(context),
    textDirection: Directionality.maybeOf(context),
    size: size,
    platform: defaultTargetPlatform,
  );
}