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

Remove height and singlechildscrollview from onEmpty Widget #133

Open
AkaankshK opened this issue Jun 3, 2022 · 4 comments
Open

Remove height and singlechildscrollview from onEmpty Widget #133

AkaankshK opened this issue Jun 3, 2022 · 4 comments

Comments

@AkaankshK
Copy link

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

@mubiru-simeon
Copy link

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

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

@waqadArshad
Copy link

waqadArshad commented Aug 10, 2022

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
Copy link

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
Copy link

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.

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

3 participants