pparth602

courselist_page.dart

Apr 26th, 2021
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.06 KB | None | 0 0
  1. import 'package:cloud_firestore/cloud_firestore.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:youtube_explode_dart/youtube_explode_dart.dart';
  4.  
  5. class CourseListPage extends StatefulWidget {
  6.   var yt = YoutubeExplode();
  7.   static String routeName = 'courseListPage';
  8.   final int itemCount;
  9.   final DocumentSnapshot courses;
  10.   List<dynamic> _videoUrls = [];
  11.   List<String> _videoIds = [];
  12.   List<dynamic> videoTitles = [];
  13.   List<Video> _videoModels = [];
  14.  
  15.   CourseListPage(
  16.       {Key key,
  17.       @required this.courses,
  18.       @required List<String> videoUrls,
  19.       @required this.itemCount,
  20.       @required List<String> videoIds})
  21.       : _videoUrls = videoUrls,
  22.         _videoIds = videoIds,
  23.         super(key: key) {
  24.     // print('============> VideoIds : ${videoIds} <============');
  25.   }
  26.  
  27.   void getTitles() async {
  28.     // videoTitles = _videoUrls.map<String>((e) => e.toString()).toList();
  29.     videoTitles = _videoModels.map((e) => e.title).toList();
  30.     for (int i = 0; i < _videoIds.length; i++) {
  31.       videoTitles
  32.           .add(await yt.videos.get(_videoIds[i].toString()).then((value) {
  33.         print('==========> ${value.title}<===============');
  34.         print('==========> $videoTitles<===============');
  35.  
  36.         return value.title;
  37.       }));
  38.     }
  39.   }
  40.  
  41.   @override
  42.   _CourseListPageState createState() => _CourseListPageState();
  43. }
  44.  
  45. class _CourseListPageState extends State<CourseListPage> {
  46.   @override
  47.   void initState() {
  48.     widget.getTitles();
  49.     print('============> VideoIds : ${widget._videoIds} <============');
  50.  
  51.     super.initState();
  52.   }
  53.  
  54.   @override
  55.   Widget build(BuildContext context) {
  56.     Size size = MediaQuery.of(context).size;
  57.     return SafeArea(
  58.       child: Scaffold(
  59.         body: SingleChildScrollView(
  60.           child: Container(
  61.             height: size.height * 0.8,
  62.             child: ListView.builder(
  63.               shrinkWrap: true,
  64.               itemCount: widget.videoTitles.length,
  65.               itemBuilder: (context, index) {
  66.                 print('<============>${widget.videoTitles.length}');
  67.                 //print(('============>${widget.videoTitles[1]}'));
  68.                 return widget.videoTitles.isEmpty
  69.                     ? Center(
  70.                         child: CircularProgressIndicator(),
  71.                       )
  72.                     : ListTile(
  73.                         title: Text('${widget.videoTitles[index]}',
  74.                             style: TextStyle(
  75.                                 color: Colors.red,
  76.                                 fontWeight: FontWeight.bold)),
  77.                       );
  78.               },
  79.             ),
  80.           ),
  81.         ),
  82.       ),
  83.     );
  84.   }
  85. }
  86.  
  87. /*
  88. ListView.builder(
  89.       itemBuilder: (BuildContext context, int index) {
  90.         DocumentSnapshot courses = widget.snapshot.data.docs[index];
  91.         return !widget.snapshot.hasData
  92.             ? Center(
  93.                 child: CircularProgressIndicator(),
  94.               )
  95.             : ListTile(
  96.                 title: courses['courseItems'],
  97.               );
  98.   },
  99. );
  100.   */
  101.  
Advertisement
Add Comment
Please, Sign In to add comment