Closed nugrahazzz closed 3 months ago
hi sir, please fix the futurize method as onEmpty will not be triggered in any condition.
this code will fix the problem
Issue resolved in v2.8.1
. Please verify if the fix works as expected.
I've done the test and the code works as it should, thanks sir
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 https://github.com/jonataslaw/getx/issues/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