I know, How to get size/position of the widget. But question is If we want to get size/position of widget that will be shown after success of FutureBuilder
then how can we get?
For more clear:
I have below hierarchy of the widget.
- CustomScrollView
- SliverAppBar
- SliverToBoxAdapter
- SingleChildScrollView
- Column
- Container
// Covered full Scree
- Button
|| <-- based on button Click*//My own code*
Container
Child ~> null ORFutureBuilder
*//My own code*
This FutureBuilder covered under Container
widget. And I want to get
size/position of this Container
widget.
I did it but not proper way.
child: FutureBuilder<MealModelData>(
future: _futureForMealList,
builder:
(BuildContext context, AsyncSnapshot<MealModelData> snapshot) {
if (snapshot.data != null) {
MealModelData mealMdl = snapshot.data;
List<MealList> mealList = mealMdl.mealList;
if (mealMdl != null)
return ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: mealList.length,
itemBuilder: (BuildContext context, int index) {
if (index == mealList.length - 1 && !isGotPos{
isGotPos= true;
_callBackForGetTopPosition();
}
.
. .
. .
. .
. .
. .
And method code is:
_callBackForGetTopPosition() {
WidgetsBinding.instance.addPostFrameCallback((_) {
final RenderBox renderBoxRed =
_keyForListView.currentContext.findRenderObject();
final positionRed = renderBoxRed.localToGlobal(Offset.zero);
print('X = ${positionRed.dx} and Y = ${positionRed.dy}')
});
}
I found this one How to get a height of a Widget?
But can't able to declare SchedulerBinding.instance.....