I'm 2 days trying to solve this problem by myself but i just accepted that i can't. So i'm here to ask you guys for help. I'm trying to use Youtube Player Flutter plugin and i created a List of videos from a channel that i choose using ListTile, ListView, and FutureBuilder. What i'm trying to do is: when i click on some video i want it to play. So i'm trying to use GestureDetector, but the problem is that i don't know how can i use Youtube Player Flutter as a player for onTap of Gesture Detector. I don't know if i'm doing this good and i accept suggestions of better ways to do that or a solution;One of my problem is:LateInitializationError: Field '_controller@25000317' has not been initialized.So to be honest i don't know how to use late but when i use it that's my problem.So if i don't use late i have to change my code.from:late YoutubePlayerController _controller;to: YoutubePlayerController? _controller;and if i do that i have to use _controller! and i have the error:Null check operator used on a null valueSo i've tried a lot of ways to not use null check operator on a null value, but i can't. If you guys can help me about that too, i will be happy.
Here's the code
import 'package:flutter/material.dart';import 'package:mood3/model/Video.dart';import 'package:mood3/telas/Api.dart';import 'package:youtube_player_flutter/youtube_player_flutter.dart';class Videos extends StatefulWidget { @override State<Videos> createState() => _VideosState();}class _VideosState extends State<Videos> {late YoutubePlayerController _controller; _listarVideos() { Api api = Api(); return api.pesquisar(""); } @override Widget build(BuildContext context) { return Container( padding: EdgeInsets.all(16), child: FutureBuilder<List<Video>?>( future: _listarVideos(), builder: (context, snapshot){ switch(snapshot.connectionState){ case ConnectionState.none: case ConnectionState.waiting: return Center( child: CircularProgressIndicator(), ); break; case ConnectionState.active: case ConnectionState.done: if(snapshot.hasData){ return ListView.separated( itemBuilder: (context, index){ List<Video>? videos = snapshot.data; Video video = videos![ index ]; return GestureDetector( onTap: (){ void runYoutubeplayer() { _controller = YoutubePlayerController( initialVideoId: video.id.toString() , flags: YoutubePlayerFlags( autoPlay: false, mute: false, ), ); } setState(() { _controller.load(video.id.toString()); }); }, child: Column( children: <Widget>[ Container( height: 200, decoration: BoxDecoration( image: DecorationImage( fit: BoxFit.cover, image: NetworkImage( video.imagem! ) ) ), ), ListTile( title: Text( video.titulo! ), subtitle: Text( video.canal! ), ) ], ), ); }, separatorBuilder: (context, index) => Divider( height: 2, color: Colors.grey, ), itemCount: snapshot.data!.length ); }else{ return Center( child: Text("Nenhum dado a ser exibido!"), ); } break; } }, ),); }}