Created
February 6, 2019 16:56
-
-
Save mg/e7e6d7e6a57d818c067ca7c4d07a5e8f to your computer and use it in GitHub Desktop.
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
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