Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.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 通过在flatter中将不透明度设置为0并返回到1来更改文本小部件的值_Animation_Flutter_Opacity_Flutter Animation - Fatal编程技术网

Animation 通过在flatter中将不透明度设置为0并返回到1来更改文本小部件的值

Animation 通过在flatter中将不透明度设置为0并返回到1来更改文本小部件的值,animation,flutter,opacity,flutter-animation,Animation,Flutter,Opacity,Flutter Animation,我如何在颤振中执行此操作: 当按下FloatingActionButton时,我想更新Text小部件的值: 将文本小部件的不透明度设置为0,持续1秒(隐藏旧值) 更改文本小部件的值(设置新值-设置状态?) 将文本小部件的不透明度设置为1,持续1秒(显示新值) 我可以使用AnimatedOpacity执行此操作吗?是的,您可以,请不要忘记在调用第二个setState重新激活文本之前等待 String text = 'Text Initial'; double opacity = 1.0

我如何在颤振中执行此操作:

当按下
FloatingActionButton
时,我想更新
Text
小部件的值:

  • 文本
    小部件的不透明度设置为0,持续1秒(隐藏旧值)
  • 更改
    文本
    小部件的值(设置新值-
    设置状态
    ?)
  • 文本
    小部件的不透明度设置为1,持续1秒(显示新值)

我可以使用
AnimatedOpacity
执行此操作吗?

是的,您可以,请不要忘记在调用第二个setState重新激活文本之前等待

  String text = 'Text Initial';
  double opacity = 1.0;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        floatingActionButton: FloatingActionButton(
          onPressed: () async {
            setState(() {
              opacity = 0.0;
            });
            await Future.delayed(const Duration(seconds: 1));
            setState(() {
              text = 'New Text';
              opacity = 1.0;
            });
          },
        ),
        body: Center(
          child: AnimatedOpacity(
            duration: const Duration(seconds: 1),
            opacity: opacity,
            child: Text(text),
          ),
        ),
      ),
    );
  }