pparth602

courselist_page.dart

Apr 25th, 2021
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.18 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.   static String routeName = 'courseListPage';
  7.   final DocumentSnapshot courses;
  8.   List<dynamic> videoUrls = [];
  9.   List<String> videoTitles = [];
  10.  
  11.   var yt = YoutubeExplode();
  12.  
  13.   void getTitles() async {
  14.     for (int i = 0; i < videoUrls.length; i++) {
  15.       var video = await yt.videos.get(videoUrls[i]);
  16.       videoTitles[i] = video.title;
  17.       print(
  18.           ' =======================> ${videoTitles[i]}<========================');
  19.     }
  20.   }
  21.  
  22.   CourseListPage({
  23.     Key key,
  24.     @required this.courses,
  25.     this.videoUrls,
  26.   }) : super(key: key);
  27.  
  28.   @override
  29.   _CourseListPageState createState() => _CourseListPageState();
  30. }
  31.  
  32. class _CourseListPageState extends State<CourseListPage> {
  33.   @override
  34.   void initState() {
  35.     widget.getTitles();
  36.     super.initState();
  37.   }
  38.  
  39.   @override
  40.   Widget build(BuildContext context) {
  41.     Size size = MediaQuery.of(context).size;
  42.     return SafeArea(
  43.       child: Scaffold(
  44.         body: SingleChildScrollView(
  45.           child: Container(
  46.             height: size.height * 0.8,
  47.             child: ListView.builder(
  48.               itemCount: widget.videoUrls.length,
  49.               itemBuilder: (context, index) {
  50.                 print('============>${widget.videoUrls.length}');
  51.                 for (int i = 0; i < widget.videoUrls.length; i++) {
  52.                   print('=========> ${widget.videoUrls.length}<===\n');
  53.                 }
  54.                 return ListTile(
  55.                   title: Text('${widget.videoTitles[index]}'),
  56.                 );
  57.               },
  58.             ),
  59.           ),
  60.         ),
  61.       ),
  62.     );
  63.   }
  64. }
  65.  
  66. /*
  67. ListView.builder(
  68.       itemBuilder: (BuildContext context, int index) {
  69.         DocumentSnapshot courses = widget.snapshot.data.docs[index];
  70.         return !widget.snapshot.hasData
  71.             ? Center(
  72.                 child: CircularProgressIndicator(),
  73.               )
  74.             : ListTile(
  75.                 title: courses['courseItems'],
  76.               );
  77.   },
  78. );
  79.   */
  80.  
Advertisement
Add Comment
Please, Sign In to add comment