main.dart 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import 'package:chewie_example/chewie_player.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:video_player/video_player.dart';
  5. void main() => runApp(new ChewieDemo());
  6. const String butterflyUri =
  7. 'https://flutter.github.io/assets-for-api-docs/videos/butterfly.mp4';
  8. class ChewieDemo extends StatefulWidget {
  9. final String title;
  10. ChewieDemo({this.title = 'Chewie Demo'});
  11. @override
  12. State<StatefulWidget> createState() {
  13. return new _ChewieDemoState();
  14. }
  15. }
  16. class _ChewieDemoState extends State<ChewieDemo> {
  17. final controller = new VideoPlayerController(
  18. butterflyUri,
  19. );
  20. TargetPlatform _platform;
  21. @override
  22. Widget build(BuildContext context) {
  23. return new MaterialApp(
  24. title: widget.title,
  25. theme: new ThemeData.light().copyWith(
  26. platform: _platform ?? Theme.of(context).platform,
  27. ),
  28. home: new Scaffold(
  29. appBar: new AppBar(
  30. title: new Text(widget.title),
  31. ),
  32. body: new Column(
  33. children: <Widget>[
  34. new Expanded(
  35. child: new Center(
  36. child: new ChewiePlayer(
  37. controller: controller,
  38. aspectRatio: 3 / 2,
  39. looping: true,
  40. autoPlay: true,
  41. ),
  42. ),
  43. ),
  44. new Row(
  45. children: <Widget>[
  46. new Expanded(
  47. child: new FlatButton(
  48. onPressed: () {
  49. setState(() {
  50. _platform = TargetPlatform.android;
  51. });
  52. },
  53. child: new Padding(
  54. child: new Text("Android controls"),
  55. padding: new EdgeInsets.symmetric(vertical: 16.0),
  56. ),
  57. )),
  58. new Expanded(
  59. child: new FlatButton(
  60. onPressed: () {
  61. setState(() {
  62. _platform = TargetPlatform.iOS;
  63. });
  64. },
  65. child: new Padding(
  66. padding: new EdgeInsets.symmetric(vertical: 16.0),
  67. child: new Text("iOS controls"),
  68. )),
  69. )
  70. ],
  71. )
  72. ],
  73. ),
  74. ),
  75. );
  76. }
  77. }