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

Bài đăng

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

Widget Previews đã stable: sửa UI không cần chạy cả app

Chạy cả app chỉ để sửa một nút rất chậm. Widget Preview render widget riêng lẻ cách ly. Sau các bản experimental, nó stable trong Flutter 3.47 . Stable nghĩa là gì Khởi động nhanh nhờ cache local .widget_preview/ . PreviewThemeData để layer theme tuần tự (ma trận test theo seed/contrast). Tự đồng bộ asset web/ khi preview widget web. Workflow đáng tiền Tách widget đang sửa thành class preview được. Thêm preview cho mặc định / dark / chữ to / data rỗng. Lặp tới khi preview nhàm chán — rồi mới ghép vào app. Đây cũng là vòng nhanh nhất cho design-system trên material_ui / catalog tùy chỉnh. Cạm bẫy Preview đụng dart:io hoặc platform channel sẽ không chạy — giữ UI thuần. Đừng nhét business logic vào preview; chỉ fixture. Bài viết gốc đăng tại FlutterCook . Bản trên đó là bản được cập nhật mới nhất.

Widget Previews are stable: iterate on UI without booting the whole app

Booting a full app to tweak a button is slow. Widget Preview renders individual widgets in isolation. After experimental cycles, it is stable in Flutter 3.47 . What stable means here Faster startup via a local .widget_preview/ cache. PreviewThemeData for sequential theme layering (matrix tests across seeds/contrast). Automatic web/ asset sync when previewing web widgets. Workflow that pays off Extract the widget you are changing into a previewable class. Add previews for default / dark / large-text / empty-data. Iterate until the preview is boring — then wire it into the app. This is also the fastest loop for design-system work on material_ui / custom catalogs. Pitfalls Previews that hit dart:io or platform channels will not run — isolate pure UI. Do not put business logic in previews; put fixtures there. Originally published on FlutterCook . Read the latest version there — that copy is the one kept up to date.