缩小 Flutter 下拉菜单

问题描述 投票:0回答:1

我正在尝试降低下拉菜单的高度,我已经尝试过这种方式:

SizedBox(
                    height: 30,
                    child: Container(
                      decoration: BoxDecoration(color: Colors.white),
                      child: DropdownMenu<String>(
                        // inputDecorationTheme: InputDecorationTheme(alignLabelWithHint: ),
                        
                        textStyle: TextStyle(fontSize: 10),
                        inputDecorationTheme: InputDecorationTheme(
                            isCollapsed: true
                        ),
                        dropdownMenuEntries: [
                          DropdownMenuEntry(value: "Name - First", label: "Name - First",
                              style: ButtonStyle(textStyle: MaterialStateTextStyle.resolveWith((states) => TextStyle(fontSize: 10) ))),
                        ],

                      ),
                    ),
                  ),

降低其高度但结果如下。如何轻松缩小下拉菜单?

DropdownManu Height change attempt

我原本希望将下拉菜单变小

flutter drop-down-menu height
1个回答
0
投票

您可以使用InputDecorationTheme中的

constraints
属性来控制下拉菜单的高度。

DropdownMenu<String>(
          dropdownMenuEntries: const [
            DropdownMenuEntry<String>(
              label: 'One',
              value: 'one',
            ),
            DropdownMenuEntry<String>(
              label: 'Two',
              value: 'two',
            ),
          ],
          hintText: 'Select',
          inputDecorationTheme: InputDecorationTheme(
            isDense: true,
            contentPadding: const EdgeInsets.symmetric(horizontal: 16),
            constraints: BoxConstraints.tight(const 
             Size.fromHeight(40)),
            border: OutlineInputBorder(
              borderRadius: BorderRadius.circular(8),
            ),
          ),
        )

确保相应地调整内容填充。

© www.soinside.com 2019 - 2024. All rights reserved.