Skip to content

Instantly share code, notes, and snippets.

@mg
Created February 6, 2019 16:56
Show Gist options
  • Select an option

  • Save mg/e7e6d7e6a57d818c067ca7c4d07a5e8f to your computer and use it in GitHub Desktop.

Select an option

Save mg/e7e6d7e6a57d818c067ca7c4d07a5e8f to your computer and use it in GitHub Desktop.

Revisions

  1. mg created this gist Feb 6, 2019.
    25 changes: 25 additions & 0 deletions getsize.dart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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);
    }
    }