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

Generate a thumbnail for a file based on the file extension. Uses the native files previewer on iOS.

example/lib/main.dart

import 'package:file_picker/file_picker.dart';
import 'package:file_previewer/file_previewer.dart';
import 'package:flutter/material.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> {
  Widget? image;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              TextButton(
                child: const Text("Pick file"),
                onPressed: () async {
                  FilePickerResult? file =
                      await FilePicker.platform.pickFiles();
                  try {
                    if (file != null) {
                      final thumbnail = await FilePreview.getThumbnail(
                        file.files.first.path!,
                      );
                      setState(() {
                        image = thumbnail;
                      });
                    }
                  } catch (e) {
                    image = Image.asset("");
                  }
                },
              ),
              image != null
                  ? Container(
                      width: 210,
                      height: 297,
                      padding: const EdgeInsets.all(8.0),
                      color: Colors.white,
                      child: image,
                    )
                  : Container(),
            ],
          ),
        ),
      ),
    );
  }
}
43
likes
160
points
577
downloads

Publisher

verified publisherdutchcodingcompany.com

Weekly Downloads

Generate a thumbnail for a file based on the file extension. Uses the native files previewer on iOS.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, path, pdfx

More

Packages that depend on file_previewer