Chuyển đến nội dung chính

Bài đăng

Hiển thị các bài đăng có nhãn Lists

Pagination and infinite scroll without layout jank — hướng dẫn Flutter

Feeds are the most common jank source. Paginate and set itemExtent when fixed. Bài này chuyển quan sát đó thành một mô hình nhỏ để bạn có thể kiểm thử, đo lường và giữ cho code dễ bảo trì khi app lớn lên. Vấn đề cốt lõi Cursor APIs, item extents, and loading states that do not thrash. Câu hỏi hữu ích không phải API hay pattern có đẹp riêng lẻ hay không, mà là state nằm ở đâu, boundary nào chịu trách nhiệm khi lỗi xảy ra, và người dùng phục hồi thế nào khi happy path biến mất. Mô hình thực tế Keep loading indicators out of the list path when possible. Hãy bắt đầu bằng một owner rõ ràng cho behavior. Widget chỉ nên render và phát intent; IO, persistence, permission và retry nên nằm sau một interface nhỏ. Nhờ vậy bạn có seam để fake trong test và một chỗ ghi lại các dữ kiện cần theo dõi ở production. Trong app Flutter, boundary thường có dạng: Widget phát intent như load, submit, refresh hoặc retry. Controller hoặc use case validate intent rồi gọi boundary. Boundary trả về data...

Pagination and infinite scroll without layout jank

Feeds are the most common jank source. Paginate and set itemExtent when fixed. This article turns that observation into a small implementation model you can test, measure, and keep boring when the app grows. The problem in one sentence Cursor APIs, item extents, and loading states that do not thrash. The useful question is not whether the API or pattern looks elegant in isolation. It is where state lives, which boundary owns failure, and how a user recovers when the happy path disappears. A practical model Keep loading indicators out of the list path when possible. Start with one explicit owner for the behavior. Keep widgets responsible for rendering and user intent; keep IO, persistence, permissions, and retries behind a small interface. That gives you a seam for a fake in tests and a place to record the facts that matter in production. For a Flutter app, the boundary usually looks like this: The widget emits an intent such as load, submit, refresh, or retry. A controller or...

Jetpack Compose: Lists

  Hai cách chúng ta có thể triển khai Lists trong Jetpack Compose. Lưu ý: Tôi đang sử dụng Jetpack Compose phiên bản 0.1.0-dev08 tại thời điểm viết bài này. Sử dụng AdapterList Chúng ta có thể sử dụng AdapterList composable - nó tương đương với RecyclerViews + RecyclerViewAdapters - nhưng với ít mã hơn đáng kể 😍 Phương thức khởi tạo AdapterList nhận dữ liệu, là danh sách các mục bạn muốn hiển thị và chuyển các mục riêng lẻ đến lambda. Ở đó bạn có thể xác định mục danh sách. Hiện tại, nó chỉ giới hạn ở việc cuộn dọc. Điều này có thể thay đổi trong các bản phát hành trong tương lai. Multiple Types Chúng ta có thể dễ dàng phân biệt giữa các loại chế độ xem khác nhau - chỉ cần thêm điều kiện if. Dưới đây là một ví dụ nếu chúng tôi muốn hiển thị một tiêu đề ở đầu danh sách: 2.Using Vertical and Horizontal Scrollers Một cách khác để triển khai danh sách là sử dụng các Scrollers đơn giản - những công cụ này sẽ không sử dụng các chế độ xem tái chế. Vì vậy, không thực sự lý tưởng cho lists...