Skip to content

Instantly share code, notes, and snippets.

@usimsek
Last active March 19, 2022 18:08
Show Gist options
  • Save usimsek/8f69e3c41231a2897c6b6a5e4345dc58 to your computer and use it in GitHub Desktop.
Save usimsek/8f69e3c41231a2897c6b6a5e4345dc58 to your computer and use it in GitHub Desktop.
flutter SWITCH
import 'package:flutter/material.dart';
class SwitchOnchangedListener extends StatefulWidget {
@override
SwitchOnchangedListenerState createState() {
return new SwitchOnchangedListenerState();
}
}
class SwitchOnchangedListenerState extends State<SwitchOnchangedListener> {
bool _isChecked = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Swiutch Onchange Listener Example"),
),
body: Column(
children: <Widget>[
Expanded(
child: Center(
child: Text(_isChecked ? "Switch On" : "Switch Off",
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.red,
)),
),
),
Expanded(
child: Container(
height: 350.0,
child: Column(
children: [
Switch(
value: _isChecked,
onChanged: (val) {
setState(() {
_isChecked = val;
});
},
),
],
),
)),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment