Juan Casas
Juan Casas

Reputation: 104

The operator '..' is not working in flutter - dart code

I am looking at the following video where they use the .. operator inside initState()

https://youtu.be/uz4xRnE-UIw?t=117

in my code it does not work!

here is my code:

 void initState() {
    super.initState();
    // select where the video is coming from  asset/file/network
    _videoPlayerController = VideoPlayerController.asset(asset); 
    ..setListener( ()=> setState(() {})); // error: expected an identifier
    ..setLooping(true);  // error: expected an identifier
    ..initialize();  // error: expected an identifier
  }

broken operator

video image

what am i doing wrong?

Upvotes: 0

Views: 214

Answers (2)

eamirho3ein
eamirho3ein

Reputation: 17900

You are using ; after each line, in order to use .. you don't need to use ; at the end of line, so try this:

void initState() {
    super.initState();
    // select where the video is coming from  asset/file/network
    _videoPlayerController = VideoPlayerController.asset(asset)
    ..setListener( ()=> setState(() {})) 
    ..setLooping(true)
    ..initialize();  
  }

Upvotes: 2

Emre Faruk KOLAÇ
Emre Faruk KOLAÇ

Reputation: 532

I believe you have extra supply of ;

 void initState() {
    super.initState();
    // select where the video is coming from  asset/file/network
    _videoPlayerController = VideoPlayerController.asset(asset)
    ..setListener( ()=> setState(() {})); // error: expected an identifier
    ..setLooping(true);  // error: expected an identifier
    ..initialize();  // error: expected an identifier
  }

Upvotes: 3

Related Questions