Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:cloud_firestore/cloud_firestore.dart';
- import 'package:flutter/material.dart';
- import 'package:learnship/pages/play_page/play_page.dart';
- import 'package:youtube_explode_dart/youtube_explode_dart.dart';
- import 'package:youtube_parser/youtube_parser.dart';
- class CourseListPage extends StatefulWidget {
- static String routeName = 'courseListPage';
- final DocumentSnapshot courses;
- const CourseListPage({Key key, @required this.courses}) : super(key: key);
- @override
- _CourseListPageState createState() => _CourseListPageState();
- }
- class _CourseListPageState extends State<CourseListPage> {
- List<String> videoTitles = [];
- List<String> videoUrls = [];
- List<String> videoIds = [];
- final yt = YoutubeExplode();
- @override
- void initState() {
- super.initState();
- }
- Future getTitles() async {
- final List<String> tutorialsTitles = [];
- final courseItems = widget.courses.get('courseItems');
- // print('Inside courseItems: $courseItems');
- // print('Inside courseItems: ${courseItems.runtimeType}'); // List<dynamic>
- final videosUrls = courseItems.map((e) => e.toString()).toList();
- // print('Inside videosUrls: $videosUrls');
- // print(
- // 'Inside videosUrls Runtime: ${videosUrls.runtimeType}'); // List<dynamic>
- final tutorialId =
- videosUrls.map((e) => getIdFromUrl(e.toString())).toList();
- // print('Inside the tutorialId: $tutorialId');
- // print(
- // 'Inside the tutorialId Runtime Type : ${tutorialId.runtimeType}'); //List<dynamic>
- final tutorialTitle = tutorialId
- .map((e) => yt.videos.get(e).then((value) {
- print('tutorialModel to String: ${value.title}');
- tutorialsTitles.add(value.title);
- return value.title;
- }))
- .toList();
- print('Inside tutorialTitle ${tutorialTitle.runtimeType}');
- print('Inside tutorialTitle: $tutorialTitle');
- // for (var u in videoUrls) {
- // videoUrls.add(u.toString());
- // print('Inside for loop: $u ');
- // print('Inside for loop: ${u.runtimeType}');
- // }
- // print(videoUrls.runtimeType);
- // videoUrls = videoUrls.toList(growable: true);
- // videoIds = videoUrls.map((e) => getIdFromUrl(e));
- // print(videoUrls);
- // print(
- // 'Inside the getTitles videoTitles RuntimeType: ${videoTitles.runtimeType}');
- setState(() {});
- }
- @override
- Widget build(BuildContext context) {
- Size size = MediaQuery.of(context).size;
- return SafeArea(
- child: Scaffold(
- body: SingleChildScrollView(
- child: FutureBuilder(
- future: getTitles(),
- builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
- switch (snapshot.connectionState) {
- case ConnectionState.none:
- return Center(child: Text('Loading none of data'));
- case ConnectionState.waiting:
- case ConnectionState.active:
- return Center(child: CircularProgressIndicator());
- break;
- case ConnectionState.done:
- return Container(
- height: size.height * 0.8,
- child: ListView.builder(
- shrinkWrap: true,
- itemCount: videoUrls.length,
- itemBuilder: (context, index) {
- //print(('============>${widget.videoTitles[1]}'));
- return videoTitles.isEmpty
- ? Center(
- child: CircularProgressIndicator(),
- )
- : ListTile(
- title: Text(
- '${videoTitles[index]}',
- style: TextStyle(
- color: Colors.red,
- fontWeight: FontWeight.bold),
- ),
- onTap: () {
- Navigator.push(
- context,
- MaterialPageRoute(builder: (builder) {
- return PlayPage(
- videoTitle: videoTitles[index],
- currentvideoID: videoIds[index],
- );
- }),
- );
- },
- );
- },
- ),
- );
- default:
- if (snapshot.hasError)
- return Text('Error: ${snapshot.error}');
- else
- return Text('Result: ${snapshot.data}');
- }
- },
- ),
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment