Flutter自定義圓形選擇框

flutter自帶的checkbox是方形的,需要圓形可以自定義一個,用法一樣:

import 'package:flutter/material.dart';
class RoundCheckBox extends StatefulWidget {
  var value = false;

  Function(bool) onChanged;

  RoundCheckBox({Key key, @required this.value, this.onChanged})
      : super(key: key);

  @override
  _RoundCheckBoxState createState() => _RoundCheckBoxState();
}

class _RoundCheckBoxState extends State<RoundCheckBox> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: GestureDetector(
          onTap: () {
            widget.value = !widget.value;
            widget.onChanged(widget.value);
          },
          child: Padding(
            padding: const EdgeInsets.all(10.0),
            child: widget.value
                ? Icon(
                    Icons.check_circle,
                    size: 25.0,
                    color: Colors.lightBlue,
                  )
                : Icon(
                    Icons.panorama_fish_eye,
                    size: 25.0,
                    color: Colors.grey,
                  ),
          )),
    );
  }
}

歡迎學習flutter的同學加羣一起學習:187670882

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章