我正在为search and review cart页面设置bool条件,然后我面临这3个我试图解决但未成功的错误(容器上的前2个错误//预计会找到",".//无法将元素类型"bool"分配给列表类型"Widget".)以及文本小部件上的第二个小部件(预期会找到"]")

bool isBool = false;
  SigleItem(this.isBool);



 isBool ==false  Container( //Expected to find ','. //The element type 'bool' can't be assigned to the list type 'Widget'.
                  margin: const EdgeInsets.only(right: 15),
                  padding: const EdgeInsets.symmetric(horizontal: 10),
                  height: 35,
                  decoration: BoxDecoration(
                    border: Border.all(color: Colors.grey),
                    borderRadius: BorderRadius.circular(30),
                  ),
                  child: Row(
                    children: [
                      const Expanded(
                        child: Text(
                          'RS-799',
                          style: TextStyle(
                            color: Colors.grey,
                          ),
                        ),
                      ),
                      Center(
                        child: Icon(
                          Icons.arrow_drop_down,
                          size: 20,
                          color: primaryColor,
                        ),
                      ),
                    ],
                  ),
                ):Text('750')//Expected to find ']'.

推荐答案

你忘记了布尔条件后的问号,读this代表Conditional Statement

isBool == false
        ? Container(
            margin: const EdgeInsets.only(right: 15),
            padding: const EdgeInsets.symmetric(horizontal: 10),
            height: 35,
            decoration: BoxDecoration(
              border: Border.all(color: Colors.grey),
              borderRadius: BorderRadius.circular(30),
            ),
            child: Row(
              children: [
                const Expanded(
                  child: Text(
                    'RS-799',
                    style: TextStyle(
                      color: Colors.grey,
                    ),
                  ),
                ),
                Center(
                  child: Icon(
                    Icons.arrow_drop_down,
                    size: 20,
                    color: Colors.red,
                  ),
                ),
              ],
            ),
          )
        : Text('750'),

Result Screen->image

Flutter相关问答推荐

如何将图像从顶部和底部半向外设置为飘动

ListTile未正确显示在flutter中

Android NFC未收到空的NFC标签

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

如何从文本比例因子迁移到文本比例因子

顶部对齐ListTile的[前导、标题、尾随]小部件

在带有 flutter 的 Native Android 中,EventChannel.EventSink 始终为 null

TextField 中的富文本并获取 RenderParagraph

如何使用 Material3 创建带有高度的完美白色提升按钮?

Select 文本时如何更改 Flutter 中的光标 colored颜色 ?

尽管设置了对齐方式,如何对齐列中的行?

如何在Flutter中的textField中在可编辑文本和前缀图标之间添加空格?

点击按钮后重新启动定时器

Flutter蓝牙 - 如何通过蓝牙从设备中获取文件?

当项目较少时收缩列表视图

如何显示从 MariaDB 获取的数据到列表视图

更改文本字段Flutter 中最大字母的 colored颜色

在 flutter 中使用 Firebase 实时数据库数据创建无限滚动效果

如何使用我拥有的 .jks 文件签署我的应用程序

如何在Flutter 的 initState 中初始化 Firestore 查询