Tạo danh sách cuộn ngang trong Flutter?

Mình muốn tạo một ListView cuộn ngang, hay một slide ngang trong Flutter thì nên làm gì hay cần package gì không ad?

Giải pháp

Có một cách rất đơn giản mà bạn không cần phải dùng packages nào hết bằng cách sử dụng horizontal list. Hãy thử xem ví dụ mẫu sau đây:

ListView(
  // This next line does the trick.
  scrollDirection: Axis.horizontal,
  children: <Widget>[
    Container(
      width: 160.0,
      color: Colors.red,
    ),
    Container(
      width: 160.0,
      color: Colors.blue,
    ),
    Container(
      width: 160.0,
      color: Colors.green,
    ),
    Container(
      width: 160.0,
      color: Colors.yellow,
    ),
    Container(
      width: 160.0,
      color: Colors.orange,
    ),
  ],
)

Kết quả mong muốn như sau, hoặc xem live preview:




Từ khóa

List of horizontal list in Flutter

1 nhận xét: