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

Futurize with statemixin does not run properly in the onEmpty state #27

Closed
nugrahazzz opened this issue May 19, 2024 · 4 comments
Closed
Assignees

Comments

@nugrahazzz
Copy link

Describe the bug
I used statemixin and futurize but to trigger onEmpty it doesn't work properly. For Widgets that appear in a successful position, onLoading and onError are running properly but onEmpty is not running properly even with the help of change(GetStatus.empty)... Under what conditions is onEmpty triggered? Let's say I have a List of Model, does onEmpty refer to the length of lists = 0 (.isEmpty)?

Futurize (default) method from rx_notifier.dart

Future<void> futurize( Future<T> Function() body, { T? initialData, String? errorMessage, bool useEmpty = true, }) async { final Future<T> Function() compute = body; _value ??= initialData; await compute().then( (T newValue) { if ((newValue == null || newValue._isEmpty()) && useEmpty) { status = GetStatus<T>.loading(); } else { status = GetStatus<T>.success(newValue); } refresh(); }, onError: (Object err) { status = GetStatus<T>.error(errorMessage ?? err.toString()); refresh(); }, ); }

Change to

Future<void> futurize( Future<T> Function() body, { T? initialData, String? errorMessage, }) async { final Future<T> Function() compute = body; _value ??= initialData; await compute().then( (T newValue) { if (newValue == null) { status = GetStatus<T>.loading(); } else { if( newValue!._isEmpty()){ status = GetStatus<T>.empty(); } else { status = GetStatus<T>.success(newValue); } } refresh(); }, onError: (Object err) { status = GetStatus<T>.error(errorMessage ?? err.toString()); refresh(); }, ); }

To Reproduce
I just followed the futurize tutorial on the youtube channel and realized that onEmpty will not be triggered under any circumstances.
https://www.youtube.com/watch?v=5XQkeWy_5Ko

I referenced from the getx issue jonataslaw/getx#2966

Expected behavior
onEmpty will be triggered when the data is retrieved and the data is empty

Screenshots
If applicable, add screenshots to help explain your problem.

Flutter Version:
3.22.0

Refreshed Version:
2.7.0

Describe on which device you found the bug:
IQOO Neo8 Pro, Realme XT, and OPPO F11

@nugrahazzz
Copy link
Author

bandicam 2024-07-25 02-57-32-697

hi sir, please fix the futurize method as onEmpty will not be triggered in any condition.

@nugrahazzz
Copy link
Author

bandicam 2024-07-25 03-05-58-076

this code will fix the problem

@Aniketkhote
Copy link
Owner

Issue resolved in v2.8.1. Please verify if the fix works as expected.

@nugrahazzz
Copy link
Author

I've done the test and the code works as it should, thanks sir

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

No branches or pull requests

2 participants