admin管理员组

文章数量:1415138

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?

本文标签: flutterHow to make viewConstraints dynamically adjust to viewBuilder content in SearchAnchorStack Overflow