Flutter-单选和多选

import 'package:flutter/material.dart';

//单选和多选
void main() => runApp(MaterialApp(
      home: _home(),
    ));

class _home extends StatefulWidget {
  @override
  State createState() {
    // TODO: implement createState
    return new _homeState();
  }
}

class _homeState extends State<_home> {
  bool _switchSelected = true; //单选状态
  bool _checkBoxSelected = true; //复选状态
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      appBar: new AppBar(
        title: Text('title'),
        centerTitle: true,
      ),
      body: new Column(
        children: [
          Switch(
            value: _switchSelected,
            activeColor: Colors.red,
            onChanged: (value) {
              setState(() {
                _switchSelected = value;
              });
            },
          ),
          Checkbox(
            value: _checkBoxSelected,
            activeColor: Colors.green,
            onChanged: (value) {
              setState(() {
                _checkBoxSelected = value;
              });
            },
          )
        ],
      ),
    );
  }
}

你可能感兴趣的:(Flutter,Flutter-单选和多选)