Flutter 可以在一个应用程序中创建多个颤振页面吗?
我去把这本书转换成android应用程序这本书有100页, 我应该为每个页面创建pageactivity吗?或者有其他的方法吗 您可以使用PageView或其生成器构造函数来实现这一点,下面是一个基本示例Flutter 可以在一个应用程序中创建多个颤振页面吗?,flutter,Flutter,我去把这本书转换成android应用程序这本书有100页, 我应该为每个页面创建pageactivity吗?或者有其他的方法吗 您可以使用PageView或其生成器构造函数来实现这一点,下面是一个基本示例 PageView.builder( itemCount: 100, itemBuilder: (_, index) => YourPage(list[index]), ) 更新: 创建两个类似这样的小部件 // It only shows Text class TextPage
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"),
],
),
],
),
);
}
你绝对不应该在每页都使用屏幕。相反,创建一个支持分页的小部件。只有一个屏幕,只需更改内容。请删除所有以前的评论,您无需向我发送您的书,如果您能告诉我您打算如何使用书制作应用程序,这将更有意义,目前我假设您的书中有文本和图像,对于有字符串的文本和图像,将有jpg、png格式的图像。如果我错了,一定要让我知道你打算如何用这本书制作这个应用程序。