是否可以在一个应用程序中制作多个页面?

时间:2019-07-09 13:05:28

标签: flutter

我去将书转换为android应用,书有100页, 我应该为每个页面创建页面(活动)吗?或其他任何方式?

1 个答案:

答案 0 :(得分:2)

enter image description here

您可以为此使用PageView或其builder构造函数,这是基本示例

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

更新

创建两个这样的小部件。

// 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);
  }
}

现在在您的主类中,将它们用作

@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"),
          ],
        ),
      ],
    ),
  );
}