karrar jasim
karrar jasim

Reputation: 123

Is possible to make Multiple flutter pages in one app?

I went to convert book to android app the book has 100 page , should I create page(activity) for each page ? or any other ways to do this?

Upvotes: 0

Views: 633

Answers (1)

CopsOnRoad
CopsOnRoad

Reputation: 268474

enter image description here

You can use PageView or its builder constructor for this, here is the basic example

PageView.builder(
  itemCount: 100,
  itemBuilder: (_, index) => YourPage(list[index]),
)

Update:

Create two widgets like this.

// It only shows Text
class TextPage extends StatelessWidget {
  final String text;
  const TextPage({@required this.text});

  @override
  Widget build(BuildContext context) {
    return Text(text, style: TextStyle(fontSize: 20));
  }
}

// It only shows Image from assets
class ImagePage extends StatelessWidget {
  final String image;
  const ImagePage({@required this.image});

  @override
  Widget build(BuildContext context) {
    return Image.asset(image);
  }
}

Now in your main class, use them as

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(),
    body: PageView(
      children: <Widget>[
        TextPage(text: "This screen only has text"), // 1st screen only text
        ImagePage(image: "assets/images/chocolate_pic.png"), // 2nd screen only image
        Column( // 3rd screen will have both
          children: <Widget>[
            TextPage(text: "This is the text followed by an image"),
            ImagePage(image: "assets/images/chocolate_pic.png"),
          ],
        ),
      ],
    ),
  );
}

Upvotes: 1

Related Questions