Flutter 颤振下拉按钮弹出按钮下方200px

Flutter 颤振下拉按钮弹出按钮下方200px,flutter,dart,dropdownbutton,Flutter,Dart,Dropdownbutton,我在ListView中使用了一个带有自定义样式的下拉按钮。我的问题是:弹出菜单在按钮下方打开约200-300px,因此看起来像下面的按钮已打开: 我用自定义样式包装了下拉列表,但我已经尝试删除它,但没有任何效果。我也试着只用一个普通的下拉按钮,但效果是一样的。 相应的构建: @override Widget build(BuildContext context) { homeModel = Provider.of<HomeModel>(context); m

我在ListView中使用了一个带有自定义样式的下拉按钮。我的问题是:弹出菜单在按钮下方打开约200-300px,因此看起来像下面的按钮已打开:

我用自定义样式包装了下拉列表,但我已经尝试删除它,但没有任何效果。我也试着只用一个普通的下拉按钮,但效果是一样的。 相应的构建:

    @override
Widget build(BuildContext context) {
    homeModel = Provider.of<HomeModel>(context);
    model = Provider.of<TransferModel>(context);
    navigator = Navigator.of(context);
    var items = model.items.entries.toList();
    return Container(
      color: Colors.white,
      child: ListView.builder(
        physics: BouncingScrollPhysics(),
        itemCount: model.items.entries.length,
        itemBuilder: (BuildContext context, int index) {
              return Padding(
                padding: const EdgeInsets.only(left: 30, right: 30, top: 10),
                child: CustomDropDown(
                  errorText: "",
                  hint: items[index].value["label"],
                  items: items[index]
                      .value["items"]
                      .asMap()
                      .map((int i, str) => MapEntry(
                          i,
                          DropdownMenuItem(
                            value: i,
                            child: Text(str is Map
                                ? str["displayName"].toString()
                                : str.toString()),
                          )))
                      .values
                      .toList()
                      .cast<DropdownMenuItem<int>>(),
                  value: items[index].value["selected"],
                  onChanged: (position) =>
                      model.selectItem(items[index].key, position),
                ),
              );
        },
      ),
    );

  }

我已经用下面的代码试用了你的CustomDropDown小部件,它按照预期工作,没有在视图中显示较低的下拉列表。代码中的其他内容可能会影响其位置

class DropdownIssue extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _DropdownIssueState();
  }
}

class _DropdownIssueState extends State<DropdownIssue> {
  int currentValue = 0;

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        color: Colors.grey,
        child: Container(
          alignment: Alignment.center,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              CustomDropDown(
                hint: 'hint',
                errorText: '',
                value: currentValue,
                items: [
                  DropdownMenuItem(
                    value: 0,
                    child: Text('test 0'),
                  ),
                  DropdownMenuItem(
                    value: 1,
                    child: Text('test 1'),
                  ),
                  DropdownMenuItem(
                    value: 2,
                    child: Text('test 2'),
                  ),
                ].cast<DropdownMenuItem<int>>(),
                onChanged: (value) {
                  setState(() {
                    currentValue = value;
                  });
                  print('changed to $value');
                }
              ),
            ],
          ),
        )
      ),
    );
  }
}
class DropdownIssue扩展了StatefulWidget{
@凌驾
状态createState(){
返回_dropdownsissuestate();
}
}
类DropDownIssusEstate扩展状态{
int currentValue=0;
@凌驾
小部件构建(构建上下文){
返回中心(
子:容器(
颜色:颜色。灰色,
子:容器(
对齐:对齐.center,
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
自定义下拉列表(
提示:“提示”,
错误文本:“”,
值:当前值,
项目:[
下拉菜单项(
值:0,
子项:文本(“测试0”),
),
下拉菜单项(
价值:1,
子项:文本(“测试1”),
),
下拉菜单项(
价值:2,
子项:文本(“测试2”),
),
].cast(),
一旦更改:(值){
设置状态(){
当前值=当前值;
});
打印(“更改为$value”);
}
),
],
),
)
),
);
}
}

hmm,可能与它在列表视图中有关?不应该。ListView是关于多个子项的滚动行为。它不应该把你的内容推到特定的高度。如果看不到更多涉及的代码,就很难调试。看来你是对的,我在我周围的代码中尝试了你的代码,但它也有同样的问题。我会再调查一些。谢谢:)对不起,我不能给你一个解决方案。但是如果你更了解你周围的代码,我可以试着帮助你。我在上面添加了更多的代码,并缩小了罪魁祸首的范围。你找到解决问题的方法了吗?
  class ContentSheet extends StatelessWidget {
  final Widget child;
  final bool isMenuVisible;

  const ContentSheet({Key key, this.child, this.isMenuVisible}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.only(top: 50),
      child: AnimatedContainer(
        duration: Duration(milliseconds: 450),
        curve: Curves.elasticOut,
        padding: EdgeInsets.only(top: isMenuVisible ? 400 : 100),
        child: ClipRRect(
          borderRadius: BorderRadius.only(
              topLeft: Radius.circular(20), topRight: Radius.circular(20)),
          child: Container(
            decoration: BoxDecoration(
              borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(20), topRight: Radius.circular(20)),
              color: Colors.white,
            ),
            child: child
          ),
        ),
      ),
    );
  }
}
class DropdownIssue extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _DropdownIssueState();
  }
}

class _DropdownIssueState extends State<DropdownIssue> {
  int currentValue = 0;

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        color: Colors.grey,
        child: Container(
          alignment: Alignment.center,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              CustomDropDown(
                hint: 'hint',
                errorText: '',
                value: currentValue,
                items: [
                  DropdownMenuItem(
                    value: 0,
                    child: Text('test 0'),
                  ),
                  DropdownMenuItem(
                    value: 1,
                    child: Text('test 1'),
                  ),
                  DropdownMenuItem(
                    value: 2,
                    child: Text('test 2'),
                  ),
                ].cast<DropdownMenuItem<int>>(),
                onChanged: (value) {
                  setState(() {
                    currentValue = value;
                  });
                  print('changed to $value');
                }
              ),
            ],
          ),
        )
      ),
    );
  }
}