我对Flutter 翼是个新手,我得到了一个我不能理解的例外.有谁能帮我一下吗?

我得到的例外是

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.
The ParentDataWidget Positioned(right: 0.0, bottom: 0.0) wants to apply ParentData of type
StackParentData to a RenderObject, which has been set up to accept ParentData of incompatible type
FlexParentData.
Usually, this means that the Positioned widget has the wrong ancestor RenderObjectWidget. Typically,
Positioned widgets are placed directly inside Stack widgets.
The offending Positioned is currently placed inside a Row widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
  Padding ← Container ← Positioned ← Row ← Stack ← RepaintBoundary ← IndexedSemantics ←
NotificationListener<KeepAliveNotification> ← KeepAlive ← AutomaticKeepAlive ← ⋯

我的代码片段如下

body: Container(
  padding: const EdgeInsets.only(top: 25, left: 16, right: 16),
  child: GestureDetector(
    onTap: () {
      FocusScope.of(context).unfocus();
    },
    child: ListView(
      children: [
        Stack(
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisSize: MainAxisSize.max,
              children: [
                Container(
                  width: 80,
                  height: 80,
                  margin: const EdgeInsets.only(left: 25),
                  decoration: BoxDecoration(
                    boxShadow: const [
                      BoxShadow(
                          spreadRadius: 2.0,
                          blurRadius: 10.0,
                          color: Colors.black,
                          offset: Offset(0, 10))
                    ],
                    shape: BoxShape.circle,
                    image: ...
                  ),
                ),
                Positioned(
                ...  
                ),
                Container(
                  margin: const EdgeInsets.only(left: 40.0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        "Naruto",
                        style: TextStyle(
                          color:
                              Theme.of(context).primaryColorLight,
                          fontSize: 20.0,
                        ),
                      ),
                      const SizedBox(
                        height: 5.0,
                      ),
                      Text(
                        "Loreum ipusm",
                        style: TextStyle(
                          color: Theme.of(context).primaryColor,
                          fontSize: 15.0,
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ],
        ),
        Container(
          ...
        ),
      ],
    ),
  ),
),

我知道这与嵌套错误的小部件有关.我不知道如何改变它,不知道哪些小部件嵌套错误,Ffltter为什么会对此抱怨.

如果需要更多的代码,请让我知道.

谢谢你的任何帮助.

推荐答案

它与定位的小部件相关.它应该直接放在堆栈中,而不是放在行中.试试下面这样的方法:

          Stack(
            children: [
              Positioned(
              child: ...
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisSize: MainAxisSize.max,
                children: [
                  Container(
                    width: 80,
                    height: 80,
                    margin: const EdgeInsets.only(left: 25),
                    decoration: BoxDecoration(
                        boxShadow: const [
                          BoxShadow(
                              spreadRadius: 2.0,
                              blurRadius: 10.0,
                              color: Colors.black,
                              offset: Offset(0, 10))
                        ],
                        shape: BoxShape.circle,
                        image: ...
                    ),
                  ),
           
                  Container(
                    margin: const EdgeInsets.only(left: 40.0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          "Naruto",
                          style: TextStyle(
                            color:
                            Theme.of(context).primaryColorLight,
                            fontSize: 20.0,
                          ),
                        ),
                        const SizedBox(
                          height: 5.0,
                        ),
                        Text(
                          "Loreum ipusm",
                          style: TextStyle(
                            color: Theme.of(context).primaryColor,
                            fontSize: 15.0,
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
              
            ],
          ),
          Container(
          ...
          ),
        ],
      ),
    ),
  ),

Flutter相关问答推荐

如何更改默认应用程序启动器/启动屏幕

如何在flutter文本字段中添加要点条目?

如何让GridView.builder用另外两个小部件来占据屏幕的剩余部分

如何在应用程序启动时解析和加载JSON文件?

DART 3.3:为什么扩展类型不起作用?

Flutter 布局-全屏幕容器

在Android Studio的新用户界面中未找到热重新加载

audioQuery不会等待判断存储权限

Flutter -如何将导航轨道标签靠左对齐?

如何将Xpriter代码页更改为代码页27?

遇到图像路径格式问题

在LinkedIn上分享Fighter和Web的链接会产生不同的结果

在Flutter 小部件测试中找不到框中的AssetImage装饰

Flutter 数独网格

如何动态获取任何小部件的像素?

仅在获取(读取)、Provider 时,Firestore 中的数据为空

Flutter中如何实现带有变化图标的浮动操作按钮?

Android 模拟器在 Apple M2 芯片 EXC_BAD_ACCESS / KERN_INVALID_ADDRESS 上随机崩溃

如何防止卡子在底部溢出?

如何从 Firebase Firestore 中获取具有特定字段值的文档?