如何在带有iPhone X和iPhone XS等缺口的iOS设备上为AppBar使用英雄动画?

时间:2019-02-25 16:49:18

标签: ios iphone dart flutter flutter-animation

嗨,我正在尝试使AppBar在过渡期间保持顶部。我发现可以使用Hero做到这一点。但是,带有缺口的iOS设备(iPhone X,XR,XS等)显示出奇怪的行为。适用于Android和其他iOS设备。在Hero动画期间,AppBar的内容先上后下。我希望它是固定的,因为初始位置和最后位置相同。我填写了issue in github,但是现在正在寻找解决方法。

这里有一个最小的例子来说明问题:

void main() async {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  MyApp({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: MyHomeScreen(),
    );
  }
}

Widget _heroAppBar({BuildContext context,String titleText}){
    return PreferredSize(
      preferredSize: Size.fromHeight(kToolbarHeight),
      child: Hero(
          tag: 'app_bar',
          child: Builder(builder: (BuildContext context) {
            return AppBar(title:Text(titleText));
          }
        ),
      ),
    );
  }


class MyHomeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar:_heroAppBar(context:context,titleText:"Home"),
      body:Center(
        child: IconButton(
          iconSize: 100,
          icon:Icon(Icons.play_arrow),
          onPressed: (){
            Navigator.push(context, MaterialPageRoute(builder: (context){
              return MyNextScreen();
            }));
          }
        ),
      )
    );
  }
}

class MyNextScreen extends StatelessWidget {
  Widget build(BuildContext context) {
    return  Scaffold(
        appBar:_heroAppBar(context:context,titleText:"Second"),
        body:Center(child:Text("Second Screen")),
        );
  }
}

我还附了一张说明问题的gif文件。

iPhone X / iPhone 7:

谢谢

0 个答案:

没有答案