【问题标题】:Why is my expansion tile expanding to the whole screen为什么我的扩展图块扩展到整个屏幕
【发布时间】:2019-05-13 19:26:10
【问题描述】:

当我使用未来的构建器扩展磁贴时,我正在尝试调用 api。它返回一个列表。但是,当我单击它时,它会扩大整个屏幕并且不显示任何内容。

这是我所描述的图像:

代码如下:

Widget build(BuildContext context) {
    return FutureBuilder(
      future: marketApiCall(),
      builder: (BuildContext context, AsyncSnapshot snapshot) {
        if (snapshot.connectionState == ConnectionState.done) {
          if(snapshot.hasData) {
            return ListView.separated(
              shrinkWrap: true,
              separatorBuilder: (BuildContext context, int index) => Divider(),
              itemCount: snapshot.data.length,
              itemBuilder: (BuildContext context, int count) {
                return ExpansionTile(
                  title: Text(snapshot.data[count].itemName),
                  children: <Widget>[
                     FutureBuilder(
                        future: getItemDetail(itemName: snapshot.data[count].urlName),
                        builder: (BuildContext context, AsyncSnapshot<List<dynamic>> snapshot) {
                          if(snapshot.connectionState == ConnectionState.done) {
                            if (snapshot.hasData){
                              debug.output(fromFunction:"Widget build", message: snapshot.data[0]['en']['description']);
                              return Container(
                                width: MediaQuery.of(context).size.width * 0.8,
                                height: MediaQuery.of(context).size.height * 0.8,
                                child: Column(
                                  mainAxisSize: MainAxisSize.min,
                                  children: <Widget>[
                                    Row(
                                      crossAxisAlignment: CrossAxisAlignment.start,
                                      children: <Widget>[
                                        Text("Item description: ", style: TextStyle(fontWeight: FontWeight.bold)),
                                        Expanded(
                                          child: Text(snapshot.data[0]['en']['description'].toString().replaceAll(reg, ''))
                                        )
                                      ],
                                    )
                                  ],
                                )                                  
                              );
                            } else {
                              return Center(
                                child: Text("Error: No data")
                              );
                            }           
                          } else {
                            return Center(
                              child: CircularProgressIndicator(),
                            );
                          }
                        }
                      )
                  ],
                );
              },
            );
          } else {
            return ListTile(
              title: Text("There was an error with the api call, please try again later")             
            );
          }
        } else {
          return Center(
            child: CircularProgressIndicator(),
          );
        }
      },
    );

我尝试添加收缩包装,看看是否可行。那没有。 此外,debug.output 只是一个显示打印消息的自定义函数,因此无需担心。如您所见,它是futurebuilder 中的futurebuilder。我尝试将内部的未来构建器分离到一个单独的有状态类并将一列返回到扩展磁贴,但这也不起作用。

【问题讨论】:

    标签: android dart flutter


    【解决方案1】:

    我认为问题就在“FutureBuilder”之后

    return Container(
           width: MediaQuery.of(context).size.width * 0.8,
           height: MediaQuery.of(context).size.height * 0.8,
    

    您为其子 Container 提供了屏幕高度的 80%,加上 ExpansionTile 的高度,它将占据整个屏幕(或几乎)。 尝试移除容器高度并让其子级调整容器大小。

    【讨论】:

    • 这听起来很可能,感谢您发现它。我会继续尝试实施您的建议
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-23
    • 1970-01-01
    • 1970-01-01
    • 2011-10-26
    相关资源
    最近更新 更多