Skip to content

[vector_graphics] The documentation for height and width parameters is misleading #184116

Description

@eflat64

The documentation for the height and width parameters in the VectorGraphic widget states:

/// If specified, the width to use for the vector graphic. If unspecified,
/// the vector graphic will take the width of its parent.
final double? width;

/// If specified, the height to use for the vector graphic. If unspecified,
/// the vector graphic will take the height of its parent.
final double? height;

However, looking at the code this seems to be slightly misleading:

// If the caller did not specify a width or height, fall back to the
// size of the graphic.
// If the caller did specify a width or height, preserve the aspect ratio
// of the graphic and center it within that width and height.
double? width = widget.width;
double? height = widget.height;

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;
}

Im not saying that there is anything necessarily wrong with the current implementation, but that the documentation for width and height is a bit misleading. Knowing that omitting these parameters results in the widget using the graphic size rather than the size of the parent layout widget would have saved me a lot of time figuring out why the SVGs in my app were looking blurry.

Could I please suggest that the documentation is updated/clarified? Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: proposalA detailed proposal for a change to Flutterd: api docsIssues with https://api.flutter.dev/p: vector_graphicsThe vector_graphics package setpackageflutter/packages repository. See also p: labels.team-engineOwned by Engine team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions