import 'package:gluestack_ui/gluestack_ui.dart';
GSSwitch(
size: GSSwitchSizes.$md,
isDisabled: false,
style: GSStyle(
checked: GSStyle(
thumbColor: Colors.grey,
activeThumbColor: Colors.blue,
),
),
value: val1,
onToggle: (bool value) {
setState(() {
val1 = value;
});
},
)
import "package:gluestack_ui/gluestack_ui.dart"
Parameters | Type | Default | Description |
---|---|---|---|
isDisabled | bool | false | When true, the switch is disabled and cannot be toggled |
isInvalid | bool | false | When true, the switch displays an error state. |
isHovered | bool | false | When true, the switch displays a hover state. |
value | bool | false | The value of the switch. If true the switch will be turned on. |
onToggle | (void Function(bool)? onToggle | - | Callback to be invoked when switch value is changed. |
Name | Value | Default |
---|---|---|
size | sm | md | lg | md |
import 'package:gluestack_ui/gluestack_ui.dart';
bool isSelected = false;
GSHStack(
children: [
GSSwitch(
value: isSelected,
onToggle: (value) {
setState(() {
isSelected = value;
});
},
),
const SizedBox(
width: 10,
),
const GSText(text: 'Allow notifications'),
],
)
import 'package:gluestack_ui/gluestack_ui.dart';
bool isSelected = true;
GSHStack(
children: [
GSSwitch(
value: isSelected,
onToggle: (value) {
setState(() {
isSelected = value;
});
},
),
const SizedBox(
width: 10,
),
const GSText(text: 'Public profile'),
],
)
import 'package:gluestack_ui/gluestack_ui.dart';
bool isSelected = false;
bool isSelectedTwo = false;
bool isSelectedThree = false;
GSVStack(
children: [
GSSwitch(
style: GSStyle(
trackColorTrue: $GSColors.red500,
onHover: GSStyle(
trackColorTrue: $GSColors.red600,
),
),
value: isSelected,
onToggle: (value) {
setState(() {
isSelected = value;
});
},
),
const SizedBox(
height: 20,
),
GSSwitch(
style: GSStyle(
trackColorTrue: $GSColors.green500,
onHover: GSStyle(
trackColorTrue: $GSColors.green600,
),
),
value: isSelectedTwo,
onToggle: (value) {
setState(() {
isSelectedTwo = value;
});
},
),
const SizedBox(
height: 20,
),
GSSwitch(
style: GSStyle(
trackColorTrue: $GSColors.orange400,
onHover: GSStyle(
trackColorTrue: $GSColors.orange600,
),
),
value: isSelectedThree,
onToggle: (value) {
setState(() {
isSelectedThree = value;
});
},
),
],
)