【问题标题】:Scroll horizontally not working on ListView水平滚动不适用于 ListView
【发布时间】:2022-01-04 03:16:33
【问题描述】:

我有以下问题,当我用完空间时,我想让我的列表视图可滚动。由于某种原因,它不起作用。我还尝试了带有 Row 孩子的 SingleChildScrollView。还是不行。

我尝试了所有可能的方法,但没有奏效。有什么建议吗?

附:我删除了一些代码,以便更容易跟踪。在完整版中,所有内容都包含在一个列中。

它是这样的:

代码:

body:
                    media.width < 1500
                        ? SingleChildScrollView(
                            scrollDirection: Axis.horizontal,
                            child: Wrap(
                              direction: Axis.vertical,
                              children: [
                                Row(children: [
                                  //1st Expansion Tile
                                  AttackExpansionTile(
                                      title: Text('Malware Attacks'),
                                      backgroundColor: Color(0xFF304e60),
                                      collapsedColor: Color(0xFF304e60),
                                      image: 'images/ransomware.png',
                                      smallImage: 'images/malware.png',
                                      subtitle: Text(
                                          'Malware usage is up almost 800% since early 2020.'),
                                      attackDefinition: Text(
                                          "One of the most used type of malware is Ransomware.\n"
                                          "Ransomware is a type of malware from cryptovirology that threatens to publish the victim's personal data or perpetually block access to it unless a ransom is paid."),
                                      finalParagraph: Text(
                                          "Ransomware is often spread through phishing emails that contain malicious attachments or through drive-by downloading. Drive-by downloading occurs when a user unknowingly visits an infected website and then malware is downloaded and installed without the user’s knowledge."
                                          "Crypto ransomware, a malware variant that encrypts files, is spread through similar methods and has also been spread through social media, such as Web-based instant messaging applications."
                                          " Additionally, newer methods of ransomware infection have been observed. For example, vulnerable Web servers have been exploited as an entry point to gain access to an organization’s network.")),

                                  //2nd Expansion Tile
                                  AttackExpansionTile(
                                      title: Text('Phising'),
                                      backgroundColor: Color(0xFF565462),
                                      collapsedColor: Color(0xFF565462),
                                      image: 'images/amazon.png',
                                      smallImage: 'images/phishing.png',
                                      subtitle: Text(
                                          'Phishing attacks are the most common cause of data breaches globally and have'
                                          ' been the root cause of notable instances of cybercrime in the last decade.'),
                                      attackDefinition: Text(
                                          'Phishing attacks attempt to steal information from users or trick them into downloading malware by'
                                          'sending malicious emails or text messages (SMS) that look like real requests but are, in fact, a Scam.\n'),
                                      finalParagraph: Text(
                                          'It occurs when an attacker, masquerading as a trusted entity, dupes a victim into opening '
                                          'an email, instant message, or text message. The recipient is then tricked into clicking a malicious link, '
                                          'which can lead to the installation of malware, the freezing of the system as part of a ransomware attack '
                                          'or the revealing of sensitive information.'
                                          'An attack can have devastating results. For individuals, this includes unauthorized purchases, the stealing of funds, or identify theft.'))
                                ])
                              ],
                            ))
                        : Container(),
                  ],
                )),
          ],
        )

【问题讨论】:

    标签: flutter flutter-web


    【解决方案1】:

    鼠标滚动行为在 2.5 上有所改变,您可以参考here

    您可以这样更改MaterialAppscrollBehavior

            scrollBehavior: ScrollConfiguration.of(context).copyWith(
              dragDevices: {
                PointerDeviceKind.touch,
                PointerDeviceKind.mouse,
              },
            ),
    

    【讨论】:

    • 我明天试试,然后告诉你。谢谢
    • 这不起作用
    【解决方案2】:

    所以,经过一番斗争,我找到了解决方案。 删除了 Wrap() 将 Row 包装在 SingleChildScrollView 中并将滚动方向设置为水平。谢谢大家。

    SingleChildScrollView(
                                scrollDirection: Axis.horizontal,
                                child: Row(children: [......]
    

    【讨论】:

      【解决方案3】:

      我不知道您为什么在 Wrap 小部件中包含 Row。这可能会使事情复杂化。

      并确保将RowmainAxisSize 属性设置为MainAxisSize.min,以便SingleChildScrollView 知道Row 的大小

      编辑:

      SCSV 的scrollDirection 应设置为Axis.horizontal

      【讨论】:

      • 我去掉了包装。我将 Row 包装在 SingleChildScrollView 中并设置了 mainAxisSize ,但我仍然遇到溢出问题并且它没有滚动
      • 确保将singleChildScrollView的滚动方向改为水平
      猜你喜欢
      • 2021-02-03
      • 2020-02-20
      • 2018-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-05
      相关资源
      最近更新 更多