Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/vector_graphics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT
## 1.1.20

* Updates minimum supported SDK version to Flutter 3.32/Dart 3.8.
* Respect BoxFit parameter when viewbox is specified.

## 1.1.19

Expand Down
2 changes: 1 addition & 1 deletion packages/vector_graphics/lib/src/listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import 'loader.dart';

const VectorGraphicsCodec _codec = VectorGraphicsCodec();

/// The deocded result of a vector graphics asset.
/// The decoded result of a vector graphics asset.
class PictureInfo {
/// Construct a new [PictureInfo].
PictureInfo._(this.picture, this.size);
Expand Down
57 changes: 27 additions & 30 deletions packages/vector_graphics/lib/src/vector_graphics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class _PictureKey {
}

class _VectorGraphicWidgetState extends State<VectorGraphic> {
_PictureData? _pictureInfo;
_PictureData? _pictureData;
Object? _error;
StackTrace? _stackTrace;
Locale? locale;
Expand Down Expand Up @@ -338,8 +338,8 @@ class _VectorGraphicWidgetState extends State<VectorGraphic> {

@override
void dispose() {
_maybeReleasePicture(_pictureInfo);
_pictureInfo = null;
_maybeReleasePicture(_pictureData);
_pictureData = null;
super.dispose();
}

Expand Down Expand Up @@ -407,8 +407,8 @@ class _VectorGraphicWidgetState extends State<VectorGraphic> {
if (data != null) {
data.count += 1;
setState(() {
_maybeReleasePicture(_pictureInfo);
_pictureInfo = data;
_maybeReleasePicture(_pictureData);
_pictureData = data;
});
return;
}
Expand All @@ -431,8 +431,8 @@ class _VectorGraphicWidgetState extends State<VectorGraphic> {
}

setState(() {
_maybeReleasePicture(_pictureInfo);
_pictureInfo = data;
_maybeReleasePicture(_pictureData);
_pictureData = data;
});
} catch (error, stackTrace) {
_handleError(error, stackTrace);
Expand All @@ -443,7 +443,7 @@ class _VectorGraphicWidgetState extends State<VectorGraphic> {

@override
Widget build(BuildContext context) {
final PictureInfo? pictureInfo = _pictureInfo?.pictureInfo;
final PictureInfo? pictureInfo = _pictureData?.pictureInfo;

Widget child;
if (pictureInfo != null) {
Expand All @@ -454,42 +454,39 @@ class _VectorGraphicWidgetState extends State<VectorGraphic> {
double? width = widget.width;
double? height = widget.height;

if (width == null && height == null) {
width = pictureInfo.size.width;
height = pictureInfo.size.height;
} else if (height != null && !pictureInfo.size.isEmpty) {
if (height != null && !pictureInfo.size.isEmpty) {
width = height / pictureInfo.size.height * pictureInfo.size.width;
} else if (width != null && !pictureInfo.size.isEmpty) {
height = width / pictureInfo.size.width * pictureInfo.size.height;
}

assert(width != null && height != null);

var scale = 1.0;
scale = math.min(
pictureInfo.size.width / width!,
pictureInfo.size.height / height!,
);
if (width != null && height != null) {
scale = math.min(
pictureInfo.size.width / width,
pictureInfo.size.height / height,
);
}

if (_webRenderObject) {
child = _RawWebVectorGraphicWidget(
pictureInfo: pictureInfo,
assetKey: _pictureInfo!.key,
assetKey: _pictureData!.key,
colorFilter: widget.colorFilter,
opacity: widget.opacity,
);
} else if (widget.strategy == RenderingStrategy.raster) {
child = _RawVectorGraphicWidget(
pictureInfo: pictureInfo,
assetKey: _pictureInfo!.key,
assetKey: _pictureData!.key,
colorFilter: widget.colorFilter,
opacity: widget.opacity,
scale: scale,
);
} else {
child = _RawPictureVectorGraphicWidget(
pictureInfo: pictureInfo,
assetKey: _pictureInfo!.key,
assetKey: _pictureData!.key,
colorFilter: widget.colorFilter,
opacity: widget.opacity,
);
Expand All @@ -507,16 +504,16 @@ class _VectorGraphicWidgetState extends State<VectorGraphic> {
}
}

child = SizedBox(
width: width,
height: height,
child: FittedBox(
fit: widget.fit,
alignment: widget.alignment,
clipBehavior: widget.clipBehavior,
child: SizedBox.fromSize(size: pictureInfo.size, child: child),
),
child = FittedBox(
fit: widget.fit,
alignment: widget.alignment,
clipBehavior: widget.clipBehavior,
child: SizedBox.fromSize(size: pictureInfo.size, child: child),
);

if (width != null && height != null) {
child = SizedBox(width: width, height: height, child: child);
}
} else if (_error != null && widget.errorBuilder != null) {
child = widget.errorBuilder!(
context,
Expand Down
2 changes: 1 addition & 1 deletion packages/vector_graphics/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: vector_graphics
description: A vector graphics rendering package for Flutter using a binary encoding.
repository: https://github.com/flutter/packages/tree/main/packages/vector_graphics
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+vector_graphics%22
version: 1.1.19
version: 1.1.20

environment:
sdk: ^3.8.0
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading