universal_file_previewer 0.3.0
universal_file_previewer: ^0.3.0 copied to clipboard
Preview 50+ file formats (PDF, images, video, audio, code, zip, markdown, CSV, JSON and more) with zero heavy dependencies. Uses pure Dart + native platform channels.
universal_file_previewer #
Preview 50+ file formats in Flutter with zero heavy dependencies.
Uses pure Dart for text-based formats and native platform channels for PDF, video, and audio.
β¨ Supported Formats #
| Category | Formats | Renderer |
|---|---|---|
| Images | JPG, PNG, GIF, WebP, BMP, SVG, HEIC, TIFF | Flutter native |
| Platform channel | ||
| Video | MP4, MOV, AVI, MKV, WebM | Platform channel |
| Audio | MP3, WAV, AAC, FLAC, OGG | Platform channel |
| Code | Dart, Python, JS, TS, Kotlin, Java, + more | Pure Dart |
| Text | TXT, Markdown, CSV, JSON, XML, HTML, LOG | Pure Dart |
| Archive | ZIP (browsable file tree) | Pure Dart |
| Docs | DOCX, XLSX, PPTX (metadata view) | Fallback |
| Unknown | Any file β metadata + size + type | Fallback |
π Installation #
dependencies:
universal_file_previewer: ^0.3.0
π± Quick Start #
Full-screen preview page #
import 'package:universal_file_previewer/universal_file_previewer.dart';
// From local file
FilePreviewPage.open(context, file: File('/path/to/document.pdf'));
// From URL (automatically downloaded and cached)
FilePreviewPage.open(context, url: 'https://example.com/document.pdf');
Inline widget #
// Local
FilePreviewWidget(file: File('/path/to/file.md'))
// Remote
FilePreviewWidget(url: 'https://example.com/file.md')
With controller (PDF page navigation) #
final controller = PreviewController();
// Widget
FilePreviewWidget(
file: myPdfFile,
controller: controller,
)
// Control programmatically
controller.nextPage();
controller.previousPage();
controller.goToPage(5);
controller.zoomIn();
controller.zoomOut();
Detect file type only #
final type = await FileDetector.detect(File('/path/to/file'));
print(type); // FileType.pdf
// From bytes
final type = FileDetector.detectFromBytes(bytes, fileName: 'doc.pdf');
βοΈ Configuration #
PreviewConfig(
showToolbar: true, // Show AppBar (in FilePreviewPage)
showFileInfo: true, // Show info button in toolbar
enableZoom: true, // Pinch-to-zoom for images & PDF
backgroundColor: Colors.black,
codeTheme: CodeTheme.dark, // dark | light | dracula | monokai
maxTextFileSizeBytes: 5 * 1024 * 1024, // 5 MB limit for text files
errorBuilder: (err) => MyErrorWidget(err),
loadingBuilder: () => MyLoadingWidget(),
)
ποΈ Architecture #
FilePreviewWidget
β
βββ FileDetector β Magic bytes + extension fallback
β βββ Pure Dart, reads first 16 bytes
β
βββ ImageRenderer β Flutter Image.file + InteractiveViewer
βββ SvgRenderer β Pure Dart SVG content display
βββ HeicRenderer β Platform channel β JPEG conversion
β
βββ PdfRenderer β Platform channel (PDFKit / PdfRenderer API)
β
βββ VideoRenderer β Platform channel (AVPlayer / ExoPlayer)
βββ AudioRenderer β Platform channel + animated waveform UI
β
βββ TextRenderer β Pure Dart, SelectableText
βββ MarkdownRenderer β Pure Dart parser, no packages
βββ JsonRenderer β Pure Dart collapsible tree
βββ CsvRenderer β Pure Dart DataTable
βββ CodeRenderer β Pure Dart syntax tokenizer
β
βββ ZipRenderer β Pure Dart ZIP spec parser (browsable tree)
β
βββ FallbackRenderer β File metadata (name, size, type, date)
π¦ Dependencies #
dependencies:
flutter:
sdk: flutter
http: ^1.2.1
path_provider: ^2.1.3
π Platform Requirements #
Android
minSdkVersion 21(PDF rendering requires API 21+)HEIC supportrequires Android 9+ (API 28+)
iOS
iOS 11.0+- PDFKit available since iOS 11
Add to android/app/build.gradle:
android {
defaultConfig {
minSdkVersion 21
}
}
πΊοΈ Roadmap #
- β Image rendering (JPG, PNG, GIF, WebP, BMP)
- β SVG display
- β PDF rendering (platform channel)
- β Video thumbnail + metadata
- β Audio player UI with waveform
- β Markdown renderer (pure Dart)
- β JSON tree viewer (pure Dart)
- β CSV table renderer (pure Dart)
- β Syntax highlighted code viewer (pure Dart)
- β ZIP archive browser (pure Dart)
- β HEIC conversion (platform channel)
- β DOCX β HTML conversion (pure Dart XML parser)
- β XLSX spreadsheet renderer (pure Dart)
- β PPTX slide viewer
- β 3D model viewer (GLB/OBJ)
- β RAR/7Z archive support
- β Thumbnail generation API
π€ Contributing #
PRs welcome! Please read CONTRIBUTING.md first.
git clone https://github.com/Naimish-Kumar/universal_file_previewer
cd universal_file_previewer
flutter pub get
cd example && flutter run
π License #
MIT License β see LICENSE for details.