dart - 同屏多于一个 float 操作按钮显示黑屏

标签 dart flutter

我尝试在我的一个屏幕上添加两个 float 操作按钮,结果在第一次重新加载应用后出现黑屏。

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

从调试日志中我注意到以下行

 Within each subtree for which heroes are to be animated (typically a PageRoute subtree),
 each Hero must have a unique non-null tag.In this case, multiple heroes
 had the following tag: <default FloatingActionButton tag>

最佳答案

调试信息表明问题出在 float 操作按钮的英雄动画上。

如果您不想在 FAB 上显示英雄动画,请将两个 FAB 的 heroTag 属性设为 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。

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),
           ),
        ],
),

关于dart - 同屏多于一个 float 操作按钮显示黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54017447/

相关文章:

sqlite - Flutter SQFLite一次创建多个表

mobile - 如何在 Flutter 中使页面背景半透明以显示上一屏幕?

node.js - 使用BLoC模式的Flutter登录系统

flutter - 播放和暂停 Flutter 动画

dart - 是否发现2个具有不同时区的DateTime对象的区别?

listview - 如何在移动 slider 时锁定页面滚动

firebase - 如何按类别显示产品 flutter Firestore

node.js - Dart VM 的性能与 Node.js 相比如何?

flutter 检测屏幕是否关闭

ios - Flutter Flavors : Can't find Generated. xcconfig