render_metrics 1.0.2-dev.4 copy "render_metrics: ^1.0.2-dev.4" to clipboard
render_metrics: ^1.0.2-dev.4 copied to clipboard

outdated

Library for getting widget metrics. Uses RenderObject to get the size and position of widgets relative to the screen window, as well as the difference between widgets.

Render Metrics #

Pub Version Pub Version (including pre-releases) Pub Likes

This package is a part of SurfGear toolset made by Surf.

SurfGear

About #

This package gives you an ability to get the current positioning coordinates of any widget in a widgets tree in your Flutter application.

Currently supported features #

  • Get the full set of positioning coordinates of the desired widget at any time;
  • Calculate the difference between the positions of two different widgets and use it the way you want to.

Usage #

Getting widget's coordinates #

Instantiate RenderParametersManager object. You can declare a special type for the unique widget's identifier you will set the next step or you can leave it dynamic.

final renderManager = RenderParametersManager<dynamic>();

Wrap the desired widget in a RenderMetricsObject. The id parameter is a unique identifier for the widget.

RenderMetricsObject(
    id: "uniqueWidgetId",
    manager: renderManager,
    child: Container(
        ...
    ),
),

Get a bundle with the positioning coordinates of the wrapped widget.

RenderData data = renderManager.getRenderData("uniqueWidgetId");

Calculating two widgets positioning difference #

Wrap both widgets you want to compare in a RenderMetricsObjects. Specify two different ids for each of them. Please note, that the manager parameter of both widgets should accept a link to the same RenderParametersManager instance.

RenderMetricsObject(
    id: "rowWidgetId",
    manager: renderManager,
    child: Row(
        ...
    ),
),
RenderMetricsObject(
    id: "columnWidgetId",
    manager: renderManager,
    child: Column(
        ...
    ),
),

Specify two unique widget identifiers when calling getDiffById() function to extract a bundle with the relative difference between the positioning coordinates of comparing widgets.

ComparisonDiff diff =
    renderManager.getDiffById("rowWidgetId", "columnWidgetId");

What metrics can I get? #

RenderData instance contains a complete set of properties that characterize any widget in a two-dimensional space.

All metrics positioning coordinates are global (relative to the entire screen coordinate space).

Metrics Description
width Widget widgth
height Widget height
yTop Top Y position
yBottom Bottom Y position
yCenter Center Y position
xLeft Left X position
xRight Right X position
xCenter Center X position

Installation #

Add Render Metrics to your pubspec.yaml file:

dependencies:
  render_metrics: 1.0.1

Issues #

For issues, file directly in the main SurfGear repo.

How to reach us #

Please, feel free to ask any questions about this package. Join our community chat on Telegram. We speak English and Russian.

Telegram

License #

Apache License, Version 2.0

117
likes
0
pub points
85%
popularity

Publisher

verified publishersurf.ru

Library for getting widget metrics. Uses RenderObject to get the size and position of widgets relative to the screen window, as well as the difference between widgets.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, surf_lint_rules

More

Packages that depend on render_metrics