【发布时间】:2020-10-29 10:27:26
【问题描述】:
作为this链接文章的后续。我正在做一个 Flutter 项目,我想通过两个按钮来增加圆的半径。
现在我已经部分成功了,但还不能很好地工作。我真的不知道该如何解释,但我会尽力而为:
发生的事情是,只要我按下减号按钮,它就会变小一步。如果我再次按下减号按钮,它会再次变小一点。但只要我再次按下加号,它就会保持相同的大小,直到我通过最大的数字。
video 的问题如果没有得到清楚的解释。
也许有人知道如何处理这个问题?
代码(删除了不必要的代码):
class _AddRayPageState extends State<AddRayPage> {
List<Marker> myMarker = [];
final Set<Circle> circle = {};
GoogleMapController mapController;
int _n = 8;
LatLng startLoc = LatLng(52.0907374, 5.1214201);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Toevoegen'),
),
body: Stack(children: <Widget>[
GoogleMap(
onMapCreated: onMapCreated,
markers: Set.from(myMarker),
initialCameraPosition: CameraPosition(target: startLoc, zoom: 8),
circles: circle,
),
]),
floatingActionButton: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 40.0),
child: Container(
child: Row(
children: <Widget>[
Container(
width: 40.0,
height: 40.0,
child: new FloatingActionButton(
heroTag: "btnAdd",
onPressed: add,
child: new Icon(
Icons.add,
color: Colors.black,
size: 30,
),
backgroundColor: Colors.white,
),
),
new Text('$_n', style: new TextStyle(fontSize: 40.0)),
Container(
width: 40.0,
height: 40.0,
child: new FloatingActionButton(
heroTag: "btnMinus",
onPressed: minus,
child: new Icon(
const IconData(0xe15b, fontFamily: 'MaterialIcons'),
color: Colors.black,
size: 30,
),
backgroundColor: Colors.white,
),
),
],
),
),
),
],
),
);
}
void add() {
setState(() {
_n++;
});
addRadiusToMap(_n);
}
void minus() {
setState(() {
if (_n != 1) _n--;
});
addRadiusToMap(_n);
}
void addRadiusToMap(radius) {
setState(() {
double reciprocal(double d) => 1000 * d;
circle.add(Circle(
circleId: CircleId("1"),
center: startLoc,
radius: reciprocal(radius.toDouble()),
));
});
}
【问题讨论】:
标签: flutter google-maps-markers