最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论