Reputation: 123
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
Reputation: 268474
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