Created
August 31, 2019 06:14
-
-
Save manofi21/9104f2305efc888671a847e489011a07 to your computer and use it in GitHub Desktop.
how to show switch in flutter
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'; | |
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