I tried to create un geofencing layer in an image ( google map url)
I have a card with a child image , and I add a circle stack over the map image and I use a slider to change the size of the zone. the problem is that I don't succeded to center the map in my container. The only solution currently found is to use margin to go down the circle but when I change the margin limit the top of the circle and not the center, so my center is shifting...
here is my code example:
new Card (
child :new Stack(
children: <Widget>[
new Container(
width: 200.0,
height: 200.0,
),
new Container(
alignment: new FractionalOffset(0.0, 0.0),
decoration: new BoxDecoration(
border: new Border.all(
color: Colors.blue.withOpacity(0.5),
width: val, // it's my slider variable, to change the size of the circle
),
shape: BoxShape.circle,
),
),
],
),
),
Border radius is used to make Circle, you can add border radius more than 50% of width or height in Card to make it a circle.
To center align the widgets in the Row widget, you can use the mainAxisAlignment property and set it to MainAxisAlignment. center.
Either use alignment
property of Stack like this
new Card(
child: new Stack(
alignment: AlignmentDirectional.center,
children: <Widget>[
new Container(
width: 200.0,
height: 200.0,
),
new Container(
alignment: new FractionalOffset(0.0, 0.0),
decoration: new BoxDecoration(
border: new Border.all(
color: Colors.blue.withOpacity(0.5),
width: 50.0,
),
shape: BoxShape.circle,
),
),
],
),
),
or simply wrap your container widget with FractionalOffsetSet
new Card(
child: new Stack(
alignment: AlignmentDirectional.center,
children: <Widget>[
new Container(
width: 200.0,
height: 200.0,
),
FractionalTranslation(
translation: Offset(0.0, 0.5),
child: new Container(
alignment: new FractionalOffset(0.0, 0.0),
decoration: new BoxDecoration(
border: new Border.all(
color: Colors.blue.withOpacity(0.5),
width: 50.0,
),
shape: BoxShape.circle,
),
),
],
),
),
Wrap your Widget in FractionalTranslation and set the the offset Y value to 0.5
FractionalTranslation(
translation: Offset(0.0, 0.5),
child: new Container(
alignment: new FractionalOffset(0.0, 0.0),
decoration: new BoxDecoration(
border: new Border.all(
color: Colors.blue.withOpacity(0.5),
width: 50.0, // it's my slider variable, to change the size of the circle
),
shape: BoxShape.circle,
),
),
),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With