-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from Bablo-AD/dev
Dev
- Loading branch information
Showing
19 changed files
with
161 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,87 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:youtube_player_flutter/youtube_player_flutter.dart'; | ||
import 'package:url_launcher/url_launcher.dart'; | ||
|
||
class VideoPage extends StatelessWidget { | ||
class VideoPage extends StatefulWidget { | ||
final String videoId; | ||
final String description; | ||
|
||
const VideoPage( | ||
{super.key, required this.videoId, required this.description}); | ||
const VideoPage({Key? key, required this.videoId, required this.description}) | ||
: super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final youtubePlayerController = YoutubePlayerController( | ||
initialVideoId: videoId, | ||
_VideoPageState createState() => _VideoPageState(); | ||
} | ||
|
||
class _VideoPageState extends State<VideoPage> { | ||
late final YoutubePlayerController youtubePlayerController; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
SystemChrome.setPreferredOrientations([ | ||
DeviceOrientation.portraitUp, | ||
DeviceOrientation.portraitDown, | ||
]); | ||
|
||
youtubePlayerController = YoutubePlayerController( | ||
initialVideoId: widget.videoId, | ||
flags: const YoutubePlayerFlags( | ||
autoPlay: false, | ||
), | ||
); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
SystemChrome.setPreferredOrientations([ | ||
DeviceOrientation.portraitUp, | ||
DeviceOrientation.portraitDown, | ||
]); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar(title: const Text('Mentor/Video')), | ||
body: Padding( | ||
padding: const EdgeInsets.all(16.0), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
body: YoutubePlayerBuilder( | ||
player: YoutubePlayer( | ||
controller: youtubePlayerController, | ||
showVideoProgressIndicator: true, | ||
progressIndicatorColor: const Color.fromARGB(255, 50, 204, 102), | ||
), | ||
builder: (context, player) { | ||
return Column( | ||
children: [ | ||
IconButton( | ||
icon: const Icon(Icons.open_in_browser, | ||
color: Color.fromARGB(255, 50, 204, 102)), | ||
onPressed: () { | ||
_launchURL(videoId); | ||
_launchURL(widget.videoId); | ||
}, | ||
), | ||
const SizedBox( | ||
height: 2, | ||
), | ||
YoutubePlayer( | ||
controller: youtubePlayerController, | ||
showVideoProgressIndicator: true, | ||
progressIndicatorColor: | ||
const Color.fromARGB(255, 50, 204, 102), | ||
), | ||
// some widgets | ||
player, | ||
const SizedBox(height: 16.0), | ||
Text(description), | ||
])), | ||
Text(widget.description), | ||
//some other widgets | ||
], | ||
); | ||
}), | ||
); | ||
} | ||
} | ||
|
||
_launchURL(String videoId) async { | ||
final url = 'https://www.youtube.com/watch?v=$videoId'; | ||
Uri uri = Uri.parse(url); | ||
if (!await canLaunchUrl(uri)) { | ||
throw Exception('Could not launch $url'); | ||
_launchURL(String videoId) async { | ||
final url = 'https://www.youtube.com/watch?v=$videoId'; | ||
Uri uri = Uri.parse(url); | ||
if (!await canLaunchUrl(uri)) { | ||
throw Exception('Could not launch $url'); | ||
} | ||
await launchUrl(uri); | ||
} | ||
await launchUrl(uri); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.