我尝试在我的一个屏幕上添加两个 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/