Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Animation 有没有办法从颤振中的动画中排除BottomAppBar?_Animation_Flutter_Dart_Bottomappbar - Fatal编程技术网

Animation 有没有办法从颤振中的动画中排除BottomAppBar?

Animation 有没有办法从颤振中的动画中排除BottomAppBar?,animation,flutter,dart,bottomappbar,Animation,Flutter,Dart,Bottomappbar,我试着将它包装在一个英雄小部件中,因为这应该可以实现我想要的。这适用于BottomNavigationBar,但不适用于BottomAppBar,这会导致以下错误:Scaffold.geometryOf()使用不包含Scaffold的上下文调用。我尝试使用生成器为其提供上下文,但也不起作用。下面是一个示例应用程序,用于展示该行为: void main() { runApp( MaterialApp( home: PageOne(), ), ); } Widg

我试着将它包装在一个英雄小部件中,因为这应该可以实现我想要的。这适用于BottomNavigationBar,但不适用于BottomAppBar,这会导致以下错误:
Scaffold.geometryOf()使用不包含Scaffold的上下文调用。
我尝试使用生成器为其提供上下文,但也不起作用。下面是一个示例应用程序,用于展示该行为:

void main() {
  runApp(
    MaterialApp(
      home: PageOne(),
    ),
  );
}

Widget _bottomNavigationBar() {
  return BottomNavigationBar(items: [
    BottomNavigationBarItem(icon: Icon(Icons.menu), title: Text('menu')),
    BottomNavigationBarItem(icon: Icon(Icons.arrow_back), title: Text('back')),
  ]);
}

Widget _bottomAppBar() {
  return BottomAppBar(
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: <Widget>[
        IconButton(icon: Icon(Icons.menu), onPressed: null),
        IconButton(icon: Icon(Icons.arrow_back), onPressed: null),
      ],
    ),
  );
}

class PageOne extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: Hero(
        tag: 'bottomNavigationBar',
        child: _bottomAppBar(),
      ),
      body: Center(
        child: IconButton(
          iconSize: 200,
          icon: Icon(Icons.looks_two),
          onPressed: () => Navigator.push(
            context,
            MaterialPageRoute(builder: (context) => PageTwo()),
          ),
        ),
      ),
    );
  }
}

class PageTwo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: Hero(
        tag: 'bottomNavigationBar',
        child: _bottomAppBar(),
      ),
      body: Center(
        child: IconButton(
          iconSize: 200,
          icon: Icon(Icons.looks_one),
          onPressed: () => Navigator.pop(context),
        ),
      ),
    );
  }
}
void main(){
runApp(
材料聚丙烯(
主页:PageOne(),
),
);
}
小部件_bottomNavigationBar(){
返回底部导航栏(项目:[
BottomNavigationBarItem(图标:图标(Icons.menu),标题:文本(“菜单”),
BottomNavigationBarItem(图标:图标(Icons.arrow_back)),标题:文本(“back”),
]);
}
小部件_bottomAppBar(){
返回底部AppBar(
孩子:排(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
图标按钮(图标:图标(Icons.menu),ON按下:null),
图标按钮(图标:图标(图标。箭头返回),ON按下:null),
],
),
);
}
类PageOne扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回脚手架(
底部导航栏:英雄(
标记:“底部导航栏”,
子项:_bottomAppBar(),
),
正文:中(
孩子:我的钮扣(
iconSize:200,
图标:图标(图标。看起来像两个),
按下:()=>Navigator.push(
上下文
MaterialPageRoute(生成器:(上下文)=>PageTwo()),
),
),
),
);
}
}
类PageTwo扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回脚手架(
底部导航栏:英雄(
标记:“底部导航栏”,
子项:_bottomAppBar(),
),
正文:中(
孩子:我的钮扣(
iconSize:200,
图标:图标(图标。看起来像一个图标),
onPressed:()=>Navigator.pop(上下文),
),
),
);
}
}

问题似乎是导航堆栈中使用的动画。因此,在页面加载期间删除动画将停止此动画。在您的示例中,我将PageRouteBuilder添加到PageOne类中,以消除导航堆栈动画。使用下面的代码替换示例中的PageOne类

class PageOne extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: _bottomAppBar(),
      body: Center(
        child: IconButton(
          iconSize: 200,
          icon: Icon(Icons.looks_two),
          onPressed: () => Navigator.push(
            context,
            PageRouteBuilder(
              pageBuilder: (context, anim1, anim2) => PageTwo(),
              transitionsBuilder: (context, anim1, anim2, child) =>
                  Container(child: child),
            ),
          ),
        ),
      ),
    );
  }
}
还有其他方法可以控制导航动画
(哦,我去掉了Hero()小部件)

我解决了这个问题,在BottomAppBar中用一个Hero小部件将行包装起来。这仍然允许页面转换,并且不会按预期设置BottomAppBar的动画

BottomAppBar(
  child: Hero(
    tag: 'bottomAppBar',
    child: Material(
      child: Row(
        ...
      ),
    ),
  ),
);
但是,当使用循环的NotChedRectangle时,这会产生滞后的动画