美文网首页
flutter Switch组件

flutter Switch组件

作者: 银弹星空 | 来源:发表于2021-04-29 17:20 被阅读0次

构造方法

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,
    })

用法

  _centerMenuRow() {
    return Container(
      height: ScreenUtil().setHeight(150),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Column(
            mainAxisSize: MainAxisSize.min,
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Switch(
                  activeThumbImage:
                      AssetImage("images/create_audio_switch_on_icon.png"),
                  inactiveThumbImage:
                      AssetImage("images/create_audio_switch_off_icon.png"),
                  activeTrackColor: Color.fromARGB(255, 209, 104, 68),
                  inactiveTrackColor: Color.fromARGB(255, 102, 102, 102),
                  value: isGoNoise ?? false,
                  onChanged: (value) {
                    setState(() {
                      isGoNoise = value;
                    });
                  }),
              Text('去噪'),
            ],
          ),
          Column(
            mainAxisSize: MainAxisSize.min,
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Switch(
                  activeThumbImage:
                      AssetImage("images/create_audio_switch_on_icon.png"),
                  inactiveThumbImage:
                      AssetImage("images/create_audio_switch_off_icon.png"),
                  activeTrackColor: Color.fromARGB(255, 209, 104, 68),
                  inactiveTrackColor: Color.fromARGB(255, 102, 102, 102),
                  value: isDoubleSound ?? false,
                  onChanged: (value) {
                    setState(() {
                      isDoubleSound = value;
                    });
                  }),
              Text('双声道'),
            ],
          ),
        ],
      ),
    );
  }

相关文章

网友评论

      本文标题:flutter Switch组件

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