universal_file_viewer 0.1.2 copy "universal_file_viewer: ^0.1.2" to clipboard
universal_file_viewer: ^0.1.2 copied to clipboard

A Flutter package to preview images, videos, PDFs, Word, Excel, CSV, PPT, and more.

example/lib/main.dart

import 'dart:io';

import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:universal_file_viewer/universal_file_viewer.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(title: 'File Viewer Test', home: FileViewerScreen());
  }
}

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

  @override
  FileViewerScreenState createState() => FileViewerScreenState();
}

class FileViewerScreenState extends State<FileViewerScreen> {
  String? _filePath;

  Future<void> _pickFile() async {
    FilePickerResult? result = await FilePicker.platform.pickFiles();

    if (result != null) {
      setState(() {
        _filePath = result.files.single.path;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Universal File Viewer Example')),
      body: Column(
        children: [
          ElevatedButton(
            onPressed: _pickFile,
            child: const Text('Pick a File'),
          ),
          const SizedBox(height: 20),
          Expanded(
            key: ValueKey(_filePath),
            child:
                _filePath == null
                    ? const Center(child: Text('No file selected'))
                    : UniversalFileViewer(
                      file: File.fromUri(Uri.parse(_filePath!)),
                    ),
          ),
        ],
      ),
    );
  }
}
31
likes
140
points
383
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package to preview images, videos, PDFs, Word, Excel, CSV, PPT, and more.

Homepage
Repository (GitHub)

Topics

#filepreviewer #widget #package

Documentation

API reference

License

MIT (license)

Dependencies

archive, docx_file_viewer, excel, flutter, markdown, open_file, path, path_provider, pdfrx, shimmer, video_player, webview_flutter, webview_flutter_web, xml

More

Packages that depend on universal_file_viewer