Skip to content

Instantly share code, notes, and snippets.

@Maadhav
Created April 11, 2020 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Maadhav/68409a5296d02beb62409bf4f9c8d290 to your computer and use it in GitHub Desktop.
Save Maadhav/68409a5296d02beb62409bf4f9c8d290 to your computer and use it in GitHub Desktop.
Flutter Switch main.dart
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