0

This is my my code and null safety is enabled. I am not able to understand why I am facing the mentioned error where I am storing the value for "videoId".

Also, what can be another way to store this value for using later as I don't think that its the best way? P.S.- It works when null safety is disabled.

error message

  • better to place your code inside a 'code sample' tag rather than a image. This will help others re-run your code – rosh-dev851 Oct 31 '21 at 13:26

2 Answers2

0

First don't assign a value for your var videoId inside the player initialization! before initializing the controller Add:

videoId = ....; 

Then

YoutubePlayerController(
      initialVideoId:videoId ...);

if your widget.youtubelink is a String, assign it to your videoId without calling convert uriToId

Reham Alraee
  • 139
  • 8
  • I did that but now facing another error- The instance member 'widget' can't be accessed in an initializer. Try replacing the reference to the instance member with a different expression. – Shashwat Singh Oct 31 '21 at 16:20
  • Yeah, write this.widget.youtubeLink -> access your widget using this – Reham Alraee Nov 01 '21 at 05:24
0

Try in this way

YoutubePlayer(
  controller: _youtubePlayerController = 
     YoutubePlayerController(
      initialVideoId: YoutubePlayer.convertUrlToId(Links!).toString(),

         flags: YoutubePlayerFlags(
            autoPlay: false,
           ),
     ),
Taki Rajani
  • 177
  • 12