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

Bài đăng

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

flutter_bloc: explicit events and states at scale

flutter_bloc: explicit events and states at scale flutter_bloc is useful because it focuses on Cubit, Bloc, BlocListener, and predictable state transitions. The important engineering move is to place the package behind a clear boundary, so your Flutter UI depends on a stable capability rather than a vendor-shaped API. What the library should own Keep package calls inside a named adapter or feature boundary. Make lifecycle, errors, and loading state part of a testable contract. Expose only the capability the app needs; hide implementation details from the whole tree. A focused starting point sealed class CheckoutState {} final class CheckoutIdle extends CheckoutState {} final class CheckoutSubmitting extends CheckoutState {} final class CheckoutDone extends CheckoutState {} class CheckoutCubit extends Cubit < CheckoutState > { CheckoutCubit ( this .repository) : super ( CheckoutIdle ()); final CheckoutRepository repository; Future ...

Riverpod, Bloc, signals hay setState: chọn cách quản lý state Flutter và sống chung với nó

Mọi bài so sánh quản lý state trong Flutter đều là một danh sách tính năng. Riverpod có provider an toàn ở compile time. Bloc có luồng dữ liệu một chiều kèm event log. signals có reactivity chi tiết tới từng giá trị. Đúng hết, và vô dụng hết — danh sách tính năng cho bạn biết một thư viện có gì , không bao giờ cho biết nó tốn gì khi người bảo trì đoạn code đó không phải là bạn. Cách nhìn hữu ích hơn: mỗi thư viện đang trả lời một câu hỏi khác nhau. Nếu câu hỏi đó không phải câu hỏi app của bạn đang đặt ra, thì tính năng của nó chỉ là chi phí bạn trả bằng thời gian review và thời gian onboard người mới. Nên thay vì liệt kê tính từ, bài này viết cùng một tính năng bốn lần — một màn hình load danh sách, hiển thị trạng thái loading, error, data và hỗ trợ pull-to-refresh — rồi đọc phần khác nhau. Nói luôn phần không được lòng ai: setState cộng với ValueNotifier và InheritedWidget là đủ cho rất nhiều app production, và tài liệu chính thức của Flutter cũng vạch ranh giới theo hướng đó....

Riverpod, Bloc, signals or setState: choosing Flutter state management and living with it

Every Flutter state management comparison is a feature checklist. Riverpod has compile-safe providers. Bloc has a unidirectional event log. signals has fine-grained reactivity. All true, all useless — a checklist tells you what a library has and never what it costs when the person maintaining that code is not you. The more useful framing is that each of these libraries answers a different question. If the question it answers is not one your app is asking, its features are overhead you pay for in review time and onboarding. So instead of tabulating adjectives, this article writes the same feature four times — one screen that loads a list, shows loading, error and data states, and supports pull-to-refresh — and then reads the diff. I will say the unpopular part up front: setState plus ValueNotifier and InheritedWidget is enough for a lot of production apps, and Flutter’s own documentation draws that line too. There is a real point where it stops being enough. That point is not “t...