我去把书转换成 android 应用程序这本书有 100 页, 我应该为每个页面创建页面(事件)吗?或任何其他方式来做到这一点?
最佳答案
您可以为此使用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"),
],
),
],
),
);
}
关于flutter - 是否可以在一个应用程序中制作多个 flutter 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56953285/