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

Refactor state management for other screens #335

Conversation

durannumit
Copy link
Collaborator

Description

Applied new state management approach to other screens and view models

@durannumit durannumit requested a review from ulusoyca October 27, 2024 18:21
@durannumit durannumit self-assigned this Oct 27, 2024

class LoginScreenContent extends StatelessWidget {
const LoginScreenContent({super.key, required this.onLoginPressed});
final LoginScreenViewModel viewModel;
Copy link
Collaborator

@ulusoyca ulusoyca Oct 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The descendent widgets should not know about the view model. We should pass the value listenable from the viewmodel through the root widget.


final AuthService _authService;

final _loginState = StatefulValueNotifier<bool>.idle(false);
Copy link
Collaborator

@ulusoyca ulusoyca Oct 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's simplify this by removing the state concept. We can simply name this as isLoggedIn.

_viewModel.onLoginPressed(email, password);
},
);
return LoginScreenContent(viewModel: _viewModel);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The descendents should never have dependency to the ViewModel

@@ -0,0 +1,52 @@
import 'package:coffee_maker_navigator_2/features/add_water/domain/entities/water_source.dart';

class AddWaterState {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new approach aims to avoid creating separate State classes. We should avoid combining multiple fields in one class. For example, the footer widget only depends on errorMessage and isReadyToAddWater and it should not be re-built when waterSource for example changes.

@durannumit durannumit requested a review from ulusoyca November 3, 2024 12:05
@ulusoyca ulusoyca merged commit af87ce3 into woltapp:state-management-experiments-in-demo-app Nov 20, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants