Menu

Post image 1
Post image 2
1 / 2
0

Flutter Bloc Async State: Stop Modeling Data With Nulls and Loading Flags

DEV Community: dart·Konstantin Voronov·3 days ago
#hKSF6116
#dev#fullscreen#state#error#enter#article
Reading 0:00
15s threshold

Flutter apps rarely start with complicated state. At first, a Bloc or Cubit state often looks harmless: class KidState { final Kid ? kid ; final bool isLoading ; final StateError ? error ; const KidState ({ required this . kid , required this . isLoading , required this . error , }); } Enter fullscreen mode Exit fullscreen mode This works until the screen becomes real. You add initial loading. Then pull-to-refresh. Then a cached value. Then an empty state. Then an error that should not erase the old content. Then a retry. Then one more field with the same lifecycle. Now the state is not simple anymore. It is implicit. // What does this mean? kid != null && isLoading && error != null Enter fullscreen mode Exit fullscreen mode Is the kid loaded? Is the screen refreshing? Did the refresh fail? Should the UI show the old kid, the error, or a full-screen loader? The problem is not Bloc. The problem is that the data lifecycle is hidden behind nulls and flags. That distinction matters for adoption.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More