fc_native_video_thumbnail 0.1.0 copy "fc_native_video_thumbnail: ^0.1.0" to clipboard
fc_native_video_thumbnail: ^0.1.0 copied to clipboard

outdated

A Flutter plugin for getting video thumbnails with native APIs.

example/lib/main.dart

import 'dart:io';

import 'package:fc_native_video_thumbnail/fc_native_video_thumbnail.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:tmp_path/tmp_path.dart';
import 'package:path/path.dart' as p;

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String? _destImg;
  String? _err;
  String _imgSizeInfo = '';
  final _plugin = FcNativeVideoThumbnail();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: _destImg == null
              ? Text(_err ?? 'Click on the + button to select a photo')
              : Column(
                  children: [
                    SelectableText(_destImg!),
                    Text(_imgSizeInfo),
                    Image(image: FileImage(File(_destImg!)))
                  ],
                ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: _selectImage,
          tooltip: 'Select an image',
          child: const Icon(Icons.add),
        ),
      ),
    );
  }

  Future<void> _selectImage() async {
    try {
      var result = await FilePicker.platform.pickFiles();
      if (result == null) {
        return;
      }
      var src = result.files.single.path!;
      var dest = tmpPath() + p.extension(src);
      setState(() {
        _err = null;
      });
      await _plugin.getThumbnailFile(
          srcFile: src,
          destFile: dest,
          width: 300,
          height: 300,
          keepAspectRatio: true,
          type: 'jpeg');
      var imageFile = File(dest);
      var decodedImage = await decodeImageFromList(imageFile.readAsBytesSync());
      setState(() {
        _destImg = dest;
        _imgSizeInfo =
            'Decoded size: ${decodedImage.width}x${decodedImage.height}';
      });
    } catch (err) {
      setState(() {
        _err = err.toString();
      });
    }
  }
}
35
likes
0
points
9.6k
downloads

Publisher

verified publisherflutter-cavalry.com

Weekly Downloads

A Flutter plugin for getting video thumbnails with native APIs.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on fc_native_video_thumbnail