> For the complete documentation index, see [llms.txt](https://yashs-organization-7.gitbook.io/modular-ui-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yashs-organization-7.gitbook.io/modular-ui-documentation/switch.md).

# Switch

## Switch

## MUISwitch

A basic switch widget provided by Modular UI.

### Properties

* **`checked`**: *bool* - The value to use for the underlying switch widget.
* **`onChanged`**: *ValueChanged?* - Called when the value of the switch should change.
* **`width`**: *double* - The width of the switch; default: 40.
* **`height`**: *double* - The height of the switch; default: 20.
* **`circleSize`**: *double* - The absolute size of the circle, aka diameter; default: 18.
* **`animationDuration`**: *Duration* - The duration of the animation; default: Durations.short3.
* **`animationCurve`**: *Curve* - The curve of the animation; default: Curves.easeInOut.
* **`onStateCol`**: *Color* - The color when the switch is in the "on" state; default: Colors.white.
* **`offStateCol`**: *Color* - The color when the switch is in the "off" state; default: Color.fromARGB(255, 39, 39, 42).

#### `newYork({ ... })`

A factory method to create a New York-style switch.

#### Parameters

* **`checked`**: *bool* - The initial value of the switch; default: false.
* **`onChanged`**: *ValueChanged?* - Callback when the value of the switch changes.
* **`width`**: *double* - The width of the switch; default: 38.
* **`height`**: *double* - The height of the switch; default: 18.
* **`circleSize`**: *double* - The absolute size of the circle, aka diameter; default: 16.
* **`onStateCol`**: *Color* - The color when the switch is in the "on" state; default: Colors.white.
* **`offStateCol`**: *Color* - The color when the switch is in the "off" state; default: Color.fromARGB(255, 39, 39, 42).

### Example Usage

{% embed url="<https://verdant-lokum-9bd5c2.netlify.app/#/switch>" %}
Switch
{% endembed %}

```dart
MUISwitch(
  checked: true,
  onChanged: (value) {
    // Handle switch value change
    print("Switch Value: $value");
  },
  width: 40,
  height: 20,
  circleSize: 18,
  animationDuration: Durations.short3,
  animationCurve: Curves.easeInOut,
  onStateCol: Colors.white,
  offStateCol: Color.fromARGB(255, 39, 39, 42),
);

// Alternatively, use the New York-style switch
MUISwitch.newYork(
  checked: false,
  onChanged: (value) {
    // Handle switch value change
    print("Switch Value: $value");
  },
  width: 38,
  height: 18,
  circleSize: 16,
  onStateCol: Colors.white,
  offStateCol: Color.fromARGB(255, 39, 39, 42),
);
```

### **Notes**

* Provides a basic switch widget with customizable appearance.
* Supports a New York-style switch through the **`newYork`** factory method.
* Utilizes animations for a smooth transition between states.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://yashs-organization-7.gitbook.io/modular-ui-documentation/switch.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
