Skip to content

Instantly share code, notes, and snippets.

@manofi21
Created August 31, 2019 06:14
Show Gist options
  • Save manofi21/9104f2305efc888671a847e489011a07 to your computer and use it in GitHub Desktop.
Save manofi21/9104f2305efc888671a847e489011a07 to your computer and use it in GitHub Desktop.
how to show switch in flutter
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
const MyApp({Key key}) : super(key: key);
@override
State<StatefulWidget> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool _switchVal = true;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 45),
child: Switch(
onChanged: (bool value) {
setState(() => this._switchVal = value);
},
value: this._switchVal,
))
],
)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment