Skip to content

Instantly share code, notes, and snippets.

@mg
Created February 6, 2019 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mg/e7e6d7e6a57d818c067ca7c4d07a5e8f to your computer and use it in GitHub Desktop.
Save mg/e7e6d7e6a57d818c067ca7c4d07a5e8f to your computer and use it in GitHub Desktop.
class MyWidget extends StatefulWidget {
final GlobalKey myKey = GlobalKey();
MyWidget();
@override
State<StatefulWidget> createState() => MyWidgetState();
}
class MyWidgetState extends State<MyWidget> {
@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback(getSize);
super.initState();
}
void getSize(_) {
final RenderBox rbox = widget.myKey.currentContext.findRenderObject();
final size = rbox.size;
}
@override
Widget build(BuildContext context) {
return Container(key: widget.myKey);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment