简体   繁体   中英

Flutter - How to overflow horizontal listview?

DartPad

I'm building a website using Flutter Web. I have a horizontal ListView that shows items. I have a ConstrainedBox that sets the maxWidth to 1200. This cuts the ListView on both sides.

When I add the OverflowBox , ListView starts at the beginning of the page. How can I overflow it correctly that ListView begins where it should be and the rest of the items won't cut, so the user can scroll and see the items outside of the ConstrainedBox ?

在此处输入图像描述

with overflow: 在此处输入图像描述

Thanks to ping (pixeltoast) from the Flutter discord server, it's answered here .

   return SizedBox(
      height: 663,
      child: LayoutBuilder(
        builder: (context, constraints) {
          return ScrollConfiguration(
            behavior: _MyCustomScrollBehavior(),
            child: ListView.separated(
              padding: EdgeInsets.symmetric(horizontal: max(0.0, (constraints.maxWidth - 800) / 3)),
              controller: _controller,
              scrollDirection: Axis.horizontal,
              itemCount: items.length,
              separatorBuilder: (_, __) => const SizedBox(width: 16),
              itemBuilder: (_, i) => items[i],
            ),
          );
        }
      ),
    );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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