将RTL添加到ListView.builder水平抖动

时间:2019-09-08 02:10:37

标签: flutter

我正在尝试使ListView.builder从右向左水平滚动

我的代码:

SliverToBoxAdapter(
  child: Container(
    height: MediaQuery.of(context).size.height / 4.5,
    margin: const EdgeInsets.only(bottom: 5.0, top: 10.0),
    child: ListView.builder(
      scrollDirection: Axis.horizontal,
      itemCount: list.length,
      itemBuilder: (BuildContext context, int index) {
        return InkWell(/* ... */)
      }
    ),
  ),
);

2 个答案:

答案 0 :(得分:1)

您只需要向ListView添加反向参数

这是一个示例:

ListView.builder(
    reverse: true,
    scrollDirection: Axis.horizontal,
    itemCount: list.length,
    itemBuilder: (context, position) {
      return Padding(
        padding: const EdgeInsets.all(8.0),
        child: Container(
          child: Text(list[position]),
          color: Colors.grey,
          height: 10,
          width: 10,
        ),
      );
    },
  )

答案 1 :(得分:0)

用于水平

ListView.builder(
    reverse: true,
    scrollDirection: Axis.horizontal,

垂直

ListView.builder(
    reverse: true,
    scrollDirection: Axis.vertical,