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<List<String>> getTitles() async {
- final courseItems = widget.courses.get('courseItems');
- final videosUrls = courseItems.map((e) => e.toString()).toList();
- final tutorialId =
- videosUrls.map((e) => getIdFromUrl(e.toString())).toList();
- print(' Tutorials ID : $tutorialId');
- print(' Tutorials ID Type : ${tutorialId.runtimeType}');
- final tutorialTitle = await tutorialId
- .map((e) async => await yt.videos.get(e).then((value) {
- //print('tutorialModel to String: ${value.title}');
- videoTitles.add(value.title);
- print('VideoTitle: $videoTitles');
- return value.title;
- }))
- .toList();
- print('tutorial Title Length: ${tutorialTitle.length}');
- print('video Title Length: ${videoTitles.length}');
- return videoTitles;
- }
- @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:
- return Center(child: CircularProgressIndicator());
- 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]}'));
- print(' Snapshot Error : ${snapshot.error}');
- print(' Snapshot Data : ${snapshot.data}');
- return videoUrls.isEmpty
- ? Center(
- child: Text('Error: ${snapshot.error}'),
- )
- : ListTile(
- title: Text(
- '${videoUrls[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