简体   繁体   English

如何在 flutter 中添加粘附到另一个小部件的浮动操作按钮

[英]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.

相关问题 如何在 flutter 中将页面添加到浮动操作按钮 - How to add a page to floating action button in flutter 每当在颤动中单击浮动操作按钮时,如何动态添加卡片小部件? - How to add a card widget dynamically whenever floating action button is clicked in flutter? 如何在 Flutter 的 Stack Widget 中添加多个浮动按钮 - How to add Multiple Floating button in Stack Widget in Flutter 如何将浮动动作固定到底部颤动(底部对齐) - how to stick floating action to bottom flutter (bottom Align) 如何在flutter的浮动操作按钮中添加whatsapp图像 - How to add whatsapp image in floating action button in flutter Flutter:向图像添加浮动操作按钮 - Flutter: add a floating action button to an image 在可扩展浮动操作按钮中,在颤动中未检测到子小部件中的手势 - In Expandable Floating action button the gestures in the child widget is not detected in flutter Flutter:在浮动操作按钮中使用 appBar 小部件而不是 appBar? - Flutter: Use appBar Widget in Floating Action Button instead of the appBar? Flutter 中的浮动操作按钮 - Floating Action Button in Flutter Flutter:如何从浮动操作按钮调用小部件的 state class 的方法 - Flutter: How to call method of widget's state class from a floating action button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM