0

I have a ListView contains PageViews Each PageView will contain an array of Images

I need to know the correct way to make PageView items to expand its width and height to match the PageView width and height

and is putting PageView inside ListView is safe!?

Thanks

Yazan Allahham
  • 174
  • 2
  • 17

2 Answers2

0

Putting a PageView inside a ListView is possible, but since ListView is providing unlimited height (since you can put as many widgets inside it as you like and it will make everything scroll practically) your PageView does not know how to handle this. The PageView needs to know how big it can get so it can layout its own children.

When using PageView, I would recommend you to make use of MediaQuery.of(context).size to get the screen width and height. You can set the size of your PageView based on that information. For example you could do:

SizedBox(
  height: MediaQuery.of(context).size.height,
  width: MediaQuery.of(context).size.width,
  child: PageView(
    ...
  ),
)

Use this inside your ListView and you should be good to go!

kounex
  • 1,555
  • 4
  • 12
  • the problem with MediaQuery.of(context).size is getting the size of screen! but I have a toolbar and a widget on top of the ListView so I cannot use MediaQuery.of(context).size! I need to know the space that ListView is filling and only use it for my PageView – Yazan Allahham Oct 26 '20 at 11:56
  • Then you should think about if you really need the `ListView` because as I wrote earlier the `ListView` itself will take all available space and inside the list it will have unlimited height. You can still use MediaQuery size as a reference of how big the screen is and subtract the size of the other widgets to get the correct size. Problem remains: `PageView` needs to know its height and width and `ListView` itself has unlimited height. – kounex Oct 26 '20 at 12:17
0

Check My Widget at Codeapprun.io, I have implemented the same thing there.

PRATIK PAWAR
  • 302
  • 1
  • 2
  • 10