如何禁用颤振开关

在我的帮助屏幕中,我有这个开关,它的目的是什么都不做,只是像它一样显示。

但是我现在遇到的问题是,即使它没有做任何事情,用户也可以拖动开关,所以我试图弄清楚如何禁用它,以便没有人可以拖动开关按钮。

    return Container(
      child: Card(
        color: Theme.of(context).primaryColor,
        margin: EdgeInsets.only(bottom: 30, top: 10),
        child: ListTile(
          title: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Text("Dark Theme",
                  style: TextStyle(color: Theme.of(context).accentColor)),
              Switch(
                  value: true,
                  onChanged: (value) {},
                  activeColor: Theme.of(context).accentColor),
              Text("Light Theme", style: TextStyle())
            ],
          ),
        ),
      ),
    );
  }

回答

要禁用您的Switch,请onChanged像这样将其方法编辑为 null

Switch(
  onChanged: null,
  value: true,
  inactiveThumbColor: Colors.tealAccent,
  inactiveTrackColor: Colors.tealAccent.withOpacity(0.5),
  // ...
),


以上是如何禁用颤振开关的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>