当前位置:网站首页>Flutter obtains the coordinate size of any element in the interface through globalkey
Flutter obtains the coordinate size of any element in the interface through globalkey
2022-06-28 23:12:00 【One leaf floating boat】
first :
The function of obtaining the coordinate size of any element on the screen is encountered in requirement development , The final implementation is as follows :
1. example:
//...
GlobalKey _globalKey = GlobalKey();
@override
Widget build(BuildContext context) {
//...
ElevatedButton.icon(
icon: Icon(Icons.send),
label: Text(" send out "),
// onPressed: () => ddlog('pressed'),
key: _globalKey,
onPressed: (){
// _showCustomPopView();
ddlog(_globalKey.position());// Offset(143.5, 117.0)
ddlog(_globalKey.size);// Size(88.0, 48.0)
},
),
//...
}
2. extension encapsulation :
import 'package:flutter/material.dart';
extension BuildContextExt on BuildContext {
/// Gets the... Of the current component RenderBox
RenderBox? renderBox() {
return this.findRenderObject() is RenderBox ? (this.findRenderObject() as RenderBox) : null;
}
/// Gets the... Of the current component position
Offset? position({Offset offset = Offset.zero}) {
return this.renderBox()?.localToGlobal(offset);
}
}
extension GlobalKeyExt on GlobalKey{
/// Gets the... Of the current component RenderBox
RenderBox? renderBox() => this.currentContext?.renderBox();
/// Gets the... Of the current component position
Offset? position({Offset offset = Offset.zero}) => this.currentContext?.position(offset: offset);
/// Gets the... Of the current component Size
Size? get size => this.currentContext?.size;
}边栏推荐
- flowable 边界定时器
- Fanuc robot_ Introduction to Karel programming (2)_ Usage of general IO signal
- LeetCode 324 摆动排序 II[排序 双指针] HERODING的LeetCode之路
- [matlab]函数定义与使用
- 在长投学堂开通证券账户是安全可靠的吗?
- Is it safe to open a stock account by mobile phone?
- Linq连表查询
- [flutter issues Series title 71] Mutual Conversion between uint8list and Image in flutter
- [matlab] function definition and use
- 2022-06-28:以下golang代码输出什么?A:true;B:false;C:panic;D:编译失败。 package main import “fm
猜你喜欢
![LeetCode 324 摆动排序 II[排序 双指针] HERODING的LeetCode之路](/img/41/b8ba8d771b7224eac1cc8c54fe9d29.png)
LeetCode 324 摆动排序 II[排序 双指针] HERODING的LeetCode之路

一张能卖上千万,商家扩张比玩家还快:球星卡的江湖你不懂
![[Chapter 2 of word tutorial series] how to set the table on each page to have a header in word](/img/1a/8416d2c48bf1ddcc45e0c5d9acf242.png)
[Chapter 2 of word tutorial series] how to set the table on each page to have a header in word

WEB API学习笔记1

LINQ linked table query

计数排序和排序的稳定性
![[deep learning] (3) encoder mechanism in transformer, complete pytoch code attached](/img/cb/d385bee7a229e8d11f5fa8af66311f.gif)
[deep learning] (3) encoder mechanism in transformer, complete pytoch code attached

2022年PMP项目管理考试敏捷知识点(4)

LeCun预言AGI:大模型和强化学习都是斜道!我的世界模型才是新路

机器学习4-降维技术
随机推荐
微搭低代码中实现二维码生成
Hit the industry directly | the flying propeller launched the industry's first model selection tool
小样本利器2.文本对抗+半监督 FGSM & VAT & FGM代码实现
Online linear programming: Dual convergence, new algorithms, and regret bounds
Flowable boundary timer
Is it safe and reliable for changtou school to help open a securities account? How to drive
在QT进行cin(全网最清晰教程)
第二章 经典同步练习作业
Differences among CPU, GPU, TPU and NPU
SqlServer复习
TDD and automated testing
Serious internal entanglement in the we media industry: where should the enterprise we media go
Prometeus 2.36.0 新特性
带链接跳转的微信红包封面制作教程和使用指南
Oil monkey script learning
Google Earth engine (GEE) -- crop extraction and analysis using sentinel-2 data
WEB API学习笔记1
Online linear programming: Dual convergence, new algorithms, and regret bounds
Business atlas in super factory
[数学建模]Matlab非线性规划之fmincon()函数