Last active
December 21, 2019 16:45
-
-
Save januwA/d712e24da1a2180afa2c177c24df8b0c to your computer and use it in GitHub Desktop.
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:video_box/video.controller.dart'; | |
import 'package:video_box/video_box.dart'; | |
import 'package:video_player/video_player.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp(home: HomePage()); | |
} | |
} | |
class HomePage extends StatefulWidget { | |
@override | |
_HomePageState createState() => _HomePageState(); | |
} | |
class _HomePageState extends State<HomePage> { | |
List<VideoController> vcs = []; | |
ScrollController controller = ScrollController(); | |
List<String> images = [ | |
"https://i.loli.net/2019/09/19/O1q543T2WostQ87.png", | |
"https://i.loli.net/2019/08/09/OvVzMqpF3jmI8lE.jpg", | |
"https://i.loli.net/2019/10/01/CVBu2tNMqzOfXHr.png" | |
]; | |
@override | |
void initState() { | |
super.initState(); | |
for (var img in images) { | |
var c = VideoController( | |
source: VideoPlayerController.network( | |
"https://gss3.baidu.com/6LZ0ej3k1Qd3ote6lo7D0j9wehsv/tieba-smallvideo/3_49a2cc6bf08f1c3733b86a2a90fb927b.mp4"), | |
cover: Center( | |
child: Image.network( | |
img, | |
fit: BoxFit.contain, | |
), | |
), | |
); | |
c.setControllerLayer(show: false); | |
c.initialize(); | |
vcs.add(c); | |
} | |
} | |
@override | |
void dispose() { | |
for (var vc in vcs) { | |
vc.dispose(); | |
} | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: ListView( | |
controller: controller, | |
children: <Widget>[ | |
for (var vc in vcs) | |
Padding( | |
padding: const EdgeInsets.only(top: 12.0), | |
child: AspectRatio( | |
aspectRatio: 16 / 9, | |
child: VideoBox(controller: vc), | |
), | |
), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment