Created
May 7, 2020 18:13
-
-
Save remylavergne/7927fa09122fcd7b9c9deb0908e0ea02 to your computer and use it in GitHub Desktop.
[Flutter] YouTube videos list simple
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
import 'package:flutter/material.dart'; | |
import 'package:youtube_player_flutter/youtube_player_flutter.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
// This widget is the root of your application. | |
final List<String> urls = [ | |
'UvBiN3BAxw4', // Aquafrolics | |
'ag6VBKD6JMA', | |
'kLWWCRb6hvY', | |
'zMVd9q-V-0c', | |
'LgHrooCU3wE', | |
]; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'YouTube Player PoC', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: Scaffold( | |
body: ListView.builder( | |
itemCount: this.urls.length, | |
itemBuilder: (BuildContext context, int index) { | |
return MonItem(url: this.urls[index]); | |
}), | |
), | |
); | |
} | |
} | |
class MonItem extends StatelessWidget { | |
final String url; | |
MonItem({Key key, this.url}) : super(key: key); | |
Widget build(BuildContext context) { | |
YoutubePlayerController _controller = YoutubePlayerController( | |
initialVideoId: this.url, | |
flags: YoutubePlayerFlags( | |
autoPlay: false, | |
mute: false, | |
), | |
); | |
return Container( | |
color: Colors.green[200], | |
margin: EdgeInsets.all(16.0), | |
height: 200.0, | |
child: YoutubePlayer( | |
controller: _controller, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment