late YoutubePlayerController _controller;
late String url = widget.url;
late YoutubePlayer youtubePlayer;
late String id;
late bool isPlaying, isMute;
late String author;
@override
void initState() {
super.initState();
isMute = false;
id = YoutubePlayer.convertUrlToId(url)!;
_controller = YoutubePlayerController(
initialVideoId: id,
flags: const YoutubePlayerFlags(autoPlay: false),
);
youtubePlayer = YoutubePlayer(
controller: _controller,
);
isPlaying = _controller.value.isPlaying;
author = _controller.metadata.author;
}
Widget setAuthor() {
// ignore: unnecessary_null_comparison
if (_controller.metadata.author != null) {
setState(() {
author = _controller.metadata.author;
});
return Text(
author,
style: const TextStyle(
color: Colors.pink,
fontSize: 25,
fontWeight: FontWeight.bold,
),
);
} else {
return setAuthor();
}
}
SafeArea(
child: Scaffold(
resizeToAvoidBottomInset: true,
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Stack(
children: [
_backAction(),
Positioned(
top: 130,
left: 3,
right: 3,
child: SizedBox(
height: MediaQuery.of(context).size.height * 2 / 3.0,
child: _Player(),
),
),
],
),
),
),
),
);
Widget _Player() {
return YoutubePlayerBuilder(
player: YoutubePlayer(
controller: _controller,
progressIndicatorColor: dustyRose,
),
builder: (BuildContext context, Widget player) {
return Scaffold(
body: Column(
children: [
const SizedBox(
height: 20,
),
player,
const SizedBox(
height: 10,
),
Text(
widget.title,
style: const TextStyle(
color: textColorBlue,
fontWeight: FontWeight.bold,
fontSize: 30),
),
const SizedBox(
height: 15,
),
Text(
widget.artist,
style: const TextStyle(color: textColorBlack, fontSize: 20),
),
const SizedBox(
height: 10,
),
Text(
widget.duration,
style: const TextStyle(color: textColorBlack),
),
const SizedBox(
height: 10,
),
// ignore: unnecessary_null_comparison
author == null
? setAuthor()
: Text(
_controller.metadata.author,
style: const TextStyle(
color: Colors.pink,
fontWeight: FontWeight.bold,
fontSize: 25),
),
const SizedBox(
height: 15,
),
buttonRowBuilder(),
],
),
);
},
);
}
buttonRowBuilder() {
double size = 35;
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
onPressed: () {
if (_controller.value.position <= const Duration(seconds: 30)) {
_controller.seekTo(const Duration(seconds: 0));
} else {
var p = _controller.value.position - const Duration(seconds: 30);
_controller.seekTo(p);
}
},
icon: const Icon(Icons.replay_30, color: textColorBlue),
iconSize: size,
),
IconButton(
onPressed: () {
if (_controller.value.isPlaying) {
_controller.pause();
} else {
_controller.play();
}
setState(() {
isPlaying = !isPlaying;
});
},
icon: isPlaying
? const Icon(Icons.pause, color: textColorBlue)
: const Icon(Icons.play_arrow, color: textColorBlue),
iconSize: size,
),
IconButton(
onPressed: () {
var newPostion =
_controller.value.position + const Duration(seconds: 30);
_controller.seekTo(newPostion);
},
icon: const Icon(Icons.forward_30, color: textColorBlue),
iconSize: size,
),
IconButton(
onPressed: () {
if (isMute) {
_controller.unMute();
} else {
_controller.mute();
}
setState(() {
isMute = !isMute;
});
},
icon: isMute
? const Icon(Icons.volume_off, color: textColorBlue)
: const Icon(Icons.volume_up, color: textColorBlue),
iconSize: size,
),
],
);
}
that is my play yotube screen . Please help me solve the problem. When I press the video button to go to this screen, the application closes without any intervention
iam use flutter v 3.0.1 and i do not go to upgrade it and I think do everything
i add all permissions in AndroidManifest.xml
<uses-permission android:name=”android.permission.INTERNET” /> <uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE” />