Created
April 11, 2020 09:18
-
-
Save Maadhav/68409a5296d02beb62409bf4f9c8d290 to your computer and use it in GitHub Desktop.
Flutter Switch main.dart
This file contains hidden or 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'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Home(), | |
); | |
} | |
} | |
class Home extends StatefulWidget { | |
@override | |
_HomeState createState() => _HomeState(); | |
} | |
class _HomeState extends State<Home> { | |
bool isSwitched = false; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
backgroundColor: Colors.green, | |
title: Text("Flutter Switch Example"), | |
), | |
body: Center( | |
child: Switch( | |
value: isSwitched, | |
onChanged: (value){ | |
setState(() { | |
isSwitched=value; | |
print(isSwitched); | |
}); | |
}, | |
activeTrackColor: Colors.lightGreenAccent, | |
activeColor: Colors.green, | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment