当Hero
包含带有mainAxisSize: MainAxisSize.min
的列时,导航到新页面时,内容溢出。导航到完全相同的页面时甚至会发生这种情况。因此,为了说明这一点,请参见下面的一个非常荒谬的示例。在此示例中,我收到消息“ 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"),
],
)
),
),
),
)
);
}
}