微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何创建可在上/下/左/右挥动的窗口小部件?

如何解决如何创建可在上/下/左/右挥动的窗口小部件?

如何创建可以在上/下/左/右挥动的卡片?

我看到可以使用 PageView ,但这仅适用于上下左右方向。

那么如何结合所有方向来检测挥动中的Wigdet?

谢谢!

解决方法

您可以将“ PageView”用作另一个“ PageView”的子代:

class _TrainigState extends State<TrainingPage> {

  PageController hPagerController = PageController(keepPage: true);
  PageController vPagerController = PageController(keepPage: true);
  double mWidth;
  double mHeight;

  @override
  Widget build(BuildContext context) {

    mWidth = MediaQuery.of(context).size.width;
    mHeight = MediaQuery.of(context).size.height;
    return PageView(
      controller: hPagerController,children: [
        _verticalPageView([Colors.blue,Colors.purpleAccent,Colors.pinkAccent,Colors.orangeAccent]),_verticalPageView([Colors.yellow,Colors.orange,Colors.deepOrange,Colors.red]),_verticalPageView([Colors.green,Colors.lightGreenAccent,Colors.greenAccent,Colors.lightBlueAccent]),],);
  }

  Widget _verticalPageView(List colors) {
    return PageView(
      controller: vPagerController,scrollDirection: Axis.vertical,children: [
        Container(
          width: mWidth,height: mHeight,color: colors[0],),Container(
          width: mWidth,color: colors[1],color: colors[2],color: colors[3],);
  }

}

我希望它对您有用。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。