你好,我试图做一个地理围栏响应,我有一堆谷歌地图网址和一个圆圈。这段代码没问题:
new Card(
elevation: 2.0,
child: new Stack(
alignment: AlignmentDirectional.center,
children: <Widget>[
new Container(
child: new Image.network(staticMapUri.toString()),
),
new Container(
alignment: new FractionalOffset(0.0, 0.0),
decoration: new BoxDecoration(
shape: BoxShape.circle,
color: Colors.lightBlue.withOpacity(0.5),
),
child:
new AspectRatio(
aspectRatio: MediaQuery.of(context).size.longestSide/GPS2,
child :
FractionalTranslation(
translation: Offset(0.0, 0.0),
child: new Container(
),
),
),
),
new Container(
//padding: const EdgeInsets.only(bottom:10.0),
margin: new EdgeInsets.all(140.0),
child : Icon(Icons.location_on, color: Colors.white, size: 25.0),
),
],
),
),
但是我搜索用滑块值替换GPS2是动态的,所以这里是代码:
new Slider(
value: valperimetre,
onChanged: (double e) => change(e),
activeColor: Colors.lightBlue,
inactiveColor :Colors.grey,
divisions: 10,
label: "$valperimetre""m",
max : 500.0,
min: 0.0,
),
new Card(
elevation: 2.0,
child: new Stack(
alignment: AlignmentDirectional.center,
children: <Widget>[
new Container(
child: new Image.network(staticMapUri.toString()),
),
new Container(
alignment: new FractionalOffset(0.0, 0.0),
decoration: new BoxDecoration(
shape: BoxShape.circle,
color: Colors.lightBlue.withOpacity(0.5),
),
child:
new AspectRatio(
aspectRatio: MediaQuery.of(context).size.longestSide/valperimetre,
child :
FractionalTranslation(
translation: Offset(0.0, 0.0),
child: new Container(
),
),
),
),
new Container(
//padding: const EdgeInsets.only(bottom:10.0),
margin: new EdgeInsets.all(140.0),
child : Icon(Icons.location_on, color: Colors.white, size: 25.0),
),
],
),
),
但目前我有这样的错误:“如果我正常重建app:断言失败:第399行pos 15:'aspectRatio.isFinite':不是真的。”如果我在重建应用程序之后将valperimetre替换为100.0,并且在我用valperimetre替换100.0之后,我可以将其重新加载。
尝试将此条件检查到代码中。
//your code here
child:(valperimetre == 0.0 || valperimetre == null) ?
Container()
:new AspectRatio(
aspectRatio: MediaQuery.of(context).size.longestSide/valperimetre,
//your code here