I'm creating an application where there is a scroll view made up using Flutter_Swiper. The problem is that I can't figure out how to put a list of widget inside the Swiper. Let me explain with an example:
Widget build(BuildContext context) {
return new Container(
child: new Swiper(
itemBuilder: (BuildContext context, int index) {
return MyWidget(id: 1, text: "hello");
},
itemCount: 10,
viewportFraction: 0.8,
scale: 0.85,
)
);
}
This is the code that the official wiki has provided to me, it works but obviously it shows me the same widget every times.
So, to do this, I created a structure like this:
class MyStructure{
final int id;
final String text;
MyStructure({this.id, this.text});
}
Then I created a widget like this:
class MyWidget extends StatelessWidget{
final MyStructure widgetStructure;
MyWidget(this.widgetStructure);
@override
Widget build(BuildContext context) {
return Container(
child: Text(widgetStructure.id, widgetStructure.text);
...
)
}
}
Then I created a list of structures like this:
List<MyStructure> widgetList;
widgetList= [MyStructure(
id = 1;
text = "a text"
)];
So, now I could create a list of widget just doing something like this:
return new Row(children: widgetList.map((item) => new MyWidget(item)).toList());
And, in theory, it works but I don't know how to use it with the swiper.
In demo, widgetList length is 10. you can see full code below
full code