在Flutter中使用Row小部件渲染CheckboxListTile小部件时出现错误。

3

我有以下代码:

            Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  CheckboxListTile(
                    title: Text("helo"),
                    controlAffinity: ListTileControlAffinity.leading,
                    value: true,
                    onChanged: null,

                  ),
                  Text(
                    "Forgot Password?",
                    style: TextStyle(color: Colors.blueGrey),
                  )
                ],
              ),

我的目标是在同一排中创建一个“记住我”复选框和“忘记密码”链接。
当我运行这段代码时,它会给出以下错误:
RenderBox was not laid out: RenderMergeSemantics#19dcc relayoutBoundary=up8 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1785 pos 12: 'hasSize'
The relevant error-causing widget was Row lib\main.dart:106
═══════════════════════════════════════════════════════════════════════════════

════════ Exception caught by rendering library ═════════════════════════════════ 
RenderBox was not laid out:
_RenderColoredBox#cd072 relayoutBoundary=up14 
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1785 pos 12: 'hasSize'
The relevant error-causing widget was CheckboxListTile

有没有办法让“记住我”复选框和“忘记密码?”在同一行中显示?此外,当前代码有什么问题?

尝试将CheckboxListTile包裹在Expanded中。 - Ketan Ramteke
1个回答

4
CheckboxListTile包装在类似下面所示的Expanded小部件中:
Row(
    mainAxisAlignment: MainAxisAlignment.spaceBetween,
    children: [
      Expanded(
        child: CheckboxListTile(
          title: Text("helo"),
          controlAffinity: ListTileControlAffinity.leading,
          value: true,
          onChanged: null,

        ),
      ),
      Text(
        "Forgot Password?",
        style: TextStyle(color: Colors.blueGrey),
      )
    ],
  ),

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接