简体   繁体   English

在 Flutter 中创建可水平和垂直滚动的小部件

[英]Creating a widget that is both horizontally and vertically scrollable in Flutter

I would like to have a widget that can be scrolled both horizontally and vertically at the same time.我想要一个可以同时水平和垂直滚动的小部件。 I would place widgets in them that are larger that the viewport.我会在其中放置比视口更大的小部件。 It can be Container of height and width larger than that of the Screen.它可以是高度和宽度大于屏幕的容器。 For eg if image is larger that screen the i can scroll it to view top, left, bottom and right parts Thanks in Advance.例如,如果图像比屏幕大,我可以滚动它以查看顶部、左侧、底部和右侧部分,在此先感谢。

Maybe a solution might be to put a listView inside another ListView and change its scrool direction... For example:也许一个解决方案可能是将一个 listView 放在另一个 ListView 中并改变它的滚动方向......例如:

ListView(
   shrinkWrap: true,
   primary: true,
   children: <Widget>[
       ListView(
         shrinkWrap: true,
         primary: false,
         scrollDirection: Axis.horizontal,
         children: <Widget>[
            Container(
              width: MediaQuery.of(context).size.width*2,
              height: MediaQuery.of(context).size.height*2,
            ),
         ],
       )
     ],
   ),

Not tested, just trying to help...没有测试,只是想帮助...

This sounds similar to: Multidirectional scroll in flutter这听起来类似于: flutter 中的多向滚动

But maybe the following plugin might be what you want: https://pub.dev/packages/bidirectional_scroll_view但也许以下插件可能是您想要的: https://pub.dev/packages/bidirectional_scroll_view

And if you want a deep dive, this is also being discussed in the gitrepo from Flutter: https://github.com/flutter/flutter/issues/20175如果你想深入了解,这也在 Flutter 的 gitrepo 中进行了讨论: https://github.com/flutter/flutter/issues/20175

I am not sure why you would want this exactly, but it might not make sense having such a big image in a mobile context.我不确定你为什么会想要这个,但在移动环境中拥有如此大的图像可能没有意义。 That being said I can imagine it would happen in the context of, for example, a zoom into the photo.话虽如此,我可以想象它会在例如放大照片的情况下发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM