美文网首页
Checkbox复选框状态变化

Checkbox复选框状态变化

作者: Jean_Lina | 来源:发表于2021-09-02 11:01 被阅读0次
    import 'package:flutter/material.dart';
    
    main() => runApp(DBJApp());
    
    class DBJApp extends StatelessWidget {
      const DBJApp({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          debugShowCheckedModeBanner: false,
          home: Scaffold(
            appBar: AppBar(
              title: Text('打扮家'),
            ),
            body: DBJBodyContent(),
          ),
        );
      }
    }
    
    class DBJBodyContent extends StatefulWidget {
      @override
      State<StatefulWidget> createState() {
        // TODO: implement createState
        return DBJBodyContentState();
      }
    }
    
    class DBJBodyContentState extends State<DBJBodyContent> {
      var flag = false;
      @override
      Widget build(BuildContext context) {
        // TODO: implement build
        return Center(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Checkbox(
                  value: flag,
                  onChanged: (state) {
                    setState(() {
                      flag = state ?? false;
                      print('点击我了');
                    });
                  }),
              Text(
                '同意协议',
                style: TextStyle(fontSize: 15, color: Colors.red),
              )
            ],
          ),
        );
      }
    }
    
    
    截屏2021-09-01 下午3.55.47.png

    相关文章

      网友评论

          本文标题:Checkbox复选框状态变化

          本文链接:https://www.haomeiwen.com/subject/ltoxwltx.html