Skip to content

How to disable the dragging of the Switch ? #24857

Closed

Description

@carlosbdw

Now there is a switch in our app to show a shop is open or closed in my App, it will show a dialog to confirm when I tap it , but if I drag the switch from On to Off , and then I close the dialog ,the switch should remain On, but it becomes Off , so I want to disable the dragging ,is it possible?

Activity

  1. zoechi commented on Nov 29, 2018

    @zoechi
    Contributor

    Please consider asking support questions in one of the other channels listed at http://flutter.io/support .

    I'd suggest to ask on StackOverflow but please add some code that demonstrates what you try to accomplish.

  2. erdemyerebasmaz commented on Dec 4, 2019

    @erdemyerebasmaz

    @carlosbdw Not sure if you still need this but I ran into 0 finds on my search for this problem. So, I'm posting for others that might be asking the same question.

    You could remove onChanged of your Switch and wrap it with a GestureDetector.
    Ignore color values... You might need to take in consideration of Theme.of(context).brightness to add necessary conditions of thumb and track color. Please refer to switch.dart.

    bool _switchValue;
      @override
      initState() {
        super.initState();
       _switchValue = false;
      }
    
    ⋮
    ⋮
    ⋮
    
    GestureDetector(
        onTap: () {
          if (this.mounted) {
            setState(() => _switchValue = !_switchValue);
          }
        },
        child: Switch(
          value: _switchValue,
          inactiveThumbColor: _switchValue
              ? Colors.white
              : Colors.grey.shade400,
          inactiveTrackColor: _switchValue
              ? Colors.white.withAlpha(0x80)
              : Colors.white30,
        ),
    )
    
    ⋮
    ⋮
    ⋮
    
    
  3. github-actions commented on Aug 25, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  4. locked as resolved and limited conversation to collaborators on Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions