[英]How to add floating action button that stick to another widget in flutter
I am trying to add floating action button that stick into another widget.. here is part of my code..我正在尝试添加粘在另一个小部件中的浮动操作按钮..这是我的代码的一部分..
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height / 2,
child: GoogleMap(
mapType: MapType.normal,
initialCameraPosition: init,
markers: ...
circles: ...,
onMapCreated: (GoogleMapController controller) {
_controller = controller;
},
),
);
I put my Maps screen inside Container... but I want to add floating action button that stick into my maps screen.. is it possible to do that?我将我的地图屏幕放在 Container 内...但我想添加浮动操作按钮以粘贴到我的地图屏幕中.. 可以这样做吗?
You can use a Stack
widget to achieve what you want.您可以使用Stack
小部件来实现您想要的。
Check the code below.检查下面的代码。 It works perfectly fine:它工作得很好:
// use a stack widget
body: Stack(
children: <Widget>[
GoogleMap(
mapType: MapType.normal,
initialCameraPosition: init,
markers: ...
circles: ...,
onMapCreated: (GoogleMapController controller) {
_controller = controller;
},
),
// align it to the bottom center, you can try different options too (e.g topLeft,centerLeft)
Align(
alignment: Alignment.bottomRight,
// add your floating action button
child: FloatingActionButton(
onPressed: () {},
child: Icon(Icons.map),
),
),
],
),
OUTPUT OUTPUT
I hope this answers your question.我希望这回答了你的问题。
Use a Stack
使用Stack
Stack(
children: <Widget>[
Align(
alignment:Alignment.center,//change this as you need
child:MyGoogleMap()
),
Align(
alignment:Alignment.bottomCenter,//change this as you need
child:FloatingActionButton(...)
),
],
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.