我想删除动画,只是打印result
,但我不知道如何从这个result
中删除动画这里是result
所在的位置:
onPressed: () => Navigator.of(context).push(MaterialPageRoute(
builder: (context) => NextPage(
result: (something + other_thing)
我是这样打印的:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ValueListenableBuilder<String>(
valueListenable: _animation,
builder: (context, value, child) {
return Text(
'The result is $value', //It has to print the result here, but without any animations
style: Theme.of(context).textTheme.headline5,
textAlign: TextAlign.center,
);
},
),
],
),
),
);
}
}
我想知道我是否需要删除这个ValueListenableBuilder,但我不知道如何从上面的代码访问result
。
除非您需要使用ValueListenableBuilder,否则您可以使用Navigator.push
来帮助您在不使用动画的情况下在不同屏幕之间移动数据。如果你不知道Navigator是如何工作的,这里有一个简单的视频来解释它是如何工作的。https://www.youtube.com/watch?v=NT3XakU4Dcw
在引擎盖下,navigator为每个动作执行动画。所以只要将持续时间设置为0就可以移除动画
Navigator.pushReplacement(
context,
PageRouteBuilder(
pageBuilder: (_, _, _) => MyPage(),
transitionDuration: const Duration(seconds: 0), // here disabling animation
));