且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

同一屏幕上有多个浮动操作按钮显示黑屏

更新时间:2023-11-18 13:27:46

调试信息表明问题出在英雄动画上

The debug information suggests that the issue is with hero animation of the floating action button.

如果不想在FAB上使用英雄动画,请将两个FAB的heroTag属性设置为null。

If you don't want hero animations on FAB, make the heroTag property of both the FAB as null.

Column(
   mainAxisSize: MainAxisSize.min,
   children: <Widget>[
        FloatingActionButton(
            heroTag: null,
            onPressed: () {
            },
            materialTapTargetSize: MaterialTapTargetSize.padded,
            backgroundColor: Colors.green,
            child: const Icon(Icons.map, size: 36.0),
       ),
       SizedBox(
            height: 16.0,
       ),
       FloatingActionButton(
            heroTag: null,
            onPressed: () {},
            materialTapTargetSize: MaterialTapTargetSize.padded,
            backgroundColor: Colors.green,
            child: const Icon(Icons.add_location, size: 36.0),
       ),
    ],
),

如果您喜欢使用FAB的默认英雄动画,则向FAB添加唯一的英雄标签。

If you prefer default hero animations with the FAB, add unique hero tags to the FABs.

Column(
       mainAxisSize: MainAxisSize.min,
       children: <Widget>[
            FloatingActionButton(
                heroTag: 'unq1',
                onPressed: () {
                },
                materialTapTargetSize: MaterialTapTargetSize.padded,
                backgroundColor: Colors.green,
                child: const Icon(Icons.map, size: 36.0),
           ),
           SizedBox(
                height: 16.0,
           ),
           FloatingActionButton(
                heroTag: 'unq2'
                onPressed: () {},
                materialTapTargetSize: MaterialTapTargetSize.padded,
                backgroundColor: Colors.green,
                child: const Icon(Icons.add_location, size: 36.0),
           ),
        ],
),