Advertisement
FahimHoque

story page

Dec 12th, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. class StoryPage extends StatefulWidget {
  2. @override
  3. _StoryPageState createState() => _StoryPageState();
  4. }
  5.  
  6. class _StoryPageState extends State<StoryPage> {
  7. late VideoPlayerController _controller;
  8. bool _isPlaying = false;
  9. @override
  10. void initState() {
  11. super.initState();
  12. _controller = VideoPlayerController.network(
  13. 'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4')
  14. ..initialize().then((_) {
  15. // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
  16. setState(() {});
  17. });
  18. }
  19.  
  20. @override
  21. Widget build(BuildContext context) {
  22. return Scaffold(
  23. backgroundColor: CustomColors.primary,
  24. appBar: AppBar(
  25. title: AppBarTitle('Story'),
  26. backgroundColor: Colors.transparent,
  27. elevation: 0.0,
  28. ),
  29. extendBodyBehindAppBar: true,
  30. body: SingleChildScrollView(
  31. child: _buildItems(),
  32. ),
  33. bottomNavigationBar: _isPlaying == true ? pauseButton() : playButton(),
  34. );
  35. }
  36.  
  37. Widget _buildItems() {
  38. return Column(
  39. crossAxisAlignment: CrossAxisAlignment.start,
  40. children: [
  41. SizedBox(height: 80),
  42. Center(
  43. child: _controller.value.isInitialized
  44. ? AspectRatio(
  45. aspectRatio: _controller.value.aspectRatio,
  46. child: VideoPlayer(_controller),
  47. )
  48. : Container(),
  49. ),
  50. SizedBox(height: 20),
  51. _buildLists(),
  52. ],
  53. );
  54. }
  55.  
  56. Widget _buildLabel(String label) {
  57. return Container(
  58. padding: EdgeInsets.only(left: 20),
  59. child: Text(
  60. label,
  61. style: HeadingTextStyle.heading20,
  62. ),
  63. );
  64. }
  65.  
  66. Widget _buildLists() {
  67. List<Widget> widgetLists = [];
  68.  
  69. for (FeedItem feedItem
  70. in Store.instance.getAppData().storyPageFeed.feedItems) {
  71. if (feedItem.cardType == CardType_Enum.GROUP_STORY_SLIDER_CARD) {
  72. GroupStory groupStory = feedItem.groupStory;
  73. widgetLists.add(_buildLabel(groupStory.title));
  74. widgetLists.add(SizedBox(height: 20));
  75. widgetLists.add(_buildMusicSlider(groupStory.stories));
  76. } else {
  77. GroupStory groupStory = feedItem.groupStory;
  78. widgetLists.add(_buildLabel(groupStory.title));
  79. widgetLists.add(SizedBox(height: 5));
  80. widgetLists.add(_buildMusicGrid(groupStory.stories));
  81. }
  82. widgetLists.add(SizedBox(height: 10));
  83. }
  84.  
  85. return Column(
  86. crossAxisAlignment: CrossAxisAlignment.start,
  87. children: widgetLists,
  88. );
  89. }
  90.  
  91. Widget _buildMusicGrid(List<Story> stories) {
  92. List<GridItem> items = [];
  93.  
  94. for (Story story in stories) {
  95. GridItem item = GridItem(
  96. GridItemType.STORY,
  97. story: story,
  98. );
  99. items.add(item);
  100. }
  101.  
  102. GridContainerData data = GridContainerData(items);
  103.  
  104. return GridContainer(data, crossAxisCount: 2);
  105. }
  106.  
  107. Widget _buildMusicSlider(List<Story> stories) {
  108. List<ListItem> items = [];
  109.  
  110. for (Story story in stories) {
  111. ListItem item = ListItem(
  112. itemType: ListItemType.STORY,
  113. story: story,
  114. );
  115. items.add(item);
  116. }
  117.  
  118. ListContainerData data = ListContainerData(items);
  119.  
  120. return Container(
  121. padding: EdgeInsets.only(left: 20),
  122. height: 140,
  123. child: ListContainer(data: data),
  124. );
  125. }
  126.  
  127. final Widget backgroundPicture = Container(
  128. width: double.infinity,
  129. height: 322,
  130. decoration: BoxDecoration(
  131. image: DecorationImage(
  132. image: AssetImage('assets/images/bg-3.png'),
  133. fit: BoxFit.cover,
  134. ),
  135. ),
  136. );
  137.  
  138. /// FOR DEMO ONLY
  139. Widget playButton() {
  140. return IconButton(
  141. onPressed: () {
  142. audioHandler.play();
  143. setState(() {
  144. _controller.play();
  145. _isPlaying = true;
  146. });
  147. },
  148. icon: Icon(Icons.play_arrow),
  149. );
  150. }
  151.  
  152. Widget pauseButton() {
  153. return IconButton(
  154. onPressed: () {
  155. audioHandler.pause();
  156. setState(() {
  157. _controller.pause();
  158. _isPlaying = false;
  159. });
  160. },
  161. icon: Icon(Icons.pause),
  162. );
  163. }
  164. }
  165.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement