Home > OS >  'String' is not a subtype of type 'YoutubePlayerController'
'String' is not a subtype of type 'YoutubePlayerController'

Time:01-21

Expanded(
                child:  Container(
                  child: SingleChildScrollView(scrollDirection: Axis.vertical,
                    child: StreamBuilder(
                      stream: FirebaseFirestore.instance.collection("videoList").snapshots(),
                      builder: (context,AsyncSnapshot<QuerySnapshot>streamSnapshot){
                        if(streamSnapshot.hasData){
                          return ListView.separated(
                              shrinkWrap: true,
                              physics: ScrollPhysics(),
                              scrollDirection: Axis.vertical,
                              clipBehavior: Clip.hardEdge,
                              itemBuilder: (context, index) {
                                DocumentSnapshot _documentSnapshot=streamSnapshot.data!.docs[index];
                            return ListTile(
                              title: YoutubePlayer(
                                key: ObjectKey(_documentSnapshot["url"]),
                                controller: _documentSnapshot["url"],
                                actionsPadding: const EdgeInsets.only(left: 20.0),
                                bottomActions: [
                                  CurrentPosition(),
                                  const SizedBox(width: 10.0),
                                  ProgressBar(isExpanded: true),
                                  const SizedBox(width: 10.0),
                                  RemainingDuration(),
                                  FullScreenButton(),
                                ],
                              ),
                              subtitle: Text(_documentSnapshot["title"],style: TextStyle(color: Colors.blueAccent,fontStyle: FontStyle.italic,fontSize: 20,fontWeight: FontWeight.w300),),
                            );
                          },
                              itemCount: streamSnapshot.data!.docs.length,
                              separatorBuilder: (context, index) => const SizedBox(height: 7.5),
                              padding: EdgeInsets.only(left: 1,right: 1,top: 10));
                        }
                        return Center(child: CircularProgressIndicator(),);
                      },
                    ),
                  ),
                ),

              ),

I am trying to connect my youtube player with firestore database but i dont know, i want to know what is the conntroller for youtube video player

CodePudding user response:

I guess you can simply create a YoutubePlayerController and give it as paramenter

controller: YoutubePlayerController(_documentSnapshot["url"]),

For further information on the controller take a look at the docu.

CodePudding user response:

First of all, this error occurs because you're trying to call a property of the YoutubePlayerController class that should be a type of its parent but you're calling it in the type of string, I guess the error occurs on the below's part of your codes:

Text(_documentSnapshot["title"],style: TextStyle(color: Colors.blueAccent,fontStyle: FontStyle.italic,fontSize: 20,fontWeight: FontWeight.w300),),

because the Text() widget just accepts string data type you should convert the calls instance to string by adding the .toString() function at the end of the _documentSnapshot["title"] property just like the _documentSnapshot["title"].toString() it may fix your problem if not, something is wrong in your response, try to log it on the console to see what is the problem.

  • Related