How to get the height of the FloatingSearchBar widget? - flutter

Please, I want to get the height of the bar of FloatingSearchBar widget so I can adjust the top padding of the next widget to not go under the FloatingSearchBar!
for exemple this next image from my app :
Image from my APP
The form widget is after the FloatingSearchBar and not under it because I use a padding with a fixed chosen value!
I used this code
final fsb = FloatingSearchBar.of(context);
print(fsb);
But when I print "fsb" I get "null" value !!
Thanks in advance!

Related

How to get the height of the whole list.builder in flutter

I need to get the whole list.builder height including the part that is out of the screen view
The List children vary in height
i used the GlobalKey method but it is giving me only the height of the list shown in the screen
I found this solution and it's working and give me the full list.builder height after scrolling event
but when adding more children to the list.builder by changing the state
this code doesn't work anymore
scrollController.addListener(() {
double? fullListViewHeight;
double fullListHeightHelper = listKey.currentContext!.size!.height +
scrollController.position.extentAfter;
fullListView ??= fullListHeightHelper;
}
listview.builder only build the item that shown to user, in order to get the height with GlobalKey method, you can use listView which build all item at the same time. If you don't know how pass your list to listView , see this example:
List yourList = [...];
_buildList(){
List<Widget> _children =yourList.map((e) => YourListItem()).toList();
return ListView(
key:yourKey,
children: _children,
);
}
it is giving me only the height of the list shown in the screen
yes.. thats correct. because listview not render all the children. see the documentation of listview:
The ListView.builder ...constructor is appropriate for list views with
a large (or infinite) number of children because the builder is called
only for those children that are actually visible.
to get exact height of all children is impossible. since when the widget child is scrolled out of view, the associated element subtree, states and render objects are destroyed.
I think you need to calculate it manually or make the children height is same for all.
To calculate it, you need to make each item the same height. Then,
To get the height of the ListView.builder you simply multiply the height of each item by the length of the ListView.builder.

Animating Text widget content based on change of variable

How can I animate the change from a Text widget with a particular String to a new String which is dynamic, i.e., I don't know what it'll be beforehand ?
For example, let the widget be Text('a'). Later I want it to animate to Text('b'), maybe a after a button being clicked by a user.
Store the user input in a variable and display it in the Text widget. For example,
var input = value;
inside the widget you can use Text('$input') or directly Text(input) to display it

Flutter Center align widget to specific coordinate

Ive create a popup menu widget which takes two arguments :a button widget, and a menu widget . When the button is pressed the menu widget is passed to an OverlayEntry as the child which is then added to the Overlay.of(context)
I'd like the resulting display to be as such:
O (Button)
____|____
| MENU |
|_______|
I can place the menu widget inside a Positioned Widget to move it freely around the Overlay, but I dont know how to get the correct coordinates. I can get the center of the Button by finding it's Renderbox, but I cant know the size, and therefore the correct position, of the Menu until after it's draw (as it can be any widget).
Is there some soft of layout option to tell a Widget of any size to vertically or horzontally align itself with a given coordinate?
To get the size of a widget:
First give your Widget a key:
key: _key,
Then you can get the size(and position) like this:
_getSize() {
final RenderBox renderBox = _key.currentContext.findRenderObject();
final size = renderBox.size;
final position = renderBox.localToGlobal(Offset.zero);
final height = size.height; //same for width
}

Visibility widget not displayed in Flutter

If we have a Visibility widget on top of our screen and we click to display it at the end of our screen scrolling top manually, why still this hidden? Does this mean that we need to do something like this instead?:
showWidget == true ? Text("hi") : Container();
Because code above is failing as well.
Video of the error:
https://youtu.be/YQ7nZ3LAENo

How do I get the height and width of the Android Navigation Bar programmatically in flutter?

How do I get the height and width of this UI element in pixel?
Use this to get the bottom nav bar height
MediaQuery.of(context).viewInsets.bottom
The following works for me:
final double navigationBarHeight = MediaQuery.of(context).padding.bottom
If
final double navigationBarHeight = MediaQuery.of(context).padding.bottom
doesn't work, check if you are not calling this inside
SafeArea, a widget that consumes this padding with a Padding widget and automatically removes it from the MediaQuery for its child.