Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions lib/src/widgets/list_view_resource_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class ListViewResourceWidget<T> extends StatelessWidget {

switch (resource.status) {
case Status.loading:
lenght += loadingTileQuantity;
lenght += (resource.data ?? []).length + loadingTileQuantity;
break;
case Status.success:
if (emptyWidget != null &&
Expand Down Expand Up @@ -285,10 +285,10 @@ class ListViewResourceWidget<T> extends StatelessWidget {
switch (resource.status) {
case Status.loading:
if (loadingTile != null) {
return loadingTile!;
return _handleLoadingState(index, data, loadingTile!);
}
if (loadingTileBuilder != null) {
return loadingTileBuilder!();
return _handleLoadingState(index, data, loadingTileBuilder!());
}
break;
case Status.success:
Comment on lines 287 to 294
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

In that case, will not be better to return this _handleLoadingState if is with Status.loading or Status.success?
Because you added the success logic on this function, so the correct name for this function should be _mapIndexToTile, or something like that... What you think?

Expand Down Expand Up @@ -316,6 +316,21 @@ class ListViewResourceWidget<T> extends StatelessWidget {
return const SizedBox.shrink();
}

Widget _handleLoadingState(int index, List<T> data, Widget returnableLoadingWidget) {
final _maxIndexForPopulatedDataArray = data.length - 1;
final _shouldReturnEmptyWidget = emptyWidget != null &&
(resource.data == null || (resource.data ?? []).isEmpty);

if (index > _maxIndexForPopulatedDataArray) return returnableLoadingWidget;
if (_shouldReturnEmptyWidget) return emptyWidget ?? const SizedBox.shrink();

final widget = tileMapper(data[index]);
if (separatorBuilder != null) {
return separatorBuilder!(index, widget);
}
return widget;
}

Widget _proxyDecorator(Widget child, int index, Animation<double> animation) {
return AnimatedBuilder(
animation: animation,
Expand Down