英雄动画导致(最小)溢出
Hero animation causes (minimal) overflow
当 Hero
包含带有 mainAxisSize: MainAxisSize.min
的列时,在导航到新页面时,内容会溢出。甚至在导航到完全相同的页面时也会发生这种情况。因此,为了说明这一点,请看下面一个相当荒谬的例子。在此示例中,我收到消息 'A RenderFlex overflowed by 0.0000172 pixels on the bottom.'
使用英雄动画时如何防止这样溢出?
示例代码:
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"),
],
)
),
),
),
)
);
}
}
当 Hero
包含带有 mainAxisSize: MainAxisSize.min
的列时,在导航到新页面时,内容会溢出。甚至在导航到完全相同的页面时也会发生这种情况。因此,为了说明这一点,请看下面一个相当荒谬的例子。在此示例中,我收到消息 'A RenderFlex overflowed by 0.0000172 pixels on the bottom.'
使用英雄动画时如何防止这样溢出?
示例代码:
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"),
],
)
),
),
),
)
);
}
}