首页 > 解决方案 > Flutter/Dart, Switch:又抛出一个异常:A RenderFlex 右侧溢出 99640 像素

问题描述

我目前正在尝试向我的 android 应用程序的设置页面添加一个开关。但是,当我添加代码并尝试在模拟器上查看它时,会引发以下错误:

抛出了另一个异常:A RenderFlex 在右侧溢出了 99640 像素。

代码:

Container(
  decoration: BoxDecoration (
    color: Colors.white,
    border: Border(
      bottom: BorderSide(width: 1.0, color: Colors.grey)
    ),
  ),
  constraints: BoxConstraints (
    maxHeight: ((width * ratio) * 0.1),
    minWidth: width,
    maxWidth: width,
  ),
  child: Row(
    children: <Widget>[
      Expanded(
        child: Padding(
          padding: EdgeInsets.only(left: (width*ratio) * 0.025),
          child: Text('Highlight Identical Numbers', style: TextStyle(color: Colors.black87, fontSize: fontTextTwoScale, fontFamily: 'Roboto'))
        )
      ),
      Container(
        child: Switch(value: null, onChanged: null,)
      ),
    ],
  ),
),

我正在尝试对其进行设置,以使文本与屏幕左侧对齐,并且开关与右侧对齐。我不明白小部件如何溢出 99640 像素。我没有看到 Switch 的尺寸选项。

在此处输入图像描述

标签: androiddartflutter

解决方案


这应该很容易完成这项工作。自定义 ListTile 或将其包装在 Container 中以进行自定义。

ListTile(
  title: Text("Setting Text One Title"),
  trailing: Switch(value: true, onChanged: (bool x) {}),
)

在此处输入图像描述


推荐阅读