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

outdated

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(),
            ],
          ),
        ),
      ),
    );
  }
}
40
likes
0
pub points
90%
popularity

Publisher

verified publisherdutchcodingcompany.com

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

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, native_pdf_renderer, path

More

Packages that depend on file_previewer