I want to play videos in each SeassionCards. Should I create different dart file for each video? Or, Is there a chance to bring videos by one by for every single buttons?
Asked
Active
Viewed 88 times
1 Answers
0
I'm assuming you have something like this in your code
...
children:[
SessionCard(
sessionNum:1,
press:(){ }
),
SessionCard(
sessionNum:2,
press:(){ }
),
SessionCard(
sessionNum:3,
press:(){ }
),
SessionCard(
sessionNum:4,
press:(){ }
),
]
change it to this
you can store your data in a list
//create a class
class SessionCardMode{
final int sessionNum;
final String videoUrl;
SessionCardModel(this.sessionNum, this.videoUrl);
}
in the top of your widget fill in your data
final List<SessionCardModel> sessionItems =
[
SessionCardModel(1, 'https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4?_=1'),
SessionCardModel(2, 'https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4?_=1'),
SessionCardModel(3, 'https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4?_=1'),
SessionCardModel(4, 'https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4?_=1'),
SessionCardModel(5, 'https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4?_=1'),
SessionCardModel(6, 'https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4?_=1'),
]
and in your list, change it something like this
...
children:List.generate(sessionItems.length,(index) =>
SessionCard(
sessionNum:sessionItems[index].sessionNum,
press:(){
// you can get the videoUrl of the particular session
// by using sessionItems[index].videoUrl
// you can open the video here
}
));
this will clean up the code a little and solve your proplem

Musa Jahun
- 66
- 1
- 6