Skip to content

Instantly share code, notes, and snippets.

@CaiJingLong
Created November 28, 2018 13:42
Show Gist options
  • Save CaiJingLong/1bcab40f5d4af4affce41fb86f1a238b to your computer and use it in GitHub Desktop.
Save CaiJingLong/1bcab40f5d4af4affce41fb86f1a238b to your computer and use it in GitHub Desktop.
ui_helper
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