当 aHero
包含带有 的 Column 时mainAxisSize: MainAxisSize.min
,在导航到新页面时,内容会溢出。甚至在导航到完全相同的页面时也会发生这种情况。为了说明这一点,请看下面一个相当荒谬的例子。在此示例中,我收到消息“A RenderFlex 在底部溢出 0.0000172 像素。” 使用英雄动画时如何防止这样的溢出?
示例代码:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Hero Overflow',
theme: ThemeData.light(),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Hero overflow"),
),
body: Center(
child: Hero(
tag: "mytag",
child: Card(
child: InkWell(
onTap: () {
Navigator.of(context).push(
PageRouteBuilder(
pageBuilder: (context, a , b) => MyHomePage()
)
);
},
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text("Hello world"),
],
)
),
),
),
)
);
}
}