Commit 5cf04b61 authored by Adam Barth's avatar Adam Barth Committed by GitHub

Rename ImageFit to BoxFit (#8871)

This machinery is useful for arbitrary boxes (e.g., with FittedBox).

Fixes #6463
parent d1f4822e
...@@ -36,7 +36,7 @@ class SectionCard extends StatelessWidget { ...@@ -36,7 +36,7 @@ class SectionCard extends StatelessWidget {
opacity: 0.075, opacity: 0.075,
child: new Image.asset( child: new Image.asset(
section.backgroundAsset, section.backgroundAsset,
fit: ImageFit.cover, fit: BoxFit.cover,
), ),
), ),
), ),
...@@ -129,7 +129,7 @@ class SectionDetailView extends StatelessWidget { ...@@ -129,7 +129,7 @@ class SectionDetailView extends StatelessWidget {
borderRadius: new BorderRadius.circular(6.0), borderRadius: new BorderRadius.circular(6.0),
backgroundImage: new BackgroundImage( backgroundImage: new BackgroundImage(
image: new AssetImage(detail.imageAsset), image: new AssetImage(detail.imageAsset),
fit: ImageFit.cover, fit: BoxFit.cover,
alignment: FractionalOffset.center, alignment: FractionalOffset.center,
), ),
), ),
......
...@@ -149,7 +149,7 @@ class ContactsDemoState extends State<ContactsDemo> { ...@@ -149,7 +149,7 @@ class ContactsDemoState extends State<ContactsDemo> {
children: <Widget>[ children: <Widget>[
new Image.asset( new Image.asset(
'packages/flutter_gallery_assets/ali_connors.jpg', 'packages/flutter_gallery_assets/ali_connors.jpg',
fit: ImageFit.cover, fit: BoxFit.cover,
height: _appBarHeight, height: _appBarHeight,
), ),
// This gradient ensures that the toolbar icons are distinct // This gradient ensures that the toolbar icons are distinct
......
...@@ -63,7 +63,7 @@ class TravelDestinationItem extends StatelessWidget { ...@@ -63,7 +63,7 @@ class TravelDestinationItem extends StatelessWidget {
new Positioned.fill( new Positioned.fill(
child: new Image.asset( child: new Image.asset(
destination.assetName, destination.assetName,
fit: ImageFit.cover, fit: BoxFit.cover,
), ),
), ),
new Positioned( new Positioned(
...@@ -71,7 +71,7 @@ class TravelDestinationItem extends StatelessWidget { ...@@ -71,7 +71,7 @@ class TravelDestinationItem extends StatelessWidget {
left: 16.0, left: 16.0,
right: 16.0, right: 16.0,
child: new FittedBox( child: new FittedBox(
fit: ImageFit.scaleDown, fit: BoxFit.scaleDown,
alignment: FractionalOffset.centerLeft, alignment: FractionalOffset.centerLeft,
child: new Text(destination.title, child: new Text(destination.title,
style: titleStyle, style: titleStyle,
......
...@@ -50,7 +50,7 @@ class DualHeaderWithHint extends StatelessWidget { ...@@ -50,7 +50,7 @@ class DualHeaderWithHint extends StatelessWidget {
child: new Container( child: new Container(
margin: const EdgeInsets.only(left: 24.0), margin: const EdgeInsets.only(left: 24.0),
child: new FittedBox( child: new FittedBox(
fit: ImageFit.scaleDown, fit: BoxFit.scaleDown,
alignment: FractionalOffset.centerLeft, alignment: FractionalOffset.centerLeft,
child: new Text( child: new Text(
name, name,
......
...@@ -44,7 +44,7 @@ class _GridTitleText extends StatelessWidget { ...@@ -44,7 +44,7 @@ class _GridTitleText extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new FittedBox( return new FittedBox(
fit: ImageFit.scaleDown, fit: BoxFit.scaleDown,
alignment: FractionalOffset.centerLeft, alignment: FractionalOffset.centerLeft,
child: new Text(text), child: new Text(text),
); );
...@@ -131,7 +131,7 @@ class _GridPhotoViewerState extends State<GridPhotoViewer> with SingleTickerProv ...@@ -131,7 +131,7 @@ class _GridPhotoViewerState extends State<GridPhotoViewer> with SingleTickerProv
..translate(_offset.dx, _offset.dy) ..translate(_offset.dx, _offset.dy)
..scale(_scale), ..scale(_scale),
child: new ClipRect( child: new ClipRect(
child: new Image.asset(config.photo.assetName, fit: ImageFit.cover), child: new Image.asset(config.photo.assetName, fit: BoxFit.cover),
), ),
), ),
); );
...@@ -181,7 +181,7 @@ class GridDemoPhotoItem extends StatelessWidget { ...@@ -181,7 +181,7 @@ class GridDemoPhotoItem extends StatelessWidget {
child: new Hero( child: new Hero(
key: new Key(photo.assetName), key: new Key(photo.assetName),
tag: photo.tag, tag: photo.tag,
child: new Image.asset(photo.assetName, fit: ImageFit.cover) child: new Image.asset(photo.assetName, fit: BoxFit.cover)
) )
); );
......
...@@ -99,7 +99,7 @@ class _CardDataItem extends StatelessWidget { ...@@ -99,7 +99,7 @@ class _CardDataItem extends StatelessWidget {
new SizedBox( new SizedBox(
width: 144.0, width: 144.0,
height: 144.0, height: 144.0,
child: new Image.asset(data.imageAsset, fit: ImageFit.contain), child: new Image.asset(data.imageAsset, fit: BoxFit.contain),
), ),
new Center( new Center(
child: new Text(data.title, style: Theme.of(context).textTheme.title), child: new Text(data.title, style: Theme.of(context).textTheme.title),
......
...@@ -218,7 +218,7 @@ class _PestoLogoState extends State<PestoLogo> { ...@@ -218,7 +218,7 @@ class _PestoLogoState extends State<PestoLogo> {
children: <Widget>[ children: <Widget>[
new Positioned.fromRect( new Positioned.fromRect(
rect: _imageRectTween.lerp(config.t), rect: _imageRectTween.lerp(config.t),
child: new Image.asset(_kSmallLogoImage, fit: ImageFit.contain), child: new Image.asset(_kSmallLogoImage, fit: BoxFit.contain),
), ),
new Positioned.fromRect( new Positioned.fromRect(
rect: _textRectTween.lerp(config.t), rect: _textRectTween.lerp(config.t),
...@@ -254,7 +254,7 @@ class RecipeCard extends StatelessWidget { ...@@ -254,7 +254,7 @@ class RecipeCard extends StatelessWidget {
children: <Widget>[ children: <Widget>[
new Hero( new Hero(
tag: recipe.imagePath, tag: recipe.imagePath,
child: new Image.asset(recipe.imagePath, fit: ImageFit.contain) child: new Image.asset(recipe.imagePath, fit: BoxFit.contain)
), ),
new Expanded( new Expanded(
child: new Row( child: new Row(
...@@ -325,7 +325,7 @@ class _RecipePageState extends State<RecipePage> { ...@@ -325,7 +325,7 @@ class _RecipePageState extends State<RecipePage> {
tag: config.recipe.imagePath, tag: config.recipe.imagePath,
child: new Image.asset( child: new Image.asset(
config.recipe.imagePath, config.recipe.imagePath,
fit: fullWidth ? ImageFit.fitWidth : ImageFit.cover, fit: fullWidth ? BoxFit.fitWidth : BoxFit.cover,
), ),
), ),
), ),
...@@ -437,7 +437,7 @@ class RecipeSheet extends StatelessWidget { ...@@ -437,7 +437,7 @@ class RecipeSheet extends StatelessWidget {
width: 32.0, width: 32.0,
height: 32.0, height: 32.0,
alignment: FractionalOffset.centerLeft, alignment: FractionalOffset.centerLeft,
fit: ImageFit.scaleDown fit: BoxFit.scaleDown
) )
), ),
new TableCell( new TableCell(
......
...@@ -132,7 +132,7 @@ class VendorItem extends StatelessWidget { ...@@ -132,7 +132,7 @@ class VendorItem extends StatelessWidget {
width: 24.0, width: 24.0,
child: new ClipRRect( child: new ClipRRect(
borderRadius: new BorderRadius.circular(12.0), borderRadius: new BorderRadius.circular(12.0),
child: new Image.asset(vendor.avatarAsset, fit: ImageFit.cover), child: new Image.asset(vendor.avatarAsset, fit: BoxFit.cover),
), ),
), ),
const SizedBox(width: 8.0), const SizedBox(width: 8.0),
...@@ -260,7 +260,7 @@ class FeatureItem extends StatelessWidget { ...@@ -260,7 +260,7 @@ class FeatureItem extends StatelessWidget {
minHeight: 340.0, minHeight: 340.0,
maxHeight: 340.0, maxHeight: 340.0,
alignment: FractionalOffset.topRight, alignment: FractionalOffset.topRight,
child: new Image.asset(product.imageAsset, fit: ImageFit.cover), child: new Image.asset(product.imageAsset, fit: BoxFit.cover),
), ),
), ),
), ),
...@@ -320,7 +320,7 @@ class ProductItem extends StatelessWidget { ...@@ -320,7 +320,7 @@ class ProductItem extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 8.0), padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: new Hero( child: new Hero(
tag: product.tag, tag: product.tag,
child: new Image.asset(product.imageAsset, fit: ImageFit.contain), child: new Image.asset(product.imageAsset, fit: BoxFit.contain),
), ),
), ),
new Padding( new Padding(
......
...@@ -39,7 +39,7 @@ class OrderItem extends StatelessWidget { ...@@ -39,7 +39,7 @@ class OrderItem extends StatelessWidget {
height: 248.0, height: 248.0,
child: new Hero( child: new Hero(
tag: product.tag, tag: product.tag,
child: new Image.asset(product.imageAsset, fit: ImageFit.contain), child: new Image.asset(product.imageAsset, fit: BoxFit.contain),
), ),
), ),
), ),
...@@ -212,7 +212,7 @@ class _OrderPageState extends State<OrderPage> { ...@@ -212,7 +212,7 @@ class _OrderPageState extends State<OrderPage> {
elevation: 1, elevation: 1,
child: new Image.asset( child: new Image.asset(
product.imageAsset, product.imageAsset,
fit: ImageFit.contain, fit: BoxFit.contain,
), ),
); );
}).toList(), }).toList(),
......
...@@ -220,7 +220,7 @@ new GridView.count( ...@@ -220,7 +220,7 @@ new GridView.count(
footer: new GridTileBar( footer: new GridTileBar(
title: new Text(url) title: new Text(url)
), ),
child: new Image.network(url, fit: ImageFit.cover) child: new Image.network(url, fit: BoxFit.cover)
); );
}).toList(), }).toList(),
); );
......
...@@ -53,7 +53,7 @@ class _AppBarBackground extends StatelessWidget { ...@@ -53,7 +53,7 @@ class _AppBarBackground extends StatelessWidget {
bottom: 0.0, bottom: 0.0,
child: new Image.asset( child: new Image.asset(
layer.assetName, layer.assetName,
fit: ImageFit.cover, fit: BoxFit.cover,
height: _kFlexibleSpaceMaxHeight height: _kFlexibleSpaceMaxHeight
) )
); );
......
...@@ -18,13 +18,13 @@ ...@@ -18,13 +18,13 @@
library painting; library painting;
export 'src/painting/basic_types.dart'; export 'src/painting/basic_types.dart';
export 'src/painting/box_fit.dart';
export 'src/painting/box_painter.dart'; export 'src/painting/box_painter.dart';
export 'src/painting/colors.dart'; export 'src/painting/colors.dart';
export 'src/painting/decoration.dart'; export 'src/painting/decoration.dart';
export 'src/painting/edge_insets.dart'; export 'src/painting/edge_insets.dart';
export 'src/painting/flutter_logo.dart'; export 'src/painting/flutter_logo.dart';
export 'src/painting/fractional_offset.dart'; export 'src/painting/fractional_offset.dart';
export 'src/painting/image_fit.dart';
export 'src/painting/text_editing.dart'; export 'src/painting/text_editing.dart';
export 'src/painting/text_painter.dart'; export 'src/painting/text_painter.dart';
export 'src/painting/text_span.dart'; export 'src/painting/text_span.dart';
......
...@@ -44,7 +44,7 @@ class FlexibleSpaceBar extends StatefulWidget { ...@@ -44,7 +44,7 @@ class FlexibleSpaceBar extends StatefulWidget {
/// Shown behind the [title] when expanded. /// Shown behind the [title] when expanded.
/// ///
/// Typically an [AssetImage] widget with [AssetImage.fit] set to [ImageFit.cover]. /// Typically an [AssetImage] widget with [AssetImage.fit] set to [BoxFit.cover].
final Widget background; final Widget background;
/// Whether the title should be centered. /// Whether the title should be centered.
......
...@@ -71,7 +71,7 @@ class ImageIcon extends StatelessWidget { ...@@ -71,7 +71,7 @@ class ImageIcon extends StatelessWidget {
width: iconSize, width: iconSize,
height: iconSize, height: iconSize,
color: iconColor, color: iconColor,
fit: ImageFit.scaleDown, fit: BoxFit.scaleDown,
alignment: FractionalOffset.center alignment: FractionalOffset.center
); );
} }
......
...@@ -6,41 +6,43 @@ import 'dart:math' as math; ...@@ -6,41 +6,43 @@ import 'dart:math' as math;
import 'basic_types.dart'; import 'basic_types.dart';
/// How an image should be inscribed into a box. /// How a box should be inscribed into another box.
/// ///
/// See also [applyImageFit], which applies the sizing semantics of these values /// See also [applyBoxFit], which applies the sizing semantics of these values
/// (though not the alignment semantics). /// (though not the alignment semantics).
enum ImageFit { enum BoxFit {
/// Fill the box by distorting the image's aspect ratio. /// Fill the target box by distorting the source's aspect ratio.
fill, fill,
/// As large as possible while still containing the image entirely within the box. /// As large as possible while still containing the source entirely within the
/// target box.
contain, contain,
/// As small as possible while still covering the entire box. /// As small as possible while still covering the entire target box.
cover, cover,
/// Make sure the full width of the image is shown, regardless of /// Make sure the full width of the source is shown, regardless of
/// whether this means the image overflows the box vertically. /// whether this means the source overflows the target box vertically.
fitWidth, fitWidth,
/// Make sure the full height of the image is shown, regardless of /// Make sure the full height of the source is shown, regardless of
/// whether this means the image overflows the box horizontally. /// whether this means the source overflows the target box horizontally.
fitHeight, fitHeight,
/// Center the image within the box and discard any portions of the image that /// Align the source within the target box (by default, centering) and discard
/// lie outside the box. /// any portions of the source that lie outside the box.
none, none,
/// Center the image within the box and, if necessary, scale the image down to /// Align the source within the target box (by default, centering) and, if
/// ensure that the image fits within the box. /// necessary, scale the source down to ensure that the source fits within the
/// box.
scaleDown scaleDown
} }
/// The pair of sizes returned by [applyImageFit]. /// The pair of sizes returned by [applyBoxFit].
class FittedSizes { class FittedSizes {
/// Creates an object to store a pair of sizes, /// Creates an object to store a pair of sizes,
/// as would be returned by [applyImageFit]. /// as would be returned by [applyBoxFit].
const FittedSizes(this.source, this.destination); const FittedSizes(this.source, this.destination);
/// The size of the part of the input to show on the output. /// The size of the part of the input to show on the output.
...@@ -50,62 +52,62 @@ class FittedSizes { ...@@ -50,62 +52,62 @@ class FittedSizes {
final Size destination; final Size destination;
} }
/// Apply an [ImageFit] value. /// Apply an [BoxFit] value.
/// ///
/// The arguments to this method, in addition to the [ImageFit] value to apply, /// The arguments to this method, in addition to the [BoxFit] value to apply,
/// are two sizes, ostensibly the sizes of an input image and an output canvas. /// are two sizes, ostensibly the sizes of an input box and an output box.
/// Specifically, the `inputSize` argument gives the size of the complete image /// Specifically, the `inputSize` argument gives the size of the complete source
/// that is being fitted, and the `outputSize` gives the size of the rectangle /// that is being fitted, and the `outputSize` gives the size of the rectangle
/// into which the image is to be drawn. /// into which the source is to be drawn.
/// ///
/// This function then returns two sizes, combined into a single [FittedSizes] /// This function then returns two sizes, combined into a single [FittedSizes]
/// object. /// object.
/// ///
/// The [FittedSizes.source] size is the subpart of the `inputSize` that is to /// The [FittedSizes.source] size is the subpart of the `inputSize` that is to
/// be shown. If the entire input image is shown, then this will equal the /// be shown. If the entire input source is shown, then this will equal the
/// `inputSize`, but if the input image is to be cropped down, this may be /// `inputSize`, but if the input source is to be cropped down, this may be
/// smaller. /// smaller.
/// ///
/// The [FittedSizes.destination] size is the subpart of the `outputSize` in /// The [FittedSizes.destination] size is the subpart of the `outputSize` in
/// which to paint the (possibly cropped) input image. If the /// which to paint the (possibly cropped) source. If the
/// [FittedSizes.destination] size is smaller than the `outputSize` then the /// [FittedSizes.destination] size is smaller than the `outputSize` then the
/// input image is being letterboxed (or pillarboxed). /// source is being letterboxed (or pillarboxed).
/// ///
/// This method does not express an opinion regarding the alignment of the /// This method does not express an opinion regarding the alignment of the
/// source and destination sizes within the input and output rectangles. /// source and destination sizes within the input and output rectangles.
/// Typically they are centered (this is what [BoxDecoration] does, for /// Typically they are centered (this is what [BoxDecoration] does, for
/// instance, and is how [ImageFit] is defined). The [FractionalOffset] class /// instance, and is how [BoxFit] is defined). The [FractionalOffset] class
/// provides a convenience function, [FractionalOffset.inscribe], for resolving /// provides a convenience function, [FractionalOffset.inscribe], for resolving
/// the sizes to rects, as shown in the example below. /// the sizes to rects, as shown in the example below.
/// ///
/// == Example == /// == Example ==
/// ///
/// This example paints an [Image] `image` onto the [Rect] `outputRect` on a /// This example paints an [Image] `image` onto the [Rect] `outputRect` on a
/// [Canvas] `canvas`, using a [Paint] paint, applying the [ImageFit] algorithm /// [Canvas] `canvas`, using a [Paint] paint, applying the [BoxFit] algorithm
/// `fit`: /// `fit`:
/// ///
/// ```dart /// ```dart
/// final Size imageSize = new Size(image.width.toDouble(), image.height.toDouble()); /// final Size imageSize = new Size(image.width.toDouble(), image.height.toDouble());
/// final FittedSizes sizes = applyImageFit(fit, imageSize, outputRect.size); /// final FittedSizes sizes = applyBoxFit(fit, imageSize, outputRect.size);
/// final Rect inputSubrect = FractionalOffset.center.inscribe(sizes.source, Point.origin & imageSize); /// final Rect inputSubrect = FractionalOffset.center.inscribe(sizes.source, Point.origin & imageSize);
/// final Rect outputSubrect = FractionalOffset.center.inscribe(sizes.destination, outputRect); /// final Rect outputSubrect = FractionalOffset.center.inscribe(sizes.destination, outputRect);
/// canvas.drawImageRect(image, inputSubrect, outputSubrect, paint); /// canvas.drawImageRect(image, inputSubrect, outputSubrect, paint);
/// ``` /// ```
FittedSizes applyImageFit(ImageFit fit, Size inputSize, Size outputSize) { FittedSizes applyBoxFit(BoxFit fit, Size inputSize, Size outputSize) {
Size sourceSize, destinationSize; Size sourceSize, destinationSize;
switch (fit) { switch (fit) {
case ImageFit.fill: case BoxFit.fill:
sourceSize = inputSize; sourceSize = inputSize;
destinationSize = outputSize; destinationSize = outputSize;
break; break;
case ImageFit.contain: case BoxFit.contain:
sourceSize = inputSize; sourceSize = inputSize;
if (outputSize.width / outputSize.height > sourceSize.width / sourceSize.height) if (outputSize.width / outputSize.height > sourceSize.width / sourceSize.height)
destinationSize = new Size(sourceSize.width * outputSize.height / sourceSize.height, outputSize.height); destinationSize = new Size(sourceSize.width * outputSize.height / sourceSize.height, outputSize.height);
else else
destinationSize = new Size(outputSize.width, sourceSize.height * outputSize.width / sourceSize.width); destinationSize = new Size(outputSize.width, sourceSize.height * outputSize.width / sourceSize.width);
break; break;
case ImageFit.cover: case BoxFit.cover:
if (outputSize.width / outputSize.height > inputSize.width / inputSize.height) { if (outputSize.width / outputSize.height > inputSize.width / inputSize.height) {
sourceSize = new Size(inputSize.width, inputSize.width * outputSize.height / outputSize.width); sourceSize = new Size(inputSize.width, inputSize.width * outputSize.height / outputSize.width);
} else { } else {
...@@ -113,20 +115,20 @@ FittedSizes applyImageFit(ImageFit fit, Size inputSize, Size outputSize) { ...@@ -113,20 +115,20 @@ FittedSizes applyImageFit(ImageFit fit, Size inputSize, Size outputSize) {
} }
destinationSize = outputSize; destinationSize = outputSize;
break; break;
case ImageFit.fitWidth: case BoxFit.fitWidth:
sourceSize = new Size(inputSize.width, inputSize.width * outputSize.height / outputSize.width); sourceSize = new Size(inputSize.width, inputSize.width * outputSize.height / outputSize.width);
destinationSize = new Size(outputSize.width, sourceSize.height * outputSize.width / sourceSize.width); destinationSize = new Size(outputSize.width, sourceSize.height * outputSize.width / sourceSize.width);
break; break;
case ImageFit.fitHeight: case BoxFit.fitHeight:
sourceSize = new Size(inputSize.height * outputSize.width / outputSize.height, inputSize.height); sourceSize = new Size(inputSize.height * outputSize.width / outputSize.height, inputSize.height);
destinationSize = new Size(sourceSize.width * outputSize.height / sourceSize.height, outputSize.height); destinationSize = new Size(sourceSize.width * outputSize.height / sourceSize.height, outputSize.height);
break; break;
case ImageFit.none: case BoxFit.none:
sourceSize = new Size(math.min(inputSize.width, outputSize.width), sourceSize = new Size(math.min(inputSize.width, outputSize.width),
math.min(inputSize.height, outputSize.height)); math.min(inputSize.height, outputSize.height));
destinationSize = sourceSize; destinationSize = sourceSize;
break; break;
case ImageFit.scaleDown: case BoxFit.scaleDown:
sourceSize = inputSize; sourceSize = inputSize;
destinationSize = inputSize; destinationSize = inputSize;
final double aspectRatio = inputSize.width / inputSize.height; final double aspectRatio = inputSize.width / inputSize.height;
......
...@@ -9,10 +9,10 @@ import 'package:flutter/foundation.dart'; ...@@ -9,10 +9,10 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'basic_types.dart'; import 'basic_types.dart';
import 'box_fit.dart';
import 'decoration.dart'; import 'decoration.dart';
import 'edge_insets.dart'; import 'edge_insets.dart';
import 'fractional_offset.dart'; import 'fractional_offset.dart';
import 'image_fit.dart';
export 'edge_insets.dart' show EdgeInsets; export 'edge_insets.dart' show EdgeInsets;
...@@ -894,7 +894,7 @@ void paintImage({ ...@@ -894,7 +894,7 @@ void paintImage({
@required Rect rect, @required Rect rect,
@required ui.Image image, @required ui.Image image,
ColorFilter colorFilter, ColorFilter colorFilter,
ImageFit fit, BoxFit fit,
ImageRepeat repeat: ImageRepeat.noRepeat, ImageRepeat repeat: ImageRepeat.noRepeat,
Rect centerSlice, Rect centerSlice,
FractionalOffset alignment FractionalOffset alignment
...@@ -912,9 +912,9 @@ void paintImage({ ...@@ -912,9 +912,9 @@ void paintImage({
outputSize -= sliceBorder; outputSize -= sliceBorder;
inputSize -= sliceBorder; inputSize -= sliceBorder;
} }
fit ??= centerSlice == null ? ImageFit.scaleDown : ImageFit.fill; fit ??= centerSlice == null ? BoxFit.scaleDown : BoxFit.fill;
assert(centerSlice == null || (fit != ImageFit.none && fit != ImageFit.cover)); assert(centerSlice == null || (fit != BoxFit.none && fit != BoxFit.cover));
final FittedSizes fittedSizes = applyImageFit(fit, inputSize, outputSize); final FittedSizes fittedSizes = applyBoxFit(fit, inputSize, outputSize);
final Size sourceSize = fittedSizes.source; final Size sourceSize = fittedSizes.source;
Size destinationSize = fittedSizes.destination; Size destinationSize = fittedSizes.destination;
if (centerSlice != null) { if (centerSlice != null) {
...@@ -984,7 +984,7 @@ class BackgroundImage { ...@@ -984,7 +984,7 @@ class BackgroundImage {
/// ///
/// The default varies based on the other fields. See the discussion at /// The default varies based on the other fields. See the discussion at
/// [paintImage]. /// [paintImage].
final ImageFit fit; final BoxFit fit;
/// How to paint any portions of the box not covered by the background image. /// How to paint any portions of the box not covered by the background image.
final ImageRepeat repeat; final ImageRepeat repeat;
......
...@@ -9,9 +9,9 @@ import 'dart:ui' as ui show Gradient, TextBox, lerpDouble; ...@@ -9,9 +9,9 @@ import 'dart:ui' as ui show Gradient, TextBox, lerpDouble;
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'basic_types.dart'; import 'basic_types.dart';
import 'box_fit.dart';
import 'decoration.dart'; import 'decoration.dart';
import 'fractional_offset.dart'; import 'fractional_offset.dart';
import 'image_fit.dart';
import 'text_editing.dart'; import 'text_editing.dart';
import 'text_painter.dart'; import 'text_painter.dart';
import 'text_span.dart'; import 'text_span.dart';
...@@ -395,7 +395,7 @@ class _FlutterLogoPainter extends BoxPainter { ...@@ -395,7 +395,7 @@ class _FlutterLogoPainter extends BoxPainter {
// only the mark // only the mark
logoSize = const Size(202.0, 202.0); logoSize = const Size(202.0, 202.0);
} }
final FittedSizes fittedSize = applyImageFit(ImageFit.contain, logoSize, canvasSize); final FittedSizes fittedSize = applyBoxFit(BoxFit.contain, logoSize, canvasSize);
assert(fittedSize.source == logoSize); assert(fittedSize.source == logoSize);
final Rect rect = FractionalOffset.center.inscribe(fittedSize.destination, offset & canvasSize); final Rect rect = FractionalOffset.center.inscribe(fittedSize.destination, offset & canvasSize);
final double centerSquareHeight = canvasSize.shortestSide; final double centerSquareHeight = canvasSize.shortestSide;
......
...@@ -8,7 +8,7 @@ import 'box.dart'; ...@@ -8,7 +8,7 @@ import 'box.dart';
import 'object.dart'; import 'object.dart';
export 'package:flutter/painting.dart' show export 'package:flutter/painting.dart' show
ImageFit, BoxFit,
ImageRepeat; ImageRepeat;
/// An image in the render tree. /// An image in the render tree.
...@@ -26,7 +26,7 @@ class RenderImage extends RenderBox { ...@@ -26,7 +26,7 @@ class RenderImage extends RenderBox {
double height, double height,
double scale: 1.0, double scale: 1.0,
Color color, Color color,
ImageFit fit, BoxFit fit,
FractionalOffset alignment, FractionalOffset alignment,
ImageRepeat repeat: ImageRepeat.noRepeat, ImageRepeat repeat: ImageRepeat.noRepeat,
Rect centerSlice Rect centerSlice
...@@ -118,9 +118,9 @@ class RenderImage extends RenderBox { ...@@ -118,9 +118,9 @@ class RenderImage extends RenderBox {
/// ///
/// The default varies based on the other fields. See the discussion at /// The default varies based on the other fields. See the discussion at
/// [paintImage]. /// [paintImage].
ImageFit get fit => _fit; BoxFit get fit => _fit;
ImageFit _fit; BoxFit _fit;
set fit(ImageFit value) { set fit(BoxFit value) {
if (value == _fit) if (value == _fit)
return; return;
_fit = value; _fit = value;
......
...@@ -1597,7 +1597,7 @@ class RenderFittedBox extends RenderProxyBox { ...@@ -1597,7 +1597,7 @@ class RenderFittedBox extends RenderProxyBox {
/// The [fit] and [alignment] arguments must not be null. /// The [fit] and [alignment] arguments must not be null.
RenderFittedBox({ RenderFittedBox({
RenderBox child, RenderBox child,
ImageFit fit: ImageFit.contain, BoxFit fit: BoxFit.contain,
FractionalOffset alignment: FractionalOffset.center FractionalOffset alignment: FractionalOffset.center
}) : _fit = fit, _alignment = alignment, super(child) { }) : _fit = fit, _alignment = alignment, super(child) {
assert(fit != null); assert(fit != null);
...@@ -1605,9 +1605,9 @@ class RenderFittedBox extends RenderProxyBox { ...@@ -1605,9 +1605,9 @@ class RenderFittedBox extends RenderProxyBox {
} }
/// How to inscribe the child into the space allocated during layout. /// How to inscribe the child into the space allocated during layout.
ImageFit get fit => _fit; BoxFit get fit => _fit;
ImageFit _fit; BoxFit _fit;
set fit(ImageFit value) { set fit(BoxFit value) {
assert(value != null); assert(value != null);
if (_fit == value) if (_fit == value)
return; return;
...@@ -1660,7 +1660,7 @@ class RenderFittedBox extends RenderProxyBox { ...@@ -1660,7 +1660,7 @@ class RenderFittedBox extends RenderProxyBox {
_transform = new Matrix4.identity(); _transform = new Matrix4.identity();
} else { } else {
final Size childSize = child.size; final Size childSize = child.size;
final FittedSizes sizes = applyImageFit(_fit, childSize, size); final FittedSizes sizes = applyBoxFit(_fit, childSize, size);
final double scaleX = sizes.destination.width / sizes.source.width; final double scaleX = sizes.destination.width / sizes.source.width;
final double scaleY = sizes.destination.height / sizes.source.height; final double scaleY = sizes.destination.height / sizes.source.height;
final Rect sourceRect = _alignment.inscribe(sizes.source, Point.origin & childSize); final Rect sourceRect = _alignment.inscribe(sizes.source, Point.origin & childSize);
......
...@@ -554,7 +554,7 @@ class FittedBox extends SingleChildRenderObjectWidget { ...@@ -554,7 +554,7 @@ class FittedBox extends SingleChildRenderObjectWidget {
/// The [fit] and [alignment] arguments must not be null. /// The [fit] and [alignment] arguments must not be null.
FittedBox({ FittedBox({
Key key, Key key,
this.fit: ImageFit.contain, this.fit: BoxFit.contain,
this.alignment: FractionalOffset.center, this.alignment: FractionalOffset.center,
Widget child Widget child
}) : super(key: key, child: child) { }) : super(key: key, child: child) {
...@@ -563,7 +563,7 @@ class FittedBox extends SingleChildRenderObjectWidget { ...@@ -563,7 +563,7 @@ class FittedBox extends SingleChildRenderObjectWidget {
} }
/// How to inscribe the child into the space allocated during layout. /// How to inscribe the child into the space allocated during layout.
final ImageFit fit; final BoxFit fit;
/// How to align the child within its parent's bounds. /// How to align the child within its parent's bounds.
/// ///
...@@ -2489,7 +2489,7 @@ class RawImage extends LeafRenderObjectWidget { ...@@ -2489,7 +2489,7 @@ class RawImage extends LeafRenderObjectWidget {
/// ///
/// The default varies based on the other fields. See the discussion at /// The default varies based on the other fields. See the discussion at
/// [paintImage]. /// [paintImage].
final ImageFit fit; final BoxFit fit;
/// How to align the image within its bounds. /// How to align the image within its bounds.
/// ///
......
...@@ -163,7 +163,7 @@ class Image extends StatefulWidget { ...@@ -163,7 +163,7 @@ class Image extends StatefulWidget {
/// ///
/// The default varies based on the other fields. See the discussion at /// The default varies based on the other fields. See the discussion at
/// [paintImage]. /// [paintImage].
final ImageFit fit; final BoxFit fit;
/// How to align the image within its bounds. /// How to align the image within its bounds.
/// ///
......
...@@ -10,19 +10,19 @@ void main() { ...@@ -10,19 +10,19 @@ void main() {
test('applyImageFit', () { test('applyImageFit', () {
FittedSizes result; FittedSizes result;
result = applyImageFit(ImageFit.scaleDown, const Size(100.0, 1000.0), const Size(200.0, 2000.0)); result = applyBoxFit(BoxFit.scaleDown, const Size(100.0, 1000.0), const Size(200.0, 2000.0));
expect(result.source, equals(const Size(100.0, 1000.0))); expect(result.source, equals(const Size(100.0, 1000.0)));
expect(result.destination, equals(const Size(100.0, 1000.0))); expect(result.destination, equals(const Size(100.0, 1000.0)));
result = applyImageFit(ImageFit.scaleDown, const Size(300.0, 3000.0), const Size(200.0, 2000.0)); result = applyBoxFit(BoxFit.scaleDown, const Size(300.0, 3000.0), const Size(200.0, 2000.0));
expect(result.source, equals(const Size(300.0, 3000.0))); expect(result.source, equals(const Size(300.0, 3000.0)));
expect(result.destination, equals(const Size(200.0, 2000.0))); expect(result.destination, equals(const Size(200.0, 2000.0)));
result = applyImageFit(ImageFit.fitWidth, const Size(2000.0, 400.0), const Size(1000.0, 100.0)); result = applyBoxFit(BoxFit.fitWidth, const Size(2000.0, 400.0), const Size(1000.0, 100.0));
expect(result.source, equals(const Size(2000.0, 200.0))); expect(result.source, equals(const Size(2000.0, 200.0)));
expect(result.destination, equals(const Size(1000.0, 100.0))); expect(result.destination, equals(const Size(1000.0, 100.0)));
result = applyImageFit(ImageFit.fitHeight, const Size(400.0, 2000.0), const Size(100.0, 1000.0)); result = applyBoxFit(BoxFit.fitHeight, const Size(400.0, 2000.0), const Size(100.0, 1000.0));
expect(result.source, equals(const Size(200.0, 2000.0))); expect(result.source, equals(const Size(200.0, 2000.0)));
expect(result.destination, equals(const Size(100.0, 1000.0))); expect(result.destination, equals(const Size(100.0, 1000.0)));
}); });
......
...@@ -38,7 +38,7 @@ void main() { ...@@ -38,7 +38,7 @@ void main() {
canvas: canvas, canvas: canvas,
rect: new Rect.fromLTWH(50.0, 75.0, 200.0, 100.0), rect: new Rect.fromLTWH(50.0, 75.0, 200.0, 100.0),
image: image, image: image,
fit: ImageFit.cover, fit: BoxFit.cover,
alignment: const FractionalOffset(0.0, 0.5) alignment: const FractionalOffset(0.0, 0.5)
); );
......
...@@ -88,7 +88,7 @@ void main() { ...@@ -88,7 +88,7 @@ void main() {
height: 200.0, height: 200.0,
child: new FittedBox( child: new FittedBox(
key: outside, key: outside,
fit: ImageFit.cover, fit: BoxFit.cover,
child: new Container( child: new Container(
key: inside, key: inside,
width: 100.0, width: 100.0,
......
...@@ -124,7 +124,7 @@ Widget buildImageAtRatio(String image, Key key, double ratio, bool inferSize) { ...@@ -124,7 +124,7 @@ Widget buildImageAtRatio(String image, Key key, double ratio, bool inferSize) {
image: new TestAssetImage(image), image: new TestAssetImage(image),
height: imageSize, height: imageSize,
width: imageSize, width: imageSize,
fit: ImageFit.fill fit: BoxFit.fill
) )
) )
) )
......
...@@ -772,7 +772,7 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { ...@@ -772,7 +772,7 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
/// A [ViewConfiguration] that pretends the display is of a particular size. The /// A [ViewConfiguration] that pretends the display is of a particular size. The
/// size is in logical pixels. The resulting ViewConfiguration maps the given /// size is in logical pixels. The resulting ViewConfiguration maps the given
/// size onto the actual display using the [ImageFit.contain] algorithm. /// size onto the actual display using the [BoxFit.contain] algorithm.
class TestViewConfiguration extends ViewConfiguration { class TestViewConfiguration extends ViewConfiguration {
/// Creates a [TestViewConfiguration] with the given size. Defaults to 800x600. /// Creates a [TestViewConfiguration] with the given size. Defaults to 800x600.
TestViewConfiguration({ Size size: _kDefaultTestViewportSize }) TestViewConfiguration({ Size size: _kDefaultTestViewportSize })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment