Reputation: 185
I would like to horizontally display 5 items at the same time, and I want the possibility to scroll or display a new (next) item each time I press a button on the side. Which widget can I use to implement it (without package) ?
Upvotes: 0
Views: 84
Reputation: 63799
I think PageView
suits best for this scenario.
class TW extends StatefulWidget {
const TW({super.key});
@override
State<TW> createState() => _TWState();
}
class _TWState extends State<TW> {
final PageController controller = PageController(
viewportFraction: 1,
);
@override
Widget build(BuildContext context) {
return Scaffold(
body: PageView.builder(
controller: controller,
itemBuilder: (context, index) {
return Text("Item $index");
},
),
floatingActionButton: FloatingActionButton(onPressed: () {
controller.nextPage(
duration: Duration(seconds: 1), curve: Curves.bounceIn);
}),
);
}
}
More about PageView
Upvotes: 1