搜索插件、代码仓与 APP 分类

插件详情v2.0.2

render_metrics

用于获取小部件度量的库。使用 RenderObject 获取相对于屏幕窗口的小部件大小和位置,以及小部件之间的差异。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
511
喜欢数
122
Pub 分数
150

安装插件

flutter pub add render_metrics

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

render_metrics 包提供了一种方法,用于在 Flutter 应用程序中获取小部件的精确布局度量。通过利用 RenderObject,它使开发者能够获取小部件的准确大小和屏幕位置数据,以及测量小部件状态之间的差异。这对于调试布局问题、实现自定义动画或创建与特定 UI 组件对齐的叠加元素特别有用。该库支持所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。

适合场景

  • 调试小部件位置
  • 创建动态叠加层
  • 测量布局变化
  • 实现自定义动画
  • 分析UI性能

主要特点

  • 访问控件大小和屏幕位置
  • 随时间变化的 widget 度量比较
  • 跨平台兼容性
  • 与 RenderObject 的集成
  • 轻量且专注的 API

适合对象

  • UI 调试工具
  • 自定义布局工具
  • 动画框架
  • 开发者工具
  • 性能分析

使用建议

  • 需要访问 RenderObject 上下文
  • 如果过度使用,可能会影响性能
  • 不适用于高频场景下的运行时度量
  • 渲染期间仅限可见小部件

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Render Metrics

Made by Surf 🏄‍♂️🏄‍♂️🏄‍♂️

Build Status Coverage Status Pub Version Pub Likes Pub popularity Flutter Platform

Overview

This package helps retrieve the current positioning coordinates of any widget in a widgets tree in your Flutter application.

Currently supported features

  • Retrieve the full set of positioning coordinates of the desired widget at any time;
  • Calculate the difference in positioning between two widgets and use it the way you need.

Example

Getting widget's coordinates

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

final renderManager = RenderParametersManager<dynamic>();

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

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

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

RenderData data = renderManager.getRenderData("uniqueWidgetId");
Calculating the difference in positioning between two widgets

Wrap the widgets you want to compare in RenderMetricsObjects. Specify two different ids for each of them. Please note, that the manager parameter of both widgets should contain the 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 using the getDiffById() function and extract a bundle with the relative difference in positioning coordinates between the widgets.

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

What metrics can I get?

RenderData

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

All metrics positioning coordinates are global, meaning they are relative to the entire screen coordinate space.

RenderData

RenderData also provides you an ability to get all widget keypoint XY-coordinates by calling one of special getters.

RenderData

ComparisonDiff

You can get the comparison relative results for each widget keypoint from the ComparisonDiff instance.

An additional set of special getters can help you calculate the difference between two adjacent sides of two different widgets (e.g. right to left, top to bottom, etc.).

RenderData

Installation

Add render_metrics to your pubspec.yaml file:

dependencies:
  render_metrics: $currentVersion$

At this moment, the current version of render_metrics is render_metrics version.

Changelog

All notable changes to this project will be documented in this file.

Issues

To report your issues, submit them directly in the Issues section.

Contribute

If you would like to contribute to the package (e.g. by improving the documentation, fixing a bug or adding a cool new feature), please read our contribution guide first and send us your pull request.

Your PRs 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.

Telegram

License

Apache License, Version 2.0

所属分类

源码仓库

使用此插件的项目

暂无相关数据。