【问题标题】:How to make the card rotate after the condition is met automatically?条件满足后如何让卡片自动旋转?
【发布时间】:2021-09-06 10:25:08
【问题描述】:
Widget buildTarget(CardItem? item) {
    if (item != null) {
      return Transform(
          alignment: FractionalOffset.center,
          transform: Matrix4.identity()
            ..setEntry(3, 2, 0.002)
            ..rotateY(pi*0.5),
          child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: ClipRRect(
              child: Container(
                height: 150,
                width: 150,
                color: Colors.white,
                child:Center(child: Image.asset(item.imageUrl)),
              ),
            ),
          ));
    } else {
      return Text('Errors');
    }
  

【问题讨论】:

    标签: flutter if-statement flip card


    【解决方案1】:
    double _rotateFactor = 0.5;
    
    void _changeAngle(double factor){
      _rotateFactor = factor;
      setState((){});
    }
    
    ...
    
    Widget buildTarget(CardItem? item) {
        if (item != null) {
          return Transform(
              alignment: FractionalOffset.center,
              transform: Matrix4.identity()
                ..setEntry(3, 2, 0.002)
                ..rotateY(pi*_rotateFactor),
              child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: ClipRRect(
                  child: Container(
                    height: 150,
                    width: 150,
                    color: Colors.white,
                    child:Center(child: Image.asset(item.imageUrl)),
                  ),
                ),
              ));
        } else {
          return Text('Errors');
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-25
      • 2021-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多