首页 > 解决方案 > 如何在 Flutter 中删除动画?

问题描述

我想删除动画并打印,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从上面的代码中访问。

标签: androidflutterdartmobile

解决方案


除非您需要使用 ValueListenableBuilder,否则您可以使用它Navigator.push来帮助您在不同屏幕之间移动数据而无需动画。如果您不知道 Navigator 的工作原理,这里有一个简单的视频来解释它的工作原理。https://www.youtube.com/watch?v=NT3XakU4Dcw


推荐阅读