To get the size / position of the widget on the screen, you can use GlobalKey to get its BuildContext , then find the RenderBox that particular widget that will contain its global position and render size.
Only one thing to be careful: this context may not exist if the widget is not displayed. Which can cause problems with ListView, because widgets are displayed only if they are potentially visible.
Another problem is that you cannot get the RenderBox widget during the build call, as the widget has not been processed yet.
But I need assembly size! What can I do?
There is one cool widget that can help: Overlay and its OverlayEntry . They are used to display widgets on top of everything else (similar to the stack).
But the coolest thing is that they are in another build thread; they are built after ordinary widgets.
This has one very cool meaning: OverlayEntry can have a size that depends on the widgets of the real widget tree.
Good. But doesn't OverlayEntry need to be rebuilt manually?
Yes they do. But there is one more thing to be aware of: the ScrollController passed to Scrollable is similar to the AnimationController listening text.
This means that you can combine AnimatedBuilder with a ScrollController , this will have a great effect to automatically rebuild your widget on a scroll. perfect for this situation, right?
Combine everything into an example:
In the following example, you will see an overlay that follows the widget inside the ListView and has the same height.
import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; class MyHomePage extends StatefulWidget { const MyHomePage({Key key, this.title}) : super(key: key); final String title; @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { final controller = ScrollController(); OverlayEntry sticky; GlobalKey stickyKey = GlobalKey(); @override void initState() { if (sticky != null) { sticky.remove(); } sticky = OverlayEntry( opaque: false,