Skip to content

Instantly share code, notes, and snippets.

@haidar786
Created December 22, 2019 09:03
Show Gist options
  • Save haidar786/e6a986f406664f70d4a6f55146c80a67 to your computer and use it in GitHub Desktop.
Save haidar786/e6a986f406664f70d4a6f55146c80a67 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:torch/torch.dart';
class SwithS extends StatefulWidget{
@override
State<StatefulWidget> createState() {
return SwitchWidgetClass();
}
}
class SwitchWidgetClass extends State {
bool switchControl = false;
var textHolder = 'Switch is OFF';
void toggleSwitch(bool value) {
if (switchControl == false) {
setState(() {
switchControl = true;
textHolder = 'Switch is ON';
});
print('Switch is ON');
Torch.turnOn();
} else {
setState(() {
switchControl = false;
textHolder = 'Switch is OFF';
});
print('Switch is OFF');
Torch.turnOff();
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
Transform.scale(
scale: 1.5,
child: Switch(
onChanged: toggleSwitch,
value: switchControl,
activeColor: Colors.blue,
activeTrackColor: Colors.green,
inactiveThumbColor: Colors.white,
inactiveTrackColor: Colors.grey,
)),
Text(
'$textHolder',
style: TextStyle(fontSize: 24),
)
]),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment