I am using SearchAnchor with a SearchBar, and I want the viewConstraints to dynamically adjust based on the number of items in viewBuilder.
Currently, my code looks like this:
SearchAnchor(
viewConstraints: BoxConstraints.loose(Size.fromHeight(200)),
builder: (context, controller) => SearchBar(
suggestionsBuilder: (_, __) => [],
viewBuilder: (suggestions) => Column(
children: List.generate(
some_number,
(int index) => ListTile(title: Text('$some_number')),
),
),
),
)
Problem: Right now, viewConstraints takes a fixed height (200), but I need it to take only as much space as needed for the number of rows returned by viewBuilder. Setting min and Maxheight also didn't work, it always takes the MaxHeight. Adding the Flexbile widget also didn't work.
Since I don’t know the number of elements beforehand (it's only available inside viewBuilder), I can't predefine a proper constraint.
How can I ensure viewConstraints automatically adjusts based on the number of items in viewBuilder, without using a fixed height?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745196669a4616125.html
评论列表(0条)