【发布时间】:2019-07-16 16:22:03
【问题描述】:
我正在为移动应用程序设计 UI。 如何实现一个复选框,将其状态从 false 更改为 true 或反之亦然?
bool _value1 = false;
new CheckboxListTile(
value: _value1,
onChanged: (bool val) => setState(() => _value1 = val),
title: new Text('Remember me'),
controlAffinity: ListTileControlAffinity.leading,
activeColor: Colors.black,
),
我没有收到任何错误,但是当我单击复选框时,它没有改变其状态。
编辑:完整的代码是这样的 -
bool _value1 = false;
return Scaffold(
backgroundColor: Colors.white,
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/background.jpg"),
fit: BoxFit.fill,
),
),
child: Column(
children: <Widget>[
SizedBox(height: 258.0),
username,
SizedBox(height: 22.0),
password,
SizedBox(height: 4.0),
new CheckboxListTile(
value: _value1,
onChanged: (bool val) => setState(() => _value1 = val),
title: new Text('Remember me'),
controlAffinity: ListTileControlAffinity.leading,
activeColor: Colors.black,
),
SizedBox(height: 8.0),
loginButton,
SizedBox(height: 58.0),
new Text(' Version 1.1'),
],
) ,
),
);
返回脚手架在里面
class LoginPage extends StatefulWidget {
static String tag = 'login-page';
@override
_LoginPageState createState() => new _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
@override
Widget build(BuildContext context) {.....}
用户名和密码以及登录按钮是其他小部件。
【问题讨论】:
-
请在您使用复选框的地方分享完整代码
标签: flutter dart flutter-layout