Flutter在圆形容器内创建单选按钮

时间:2019-03-01 12:21:21

标签: flutter

      return Material(
      child: Center(
        child: Stack(
          children: <Widget>[
            Container(
              alignment: Alignment.center,
              child: new Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.start,
                children: <Widget>[
                  Stack(
                    children: <Widget>[Positioned(
                      top: 15,
                      left: 5,
                      child:  Container(
                        alignment: Alignment.center,
                        width: 25.0,
                        height: 25.0,
                        decoration: new BoxDecoration(
                          shape: BoxShape.circle,
                          color: const Color(0XFFE6E6E6),
                          border: new Border.all(
                            width: 0.0,
                            color: Colors.white,
                          ),
                        ),
                      )
                    ),
                      Center(                                               
                        child: Radio(
                          groupValue: null,
                          onChanged: (Null value) {},
                          value: null,
                        ),
                      )
                    ],
                  )
  }

我正在gridview中实现单选按钮,我想在容器内创建一个单选按钮。我上面尝试过的代码没有将单选按钮放置在容器内。

1 个答案:

答案 0 :(得分:1)

尝试这个。您可以根据需要获取代码。

Material(
        child: Container(
      height: 200.0,
      decoration: new BoxDecoration(
        color: Colors.white,
        shape: BoxShape.circle,
      ),
      child: Center(
        child: Stack(
          children: <Widget>[
            Container(
              alignment: Alignment.center,
              child: new Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Stack(
                    alignment: Alignment.center,
                    children: <Widget>[
                      Container(
                        alignment: Alignment.center,
                        width: 20.0,
                        height: 20.0,
                        decoration: new BoxDecoration(
                          shape: BoxShape.circle,
                          color: const Color(0XFFE6E6E6),
                          border: new Border.all(
                            width: 0.0,
                            color: Colors.white,
                          ),
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
                        child: Radio(
                          groupValue: null,
                          onChanged: (Null value) {},
                          value: null,
                        ),
                      )
                    ],
                  )
                ],
                // child: contentInCircle,
              ),
            ),
          ],
        ),
      ),
    ))