render_metrics 1.0.2-dev.5
render_metrics: ^1.0.2-dev.5 copied to clipboard
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 #
This package is a part of SurfGear toolset made by Surf.
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 RenderMetricsObject
s. Specify two different id
s 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
Changelog #
All notable changes to this project will be documented in this file.
Issues #
For issues, file directly in the main SurfGear repo.
Contribute #
If you would like to contribute to the package (e.g. by improving the documentation, solving a bug or adding a cool new feature), please review our contribution guide first and send us your pull request.
You PR's are always welcome.
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.