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

ListView.builder do not automaticly add pages when overflow #162

Closed
MichelMelhem opened this issue Oct 19, 2019 · 12 comments
Closed

ListView.builder do not automaticly add pages when overflow #162

MichelMelhem opened this issue Oct 19, 2019 · 12 comments

Comments

@MichelMelhem
Copy link

Describe the bug
Hello,
When I use the widget ListView.builder and I have a problem. When the number of items in the list is greater than what the page can contain, the list is cut and the pdf ends. No new elements are automatically created to allow the remaining elements to be drawn.

To Reproduce
Code snippet to reproduce the behavior:

    return ui.Container(
                              alignment: ui.Alignment.topLeft,
                              child: ui.ListView.builder(
                                  itemCount: issues.length,
                                  itemBuilder: (ui.Context context, int index) {
                                    Issue issue = issues[index];
                                    return ui.Column(children: <ui.Widget>[
                                      ui.Header(
                                          text: "Issue n°${issue.id}",
                                          textStyle:
                                              ui.TextStyle(fontSize: 20)),
                                      ui.Text("Description :",
                                          textAlign: ui.TextAlign.left,
                                          style: ui.TextStyle(fontSize: 15)),
                                    
                                          })
                                    ]);
                                  }));
                        }));

This is an example but any list wich has a number of elements superior of what the page could render will do the job.
Expected behavior
The list is going to be cut and no new page will be created for rendering the rest of it.
Screenshots
image

Flutter Doctor

[√] Flutter (Channel stable, v1.9.1+hotfix.5, on Microsoft Windows [Version 10.0.18362.418], locale en-US)
    • Flutter version 1.9.1+hotfix.5 at C:\src\flutter
    • Framework revision 1aedbb1835 (2 days ago), 2019-10-17 08:37:27 -0700
    • Engine revision b863200c37
    • Dart version 2.5.0


[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at C:\Users\Michel\AppData\Local\Android\Sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 28.0.3
    • ANDROID_HOME = C:\Users\Michel\AppData\Local\Android\Sdk
    • Java binary at: C:\Users\Michel\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-1\191.5791312\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
    • All Android licenses accepted.

[!] Android Studio (version 3.4)
    • Android Studio at C:\Users\Michel\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\182.5314842
    • Flutter plugin version 38.2.1
    • Dart plugin version 183.6270
    X Unable to determine bundled Java version.
    • Try updating or re-installing Android Studio.

[√] Android Studio (version 3.5)
    • Android Studio at C:\Users\Michel\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-1\191.5791312
    • Flutter plugin version 38.2.3
    • Dart plugin version 191.8423
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[√] VS Code (version 1.39.2)
    • VS Code at C:\Users\Michel\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.5.1

[!] Connected device
    ! No devices available

! Doctor found issues in 2 categories.

Desktop (please complete the following information):

  • [ 9] Android

Smartphone (please complete the following information):

  • Device: Mi mix 3
  • OS: Android 9
  • Browser no web
  • Version the latest version
@DavBfr
Copy link
Owner

DavBfr commented Oct 20, 2019

First, if you use MultiPage, the widget that can create new pages must be the top level.
Then the only widgets that can create pages are Table, GridView, and Wrap.
"Wrap" is the most powerful, I would do like this:

    pdf.addPage(
      MultiPage(
        build: (Context context) => <Widget>[
          Wrap(
            children: List<Widget>.generate(issues.length, (int index) {
              final issue = issues[index];
              return Container(
                child: Column(
                  children: <Widget>[
                    Header(
                        text: "Issue n°${issue.id}",
                        textStyle: TextStyle(fontSize: 20)),
                    Text("Description :",
                        textAlign: TextAlign.left,
                        style: TextStyle(fontSize: 15)),
                  ],
                ),
              );
            }),
          ),
        ],
      ),
    );

@MichelMelhem
Copy link
Author

Thank you !

@MichelMelhem
Copy link
Author

Despite the very good solution you gave me i'm still getting an issue :
The space between each elements is very big even if the space could feet one of the list elements :
image

@MichelMelhem
Copy link
Author

@DavBfr Any updates ?

@DavBfr
Copy link
Owner

DavBfr commented Oct 22, 2019

Can it really fit?

Try to enable the debug output, using the static variable:

Document.debug = true;

This will draw margins and widget limits like the flutter debug paint feature.

@MichelMelhem
Copy link
Author

MichelMelhem commented Oct 22, 2019

image

Here for example there would be the place fot draw on the next page the start of the observation 7 until Picture 0 for example

@DavBfr
Copy link
Owner

DavBfr commented Oct 22, 2019

No, it's a full child of wrapper that has to fit. If you want to split anywhere, remove the Container and Column and add the content directly as children of Wrap.

The lib puts you in control to design beautiful pdf documents.

@MichelMelhem
Copy link
Author

yes, but if i have multiples elements to put inside my wrap how can i do without using a column ?

@DavBfr
Copy link
Owner

DavBfr commented Oct 22, 2019

final children = <Widget>[];

for (var item in items) {
children.add(Text('my title'));
children.add(Text('my content'));
children.add(Image(...));
}

pdf.addPage(
      MultiPage(
        build: (Context context) => <Widget>[
          Wrap(children: children),
          ),
        ],
      ),
    );

@MichelMelhem
Copy link
Author

@DavBfr The problem with your solution is that my items or no longer alligned in colllumn they are in row. How i can fix that ?

@DavBfr
Copy link
Owner

DavBfr commented Oct 22, 2019

you can force all widgets to occupy the full width, using a SizedBox for example:

children.add(SizedBox(width:double.infinity, child:Text('my title')));

@MichelMelhem
Copy link
Author

Thank you for your help !

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