flutter - How to make viewConstraints dynamically adjust to viewBuilder content in SearchAnchor? - Stack Overflow

I am using SearchAnchor with a SearchBar, and I want the viewConstraints to dynamically adjust based on

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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信