From ef098c2aa47d873709a622efe3b14ee51d818758 Mon Sep 17 00:00:00 2001 From: RamonFarizel <45459898+RamonFarizel@users.noreply.github.com> Date: Thu, 22 Aug 2024 13:42:18 -0300 Subject: [PATCH] Document scale parameter for Image and RawImage (#153728) This PR documents the scale parameter for Image and RawImage. It adds the quote from the [Image.memory](https://main-api.flutter.dev/flutter/widgets/Image/Image.memory.html) for other constructors like: `Image.asset`, `Image.new`, `Image.network`, `Image.file` and `RawImage` > The scale argument specifies the linear scale factor for drawing this image at its intended size and applies to both the width and the height. For example, if this is 2.0, it means that there are four image pixels for every one logical pixel, and the image's actual width and height (as given by the [dart:ui.Image.width](https://main-api.flutter.dev/flutter/dart-ui/Image/width.html) and [dart:ui.Image.height](https://main-api.flutter.dev/flutter/dart-ui/Image/height.html) properties) are double the height and width that should be used when painting the image (e.g. in the arguments given to [Canvas.drawImage](https://main-api.flutter.dev/flutter/dart-ui/Canvas/drawImage.html)). #148623 --- packages/flutter/lib/src/widgets/basic.dart | 10 ++++++++-- packages/flutter/lib/src/widgets/image.dart | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index 49676bcf8c..3eb41334e5 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -5957,6 +5957,10 @@ class RichText extends MultiChildRenderObjectWidget { /// expected to call [dart:ui.Image.dispose] on the [image] once the [RawImage] /// is no longer buildable. /// +/// The `scale` argument specifies the linear scale factor for drawing this +/// image at its intended size and applies to both the width and the height. +/// {@macro flutter.painting.imageInfo.scale} +/// /// This widget is rarely used directly. Instead, consider using [Image]. class RawImage extends LeafRenderObjectWidget { /// Creates a widget that displays an image. @@ -6005,9 +6009,11 @@ class RawImage extends LeafRenderObjectWidget { /// aspect ratio. final double? height; - /// Specifies the image's scale. + /// The linear scale factor for drawing this image at its intended size. /// - /// Used when determining the best display size for the image. + /// The scale factor applies to the width and the height. + /// + /// {@macro flutter.painting.imageInfo.scale} final double scale; /// If non-null, this color is blended with each image pixel using [colorBlendMode]. diff --git a/packages/flutter/lib/src/widgets/image.dart b/packages/flutter/lib/src/widgets/image.dart index 5e61b391bc..85faacd8ed 100644 --- a/packages/flutter/lib/src/widgets/image.dart +++ b/packages/flutter/lib/src/widgets/image.dart @@ -339,6 +339,10 @@ class Image extends StatefulWidget { /// To show an image from the network or from an asset bundle, consider using /// [Image.network] and [Image.asset] respectively. /// + /// The `scale` argument specifies the linear scale factor for drawing this + /// image at its intended size and applies to both the width and the height. + /// {@macro flutter.painting.imageInfo.scale} + /// /// Either the [width] and [height] arguments should be specified, or the /// widget should be placed in a context that sets tight layout constraints. /// Otherwise, the image dimensions will change as the image is loaded, which @@ -379,6 +383,10 @@ class Image extends StatefulWidget { /// Otherwise, the image dimensions will change as the image is loaded, which /// will result in ugly layout changes. /// + /// The `scale` argument specifies the linear scale factor for drawing this + /// image at its intended size and applies to both the width and the height. + /// {@macro flutter.painting.imageInfo.scale} + /// /// All network images are cached regardless of HTTP headers. /// /// An optional [headers] argument can be used to send custom HTTP headers @@ -428,6 +436,10 @@ class Image extends StatefulWidget { /// Creates a widget that displays an [ImageStream] obtained from a [File]. /// + /// The `scale` argument specifies the linear scale factor for drawing this + /// image at its intended size and applies to both the width and the height. + /// {@macro flutter.painting.imageInfo.scale} + /// /// Either the [width] and [height] arguments should be specified, or the /// widget should be placed in a context that sets tight layout constraints. /// Otherwise, the image dimensions will change as the image is loaded, which @@ -508,6 +520,10 @@ class Image extends StatefulWidget { /// If the `bundle` argument is omitted or null, then the /// [DefaultAssetBundle] will be used. /// + /// The `scale` argument specifies the linear scale factor for drawing this + /// image at its intended size and applies to both the width and the height. + /// {@macro flutter.painting.imageInfo.scale} + /// /// By default, the pixel-density-aware asset resolution will be attempted. In /// addition: ///