Home > Enterprise >  How to set the orientation of the PageView to the left?
How to set the orientation of the PageView to the left?

Time:01-30

I have to add pages dynamically at left side.

So, is it possible to set a PageView whose default orientation is horizontal and left, like the orientation of a Japanese book?

If initial List of pages is like:

List<Widget> _pages = [Widget0, Widget1, Widget2];

Plain PageView's direction:

[0] -> [1] -> [2]

But what I want:

[2] <- [1] <- [0]

CodePudding user response:

From the PageView documentation here, under the properties section you could try using the reverse property, here's a brief example:

class MyStatelessWidget extends StatelessWidget {
  const MyStatelessWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final PageController controller = PageController();
    return PageView(
      reverse: true,
      controller: controller,
      children: const <Widget>[
        Center(
          child: Text('First Page'),
        ),
        Center(
          child: Text('Second Page'),
        ),
        Center(
          child: Text('Third Page'),
        )
      ],
    );
  }
}

CodePudding user response:

sort the list before you send it to pageview

Like that _pages.sort((a, b) => b.compareTo(a));

CodePudding user response:

Instead of using _pages.add() use:

_pages.insert(0,Widget())

that means to insert a new widget dynamically to the list of widgets but at first index.

  •  Tags:  
  • Related