Flutter 颤振旋转杯形吸管

Flutter 颤振旋转杯形吸管,flutter,dart,cupertinopicker,Flutter,Dart,Cupertinopicker,有没有办法让CupertinoPicker在颤振状态下旋转90度?这样您可以水平拾取,而不是垂直拾取。Transform.rotate不是一个选项,因为此时选择器的宽度限制为父窗口小部件的高度。或者有什么好方法可以强迫cupertino选择器比它的父小部件大?小部件怎么样 RotatedBox( 四分之一轮:1, 儿童:CupertinoPicker(…), ) 与仅在绘制之前应用变换的“变换”不同,此对象在布局之前应用其旋转,这意味着整个旋转的长方体仅消耗旋转子体所需的空间 所以我找到了两个

有没有办法让CupertinoPicker在颤振状态下旋转90度?这样您可以水平拾取,而不是垂直拾取。Transform.rotate不是一个选项,因为此时选择器的宽度限制为父窗口小部件的高度。或者有什么好方法可以强迫cupertino选择器比它的父小部件大?

小部件怎么样

RotatedBox(
四分之一轮:1,
儿童:CupertinoPicker(…),
)
与仅在绘制之前应用变换的“变换”不同,此对象在布局之前应用其旋转,这意味着整个旋转的长方体仅消耗旋转子体所需的空间


所以我找到了两个解决方案。首先,可以使用旋转框。谢谢你的建议。2.解决方案:制作一个完整的自定义选择器。因此,如果有人有同样的问题,你可以使用我的自定义选择器。代码乱七八糟,请不要评判lmao

class CustomPicker extends StatefulWidget {
  CustomPicker(
      {@required double this.width,
      @required double this.height,
      @required double this.containerWidth,
      @required double this.containerHeight,
      @required double this.gapScaleFactor,
      @required List<Widget> this.childrenW,
      Function(int) this.onSnap});

  double width;
  double height;
  double containerWidth;
  double containerHeight;
  double gapScaleFactor;
  List<Widget> childrenW;
  Function(int) onSnap;

  _CustomPicker createState() => _CustomPicker(width, height, containerWidth,
      containerHeight, gapScaleFactor, childrenW, onSnap);
}

class _CustomPicker extends State<CustomPicker>
    with SingleTickerProviderStateMixin {
  AnimationController controller;
  double width;
  double height;
  double containerWidth;
  double containerHeight;
  double gapScaleFactor;
  double currentScrollX = 0;
  double oldAnimScrollX = 0;
  double animDistance = 0;
  int currentSnap = 0;
  List<Widget> childrenW;
  List<Positioned> scrollableContainer = [];
  final Function(int) onSnap;

  int currentPos;
  _CustomPicker(
      double this.width,
      double this.height,
      double this.containerWidth,
      double this.containerHeight,
      double this.gapScaleFactor,
      List<Widget> this.childrenW,
      Function(int) this.onSnap) {
    initController();
    init();
  }

  void initController() {
    controller = AnimationController(
      vsync: this,
      duration: Duration(milliseconds: 200),
      lowerBound: 0,
      upperBound: 1,
    )..addListener(() {
        setState(() {
          currentScrollX = oldAnimScrollX + controller.value * animDistance;
          init();
        });
      });
  }

  void init() {
    scrollableContainer.clear();
    if (currentScrollX < 0) {
      currentScrollX = 0;
    }
    double scrollableLength =
        (containerWidth + containerWidth * gapScaleFactor) *
                (childrenW.length) -
            containerWidth * gapScaleFactor;

    if (currentScrollX > scrollableLength - containerWidth) {
      currentScrollX = scrollableLength - containerWidth;
    }
    for (int i = 0; i < childrenW.length; i++) {
      double leftPos = width / 2 -
          containerWidth / 2 -
          currentScrollX +
          containerWidth * i +
          containerWidth * gapScaleFactor * i;
      double mid = width / 2 - containerWidth / 2;
      double topPos = containerHeight *
          0.9 *
          ((leftPos - mid).abs() / scrollableLength) /
          2;
      scrollableContainer.add(Positioned(
          //calculate X position
          left: leftPos,
          top: topPos,
          child: Container(
            height: containerHeight -
                containerHeight *
                    0.9 *
                    ((leftPos - mid).abs() / scrollableLength),
            width: containerWidth -
                containerWidth *
                    0.9 *
                    ((leftPos - mid).abs() / scrollableLength),
            child: childrenW[i],
          )));
    }
  }

  void lookForSnappoint() {
    double distance = 1000000;
    double animVal = 0;
    int index = -2032;
    for (int i = 0; i < scrollableContainer.length; i++) {
      double snappoint = width / 2 - containerWidth / 2;
      double currentLeftPos = width / 2 -
          containerWidth / 2 -
          currentScrollX +
          containerWidth * i +
          containerWidth * gapScaleFactor * i;
      if ((currentLeftPos - snappoint).abs() < distance) {
        distance = (currentLeftPos - snappoint).abs();
        animVal = currentLeftPos - snappoint;
        index = i;
      }
    }
    animDistance = animVal;
    oldAnimScrollX = currentScrollX;
    controller.reset();
    controller.forward();
    this.onSnap(index);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: widget.width,
      height: widget.height,
      child: GestureDetector(
        onPanUpdate: (DragUpdateDetails dragUpdateDetails) {
          setState(() {
            this.currentScrollX -= dragUpdateDetails.delta.dx;
            init();
          });
        },
        onPanEnd: (DragEndDetails dragEndDetails) {
          lookForSnappoint();
        },
        behavior: HitTestBehavior.translucent,
        child: LayoutBuilder(builder: (context, constraint) {
          return Container(
            child: Stack(
              children: <Widget>[
                Stack(children: scrollableContainer),
              ],
            ),
          );
        }),
      ),
    );
  }
}
类CustomPicker扩展StatefulWidget{
顾客选择者(
{@需要此宽度的两倍,
@需要两倍于此高度,
@需要将此集装箱宽度加倍,
@需要双倍于此。集装箱重量,
@需要将此值加倍。间隙比例系数,
@必须列出此.childrenW,
函数(int)this.onSnap});
双倍宽度;
双高;
双集装箱宽度;
双集装箱重量;
双间隙因子;
列出儿童名单;
函数(int)onSnap;
_CustomPicker createState()=>\u CustomPicker(宽度、高度、容器宽度、,
容器重量、间隙比例因子、儿童、睡眠);
}
类\u CustomPicker扩展状态
使用SingleTickerProviderStateMixin{
动画控制器;
双倍宽度;
双高;
双集装箱宽度;
双集装箱重量;
双间隙因子;
双电流X=0;
双精度X=0;
双倍距离=0;
int currentSnap=0;
列出儿童名单;
列表scrollableContainer=[];
最终功能(int)onSnap;
int-currentPos;
_顾客选择者(
这个宽度加倍,
双倍于这个高度,
把这个翻一倍,集装箱宽度,
把这个翻一倍,集装箱的重量,
把这个翻一番,gapScaleFactor,
列出这个。childrenW,
函数(int)this.onSnap){
initController();
init();
}
void initController(){
控制器=动画控制器(
vsync:这个,,
持续时间:持续时间(毫秒:200),
lowerBound:0,
上限:1,
)…addListener(){
设置状态(){
currentScrollX=oldAnimScrollX+controller.value*animDistance;
init();
});
});
}
void init(){
scrollableContainer.clear();
如果(currentScrollX<0){
currentScrollX=0;
}
双滚动长度=
(集装箱宽度+集装箱宽度*间隙比例系数)*
(儿童长度)-
集装箱宽度*间隙比例系数;
如果(currentScrollX>scrollableLength-containerWidth){
currentScrollX=scrollableLength-容器宽度;
}
for(int i=0;i