[英]How to make circle on corners of box in flutter?
I want to make a circle on each vertex of boxes(sqaure) and lines on each edge. 我想在box(sqaure)的每个顶点上画一个圆,并在每个边缘上画线。 How can I achieve that in flutter? 我该如何在颤抖中实现?
I have used Box Decoration to make those boxes. 我已经用盒子装饰制作了那些盒子。 Below is the code: 下面是代码:
GridView.builder(
itemCount: 20,
itemBuilder: (context, index) =>
GestureDetector(
onTap: (),
child: Container(
decoration: BoxDecoration(
color: Colors.green, shape: BoxShape.rectangle),
color: Colors.red, shape: BoxShape.circle);
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
mainAxisSpacing: 2,
crossAxisSpacing: 2,
),
Please suggest how can I achieve this. 请提出我该如何实现。
Below is expected for circle + I want to add lines on edges too : 以下是圆+的示例,我也想在边缘上添加线条:
and this is my output: 这是我的输出:
Here is the full solution ( h
donates Horizontal, and v
Vertical) 这是完整的解决方案( h
捐赠水平, v
捐赠垂直)
double _hPadding = 72, _vPadding = 20, _dotSize = 20;
int _hBox = 3, _vBox = 4;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Stack(
children: <Widget>[
Padding(
padding: EdgeInsets.symmetric(horizontal: _hPadding, vertical: _vPadding),
child: _buildBoxLayout(),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: _hPadding - _dotSize / 2, vertical: _vPadding - _dotSize / 2),
child: _buildDotLayout(),
),
],
),
);
}
Widget _buildBoxLayout() {
return GridView.builder(
itemCount: _hBox * _vBox,
itemBuilder: (context, index) => Container(color: Colors.grey[((index % 2) + 2) * 100]),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: _hBox),
);
}
Widget _buildDotLayout() {
double spacing = (MediaQuery.of(context).size.width - _hPadding * 2 - _hBox * _dotSize) / _hBox;
return GridView.builder(
itemCount: (_hBox + 1) * (_vBox + 1),
itemBuilder: (context, index) => Container(decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.grey[700])),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: _hBox + 1,
crossAxisSpacing: spacing,
mainAxisSpacing: spacing
),
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.