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

wah*_*hyu 4 maps button floating-action-button flutter

我正在尝试添加粘贴到另一个小部件中的浮动操作按钮..这是我的代码的一部分..

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;
        },
      ),
    );
Run Code Online (Sandbox Code Playgroud)

我将我的地图屏幕放入容器中...但我想添加粘贴到我的地图屏幕中的浮动操作按钮..可以这样做吗?

voi*_*oid 7

您可以使用Stack小部件来实现您想要的。

检查下面的代码。它工作得很好:

 // 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),
              ),
            ),
          ],
        ),
Run Code Online (Sandbox Code Playgroud)

输出

在此输入图像描述

我希望这回答了你的问题。