Flutter MenuAnchor throws "BoxConstraints forces an infinite width" - Stack Overflow

admin2025-04-17  2

Its happening right at my MenuAnchor:

The relevant error-causing widget was:
    MenuAnchor MenuAnchor

I've seen this error many times, usually means that a height or width is missing. I tried wrapping my MenuAnchor with a SizedBox with a height and width and I tried wrapping the menuChildren with a SizedBox with a height and width and neither fixes the issue. The MenuAnchor is inside of a Column.

Widget build(BuildContext context) {
    return ValueListenableBuilder(
      valueListenable: controller,
      builder: (context, selectedKeys, child) {
        return MenuAnchor(
          controller: controller.menuController,
          alignmentOffset: const Offset(10, 5),
          style: MenuStyle(
            shape: const WidgetStatePropertyAll(LinearBorder()),
            padding: const WidgetStatePropertyAll(EdgeInsets.zero),
            maximumSize: WidgetStatePropertyAll(Size.fromHeight(MediaQuery.of(context).size.height - kToolbarHeight - MediaQuery.of(context).padding.vertical)),
          ),
          key: key,
          menuChildren: [
            ...options.map<Widget>(
              (option) => _DropdownItem<T>(
                selected: controller.isSelected(option.key),
                itemKey: option.key,
                title: option.title,
                onChanged: (key) {
                  controller.toggle(key);
                  onChanged(controller.value);
                },
                showCheckbox: showCheckbox,
              ),
            ),
转载请注明原文地址:http://anycun.com/QandA/1744843035a88390.html