android - 为什么我的扩展磁贴扩展到整个屏幕

标签 android dart flutter

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

这是我描述的图片: Expansion tile just got expanded

Without expanded

代码如下:

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(),
          );
        }
      },
    );

我试过添加 shrinkwrap 看看是否可行。那没有。 此外,debug.output 只是一个显示打印消息的自定义函数,因此无需担心。如您所见,它是 future builder 中的 future builder 。我已经尝试将内部 future builder 分离到一个单独的有状态类并将一列返回到扩展磁贴,但这也没有用。

最佳答案

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

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

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

关于android - 为什么我的扩展磁贴扩展到整个屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56118709/

相关文章:

firebase - 如果电子邮件和密码在 firebase flutter 中无效,如何显示错误消息?

python - 如何在 python 中解码飞镖编码的 readAsBytesSync() 字符串

firebase - 如果保留为空,如何不将字段保存到Firebase

android - 在后台服务中覆盖音量按钮

android - 填充将字符串映射到 Android 中 XML 中的数字的 Spinner

android - 基于云的后端移动应用程序的优点和缺点是什么,例如。解析

dart - 为什么我不能使用Type变量作为泛型类的Type参数

flutter - 具有可重启变压器的 block 并发不会取消先前的事件

Flutter:我应该如何访问此删除请求中的响应正文?

android - 如何将 query() 与 WHERE 子句一起使用?