Transform.rotate的扑动角度值不会改变,也不会更新状态。

问题描述 投票:0回答:1

这是我的代码

class TitleGreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
print('title green buile');
return  Positioned(
    key:  UniqueKey(),
    top: 0.0,
    child: GestureDetector(
        onTap: () {
          Provider.of<MoveDetailsDesVisibility>(context)
              .setViisibility(1, context);
        },
        child: AnimatedContainer(
          key:  UniqueKey(),
          duration: Duration(seconds: 0),
          padding: EdgeInsets.only(
              top: Provider.of<MoveDetailsDesVisibility>(context)
                  .des2visibility
                  ? (1 / 4) * height + 225
                  : (1 / 4) * height + 115),

          height: Provider.of<MoveDetailsDesVisibility>(context)
              .des2visibility
              ? (1 / 4) * height + 260
              : (1 / 4) * height + 150,
          //150
          width: (3 / 4) * width - 11.5,
          decoration: BoxDecoration(
              color: Color(0xFF24DC25),
              borderRadius:
              BorderRadius.only(bottomLeft: Radius.circular(30))),
          child: Column(
            children: <Widget>[
              Row(
                children: <Widget>[
                  SizedBox(
                    width: 5,
                  ),

                  Transform.rotate(
                      key:  UniqueKey(),
                      angle: Provider.of<MoveDetailsDesVisibility>(context)
                          .des2visibility?-80:0,
                      child:
                      Image.asset(
                        'assets/icons/faNote.png',
                        fit: BoxFit.cover,
                        width: 20,
                        height: 20,
                      )),
                  SizedBox(
                    width: 9,
                  ),
                  Text(
                    'توضیحات مربی',
                    style: TextStyle(
                        color: Colors.white,
                        fontSize: 14,
                        fontWeight: FontWeight.bold),
                  )
                ],
              ),

            ],
          ),
        )));
   }
}

在这段代码中,当我更新提供者并改变提供者的值时,整个widget类被调用,构建方法被调用,但这个检查 "des2visibility "的值是false还是true的代码没有被调用,图像widget没有转换,而整个widget构建的地方是不正确的。

flutter provider state-management
1个回答
0
投票

这是一个无状态的小部件,你应该使用有状态的小部件Titlegen。

© www.soinside.com 2019 - 2024. All rights reserved.