YSVideoImage.dart 951 B

12345678910111213141516171819202122232425262728293031323334
  1. import 'dart:typed_data';
  2. import 'package:flutter/material.dart';
  3. import 'package:video_thumbnail/video_thumbnail.dart';
  4. class YSVideoImage extends StatefulWidget {
  5. final String path;
  6. const YSVideoImage({Key? key, required this.path}) : super(key: key);
  7. @override
  8. YSVideoImageState createState() => YSVideoImageState();
  9. }
  10. class YSVideoImageState extends State<YSVideoImage> {
  11. Uint8List? _uint8list;
  12. @override
  13. void initState() {
  14. _getListData();
  15. super.initState();
  16. }
  17. _getListData() async{
  18. _uint8list = await VideoThumbnail.thumbnailData(
  19. video: widget.path,
  20. imageFormat: ImageFormat.JPEG,
  21. maxWidth: 128, // specify the width of the thumbnail, let the height auto-scaled to keep the source aspect ratio
  22. quality: 25,
  23. );
  24. setState(() {});
  25. }
  26. @override
  27. Widget build(BuildContext context) {
  28. return _uint8list!=null?Image.memory(_uint8list!,fit: BoxFit.cover,):const SizedBox();
  29. }
  30. }