Flutter之Switch组件

/**
 *
 *
    const Switch({
    Key key,
    @required this.value,
    @required this.onChanged,
    this.activeColor,//选中时圆圈的颜色
    this.activeTrackColor,//选中时底部横条的颜色

    this.inactiveThumbColor,//未选中时圆圈的颜色
    this.inactiveTrackColor,//未选中时底部横条的颜色

    this.activeThumbImage,//选中时圆圈的图片
    this.inactiveThumbImage,//未选中时圆圈的图片

    this.materialTapTargetSize,//点击区域尺寸,padded:向四周扩展48px区域;shrinkWrap:控件区域
    this.dragStartBehavior = DragStartBehavior.start,
    })
 */

/**
 * const SwitchListTile({
    Key key,
    @required this.value,
    @required this.onChanged,
    this.activeColor,
    this.activeTrackColor,
    this.inactiveThumbColor,
    this.inactiveTrackColor,
    this.activeThumbImage,
    this.inactiveThumbImage,
    this.title,
    this.subtitle,
    this.isThreeLine = false,//设置为true,高度变大
    this.dense,
    this.secondary,//左侧图标
    this.selected = false,
    })
 */
body: Column(
          children: <Widget>[
            Switch(
              value: isCheck,
              onChanged: (isChecked) {
                setState(() {
                  isCheck = isChecked;
                });
              },

              activeColor: Colors.black,
              activeTrackColor: Colors.blue,
//
              inactiveThumbColor: Colors.green,
              inactiveTrackColor: Colors.orange,

//              activeThumbImage: AssetImage("images/app.png"),
//              inactiveThumbImage: AssetImage("images/app.png"),

              materialTapTargetSize: MaterialTapTargetSize.padded,
            ),
            Container(
              color: Colors.grey,
              child: SwitchListTile(
                value: isCheck1,
                onChanged: (isChecked) {
                  setState(() {
                    isCheck1 = isChecked;
                  });
                },
                activeColor: Colors.red,
                title: Text("标题"),
                subtitle: Text("副标题副标题副标题副标题副标题副标题副标题副标题副标题"),
                secondary: Icon(Icons.alarm),
                selected: true,
                activeThumbImage: AssetImage("images/app.png"),
                inactiveThumbImage: AssetImage("images/app.png"),
                isThreeLine: false,
              ),
            ),
            Container(
              margin: EdgeInsets.only(top: 5.0),
              color: Colors.grey,
              child: SwitchListTile(
                value: isCheck1,
                onChanged: (isChecked) {
                  setState(() {
                    isCheck1 = isChecked;
                  });
                },
                activeColor: Colors.red,
                title: Text("标题"),
                subtitle: Text("副标题副标题副"),
                secondary: Icon(Icons.alarm),
                selected: true,
                activeThumbImage: AssetImage("images/app.png"),
                inactiveThumbImage: AssetImage("images/app.png"),
                isThreeLine: true,
              ),
            )
          ],
        ),

码云地址:https://gitee.com/xgljh/Flutter.git

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容