Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a UiState class for the architecture pages #11437

Open
1 task
alefwd opened this issue Nov 24, 2024 · 0 comments
Open
1 task

Introduce a UiState class for the architecture pages #11437

alefwd opened this issue Nov 24, 2024 · 0 comments
Labels
from.page-issue Reported in a reader-filed concern

Comments

@alefwd
Copy link

alefwd commented Nov 24, 2024

Page URL

https://docs.flutter.dev/app-architecture/guide

Page source

https://github.com/flutter/website/blob/main/src/content/app-architecture/guide.md

Describe the problem

Similarly to Android Architecture Components, the UI layer should introduce a well defined UiState class.
The use of a UiState class has many benefits, as it allows a clear declaration of what is part of the UI state, it helps reasoning about it and it helps handling it, without having the code scattered into another class.

Here one example of a generic UiState class I use (with freezed):

@freezed
class AlePageUiState with _$AlePageUiState {
  const factory AlePageUiState({
    @Default([]) List<ItemUiState> items,
    @Default(false) bool loading,
    @Default(false) bool error,
    @Default('') String errorMsg,
  }) = _AlePageUiState;
}

The UI state class doesn't necessarily need to include the loading and error, but keeping them included helps to represent better the formula:

UI = f ( state )

because anything that change the UI has to originate from a change in the state, including the loading state where we usually want to show a loading indicator and the error state where we usually want to show a snackbar.
Having them included in the UiState class helps to reason in terms of a (in)finite state machine:

Gc0EfiUXIAAC3x2

All the material taken from here, where you can find also a code repository, a video and the slides.

Expected fix

Adding a section titled "Defining the UI state" or similar.

Additional context

No response

I would like to fix this problem.

  • I will try and fix this problem on docs.flutter.dev.
@alefwd alefwd added the from.page-issue Reported in a reader-filed concern label Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
from.page-issue Reported in a reader-filed concern
Projects
None yet
Development

No branches or pull requests

1 participant