如何在ListView中使用Flutter SingleChildScroll视图?

ikfrs5lh  于 2023-05-08  发布在  Flutter
关注(0)|答案(1)|浏览(160)

如何在ListView中使用SingleChildScroll视图?
这是我当前的实现

ListView(
          shrinkWrap: true,
          children: [
            SingleChildScrollView(
              scrollDirection: Axis.horizontal,
              child: Row(
                children: [
                  Card(
                    child: Container(
                      padding: const EdgeInsets.all(12),
                      color: Colors.orange,
                      width: 300,
                      child: const Text('Hello'),
                    ),
                  ),
                  Card(
                    child: Container(
                      padding: const EdgeInsets.all(12),
                      color: Colors.orange,
                      width: 300,
                      child: const Text('Sample events'),
                    ),
                  ),
                ],
              ),
            ),
            //... more widgets here
          ],
        );

但是当我水平滚动的时候我得到了这个错误

@pragma("vm:external-name", "AssertionError_throwNew")
  external static _doThrowNew(
      int assertionStart, int assertionEnd, Object? message);
  @pragma("vm:external-name", "AssertionError_throwNewSource")
  external static _doThrowNewSource(
      String failedAssertion, int line, int column, Object? message);

这是我想要解决的设计。

t2a7ltrp

t2a7ltrp1#

我正在努力解决您的问题:

physics:BouncingScrollPhysics(),

ListView(
      children: [
        Container(
          height: 200,
          child: SingleChildScrollView(
            physics: BouncingScrollPhysics(),
            scrollDirection: Axis.horizontal,
            child: Row(
              children: [
                Container(
                  width: 300,
                  color: Colors.orange,
                  child: const Text('Hello'),
                ),
                Container(
                  width: 300,
                  color: Colors.orange,
                  child: const Text('Sample events'),
                ),
              ],
            ),
          ),
        ),
        //... more widgets here
      ],
    );

相关问题