How can I rotate a Container widget in 2D around a specified anchor point?

后端 未结 4 2067
余生分开走
余生分开走 2021-02-05 09:44

I\'d like to perform a very simple 2D rotation of a Container widget (that contains a handful of other widgets.) This widget would be rotated around a single fixed point in the

4条回答
  •  感动是毒
    2021-02-05 09:54

    For those who want to make an app like me, just using Transform and Gesturedetector. And remember don't use Draggable and Gesturedetector together because you only can drag and drop but you can't zooming widget :)).

    Refer: A Deep Dive Into Transform Widgets in Flutter

    barbswatanabe

    :

                 Transform.rotate(
                      alignment: FractionalOffset.center,
                      angle: state.listStickerModel[index].angle,
                      child: Transform(
                        alignment: FractionalOffset.center,
                        transform: new Matrix4.diagonal3(vector.Vector3(
                            state.listStickerModel[index].zoom,
                            state.listStickerModel[index].zoom,
                            state.listStickerModel[index].zoom)),
                        child: GestureDetector(
                          onScaleStart: (detail) {
                            _editPhotoBloc.add(UpdateSticker(
                              index: index,
                              offset: detail.focalPoint,
                              previousZoom: state.listStickerModel[index].zoom,
                            ));
                          },
                          onScaleUpdate: (detail) {
                            _editPhotoBloc.add(UpdateSticker(
                                index: index,
                                offset: Offset(detail.localFocalPoint.dx,
                                    detail.focalPoint.dy),
                                angle: detail.rotation,
                                zoom:
                                    state.listStickerModel[index].previousZoom *
                                        detail.scale));
                          },
                          child: Container(
                            alignment: Alignment.center,
                            child: SvgPicture.asset(
                                state.listStickerModel[index].src),
                          ),
                        ),
                      ),
                    ),
    

提交回复
热议问题