class SwitchDemo extends StatefulWidget {
@override
_SwitchDemoState createState() => _SwitchDemoState();
}
class _SwitchDemoState extends State<SwitchDemo> {
bool _switchItemA = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('checkboxDemo'),
elevation: 0,
),
body: Container(
padding: EdgeInsets.all(16),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Switch(
value: _switchItemA,
onChanged: (value) {
setState(() {
_switchItemA = value;
});
},
)
],
)
],
),
),
);
}
}
预览
class SwitchDemo extends StatefulWidget {
@override
_SwitchDemoState createState() => _SwitchDemoState();
}
class _SwitchDemoState extends State<SwitchDemo> {
bool _switchItemA = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('SwitchDemo'),
elevation: 0,
),
body: Container(
padding: EdgeInsets.all(16),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SwitchListTile(
value: _switchItemA,
onChanged: (value) {
setState(() {
_switchItemA = value;
});
},
title: Text('Switch Item A'),
subtitle: Text('Description'),
secondary: Icon(_switchItemA ? Icons.visibility : Icons.visibility_off),
selected: _switchItemA,
),
],
),
),
);
}
}
image.png
网友评论