首页 > 解决方案 > 动画切换器的内部小部件状态更改

问题描述

我现在正在使用 AnimatedSWitcher,它工作得很好但是如何更改 Animated Switcher 小部件内部的状态我的代码是这样的:

                    void initstate(){
                   _layout=first();
                       }
                  first(){
            return InkWell(onTap:() 
            {
             setState(()
           {_layout=second();}); 
                  child:
         Row( 
           children:[
           Text("example"), 
           ...(other widgets)
              ]);


               second(){
            return InkWell(onTap:() 
            {
             setState(()
           {_layout=first();}); 
                  child:
         Row( 
           children:[
            Text("second example"),
         ]);

         @override
           Widget build(BuildContext context) {
              ...,
                  AnimatedSwitcher(duration: const Duration(milliseconds: 300),

                  transitionBuilder:
                      (Widget child, Animation<double> animation) {
                    return ScaleTransition(child: child, scale: animation);
                  },
                  child: _layout,
                ),
         }

在某处我有按钮来更改第一个布局中的文本,但是这个 setState 不起作用。我的问题是如何更改 AnimatedSwitcher 的文本内部小部件

标签: flutterflutter-animation

解决方案


推荐阅读