Created
November 28, 2018 13:42
-
-
Save CaiJingLong/1bcab40f5d4af4affce41fb86f1a238b to your computer and use it in GitHub Desktop.
ui_helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/widgets.dart'; | |
class UIHelper { | |
static Rect findGlobalRect(GlobalKey key) { | |
RenderBox renderObject = key.currentContext?.findRenderObject(); | |
if (renderObject == null) { | |
return null; | |
} | |
var globalOffset = renderObject?.localToGlobal(Offset.zero); | |
if (globalOffset == null) { | |
return null; | |
} | |
var bounds = renderObject.paintBounds; | |
bounds = bounds.translate(globalOffset.dx, globalOffset.dy); | |
return bounds; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment