thumblr_macos 0.4.0 icon indicating copy to clipboard operation
thumblr_macos: ^0.4.0 copied to clipboard

PlatformmacOS

The macOS implementation of the thumblr plugin.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:thumblr_platform_interface/thumblr_platform_interface.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

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

class _MyAppState extends State<MyApp> {
  final _position = ValueNotifier<double>(0.0);
  Thumbnail? _thumbnail;

  @override
  void initState() {
    super.initState();
    getThumbnail();
  }

  void _onSeekPosition(double value) {
    _position.value = value;
  }

  void _onSeekEnd(double value) {
    _position.value = value;
    getThumbnail();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> getThumbnail() async {
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    Thumbnail? _result;
    try {
      _result = await ThumblrPlatform.instance.generateThumbnail(
        filePath:
            'https://stream-cloud-uploads.imgix.net/63735/attachments/81880b11-42d8-4cc5-849b-433346969fb0.C41A7960-7F94-4C1C-8D9F-6BF7EF313AB2_L0_0.MP4?dl=C41A7960-7F94-4C1C-8D9F-6BF7EF313AB2_L0_0.MP4&s=880dbbefde63c1232eee177b8913af21',
        position: _position.value,
      );
    } on PlatformException catch (e) {
      debugPrint('Failed to generate thumbnail: ${e.message}');
    } catch (e) {
      debugPrint('Failed to generate thumbnail: ${e.toString()}');
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() => _thumbnail = _result);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Material(
        child: Column(
          children: [
            Expanded(
              child: Padding(
                padding: const EdgeInsets.all(16.0),
                child: Center(
                  child: _thumbnail?.image != null
                      ? RawImage(image: _thumbnail?.image)
                      : const SizedBox.shrink(),
                ),
              ),
            ),
            Row(
              children: [
                const SizedBox(width: 8.0),
                const Text('0.0'),
                Expanded(
                  child: ValueListenableBuilder(
                    valueListenable: _position,
                    builder:
                        (BuildContext context, double value, Widget? child) {
                      return Slider(
                        min: 0.0,
                        max: _thumbnail?.videoDuration ?? 1.0,
                        value: value,
                        onChanged: _onSeekPosition,
                        onChangeEnd: _onSeekEnd,
                      );
                    },
                  ),
                ),
                Text('${_thumbnail?.videoDuration ?? 1.0}'),
                const SizedBox(width: 8.0),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
120
pub points
48%
popularity

Publisher

verified publisher icongroovinchip.dev

The macOS implementation of the thumblr plugin.

Homepage

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

Dependencies

flutter, thumblr_platform_interface

More

Packages that depend on thumblr_macos