vedartm / paginate_firestore

A flutter package to simplify pagination with firestore data 🗃
https://pub.dev/packages/paginate_firestore
MIT License
113 stars 136 forks source link

Remove height and singlechildscrollview from onEmpty Widget #133

Open AkaankshK opened 2 years ago

AkaankshK commented 2 years ago

Please remove these so that we can add custom empty state widgets. Currently because of this, everything is scrollable and wierd. Thanks

mubiru-simeon commented 2 years ago

if (loadedState.documentSnapshots.isEmpty) { return _buildWithScrollView(context, widget.onEmpty); }

On this part. Please remove the scroll view. It messes up the entire UI

waqadArshad commented 2 years ago

This is how I fixed it. In the paginate_firestore.dart, added an extra bool in the _buildWithScrollView part

Widget _buildWithScrollView(BuildContext context, Widget child, [bool isError = false]) {
    return !isError
        ? SingleChildScrollView(
      child: Container(
        alignment: Alignment.center,
        height: MediaQuery.of(context).size.height,
        child: child,
      ),
    )
        :  Container(
      alignment: Alignment.center,
      height: MediaQuery.of(context).size.height,
      child: child,
    );
  }

and then passed true wherever needed:

if (state is PaginationInitial) {
          return _buildWithScrollView(context, widget.initialLoader);
        } else if (state is PaginationError) {
          return _buildWithScrollView(
            context,
            (widget.onError != null)
                ? widget.onError!(state.error)
                : ErrorDisplay(exception: state.error),
            true,
          );
        } else {
          final loadedState = state as PaginationLoaded;
          if (widget.onLoaded != null) {
            widget.onLoaded!(loadedState);
          }
          if (loadedState.hasReachedEnd && widget.onReachedEnd != null) {
            widget.onReachedEnd!(loadedState);
          }

          if (loadedState.documentSnapshots.isEmpty) {
            return _buildWithScrollView(context, widget.onEmpty, true);
          }
          return widget.itemBuilderType == PaginateBuilderType.listView
              ? _buildListView(loadedState)
              : widget.itemBuilderType == PaginateBuilderType.gridView
              ? _buildGridView(loadedState)
              : _buildPageView(loadedState);
        }
waqadArshad commented 2 years ago

This is how I fixed it. In the paginate_firestore.dart, added an extra bool in the _buildWithScrollView part

Widget _buildWithScrollView(BuildContext context, Widget child, [bool isError = false]) {
    return !isError
        ? SingleChildScrollView(
      child: Container(
        alignment: Alignment.center,
        height: MediaQuery.of(context).size.height,
        child: child,
      ),
    )
        :  Container(
      alignment: Alignment.center,
      height: MediaQuery.of(context).size.height,
      child: child,
    );
  }

and then passed true wherever needed:

if (state is PaginationInitial) {
          return _buildWithScrollView(context, widget.initialLoader);
        } else if (state is PaginationError) {
          return _buildWithScrollView(
            context,
            (widget.onError != null)
                ? widget.onError!(state.error)
                : ErrorDisplay(exception: state.error),
            true,
          );
        } else {
          final loadedState = state as PaginationLoaded;
          if (widget.onLoaded != null) {
            widget.onLoaded!(loadedState);
          }
          if (loadedState.hasReachedEnd && widget.onReachedEnd != null) {
            widget.onReachedEnd!(loadedState);
          }

          if (loadedState.documentSnapshots.isEmpty) {
            return _buildWithScrollView(context, widget.onEmpty, true);
          }
          return widget.itemBuilderType == PaginateBuilderType.listView
              ? _buildListView(loadedState)
              : widget.itemBuilderType == PaginateBuilderType.gridView
              ? _buildGridView(loadedState)
              : _buildPageView(loadedState);
        }

@vedartm can I generate a pull request with these changes?

mubiru-simeon commented 2 years ago

Nice work. I had also thought of making a controller, to enable reloading the pagination results at will, eg when a user selects filters for their results. But im a little busy right now, sooo I'll do it later on and post the code.