Created
December 22, 2019 09:03
-
-
Save haidar786/e6a986f406664f70d4a6f55146c80a67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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