如何禁用颤振开关 [英] How can I disabled flutter switch

查看:51
本文介绍了如何禁用颤振开关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的帮助屏幕中,我有此开关,其目的是不做任何事情,而只是按原样显示.

In my help screen, I have this switch and the purpose for that is to do nothing but just display like the way it is.

但是我现在遇到的问题是,尽管它什么也没做,但是用户可以拖动开关,所以我试图弄清楚如何禁用它,这样没人可以拖动开关按钮

But the problem I'm having right now, even though it doesn't do anything, the user can drag the switch so I'm trying to figure out how I can disabled it so that no one can drag the switch button.

    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

To disable your Switch, edit its onChanged method to null like this

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

这篇关于如何禁用颤振开关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆