RSPL Network File Viewer
RSPLNetworkFileViewer is a customizable Flutter widget designed to display files like images and PDFs directly from a network source. It supports various customization options for appearance, headers, and error handling.
Features
- Supports multiple file types, including images and PDFs.
- Customizable UI with background color, content padding, and optional custom header.
- Provides HTTP headers for secure or authenticated file access.
- Includes a fallback error widget for better user experience.

Platform Support
- Android β API Level: 21
- Android Version: Android 5.0
- iOS β iOS 13.0+
Requirements
- Dart: >=3.4.0 <4.0.0
- Flutter: Flutter 3.24.0+ based on Dart 3.4.0
- iOS: >=13.0
- Java: 1.8 (Java 8)
- Kotlin: 1.8.22
- Android Gradle Plugin: 8.1.0
- Gradle wrapper: 8.3
Permissions Required
- Android: INTERNET permission
- iOS: No explicit permissions
Description
A customizable Flutter widget for displaying images and PDFs directly from network URLs with built-in caching, customizable headers, and error handling. Supports authenticated file access via custom HTTP headers and provides a flexible UI with optional custom header and error widgets.
Highlights / Features
β’ π Multi-format support: Display images (PNG, JPG, JPEG, GIF, BMP, TIFF) and PDF documents from network URLs
β’ π¨ Customizable UI: Background colors, content padding, custom headers, and error widgets for branding and UX
β’ π Authentication ready: Custom HTTP headers support for secure file access with Bearer tokens, API keys, and custom authentication
β’ πΎ Smart caching: Built-in PDF caching for offline access and improved performance with automatic cache management
β’ π Enhanced image viewing: Double-tap zoom functionality for images with smooth pinch-to-zoom gestures
β’ π‘οΈ Error handling: Default error widgets with theme-aware styling, plus support for custom error displays
β’ π§ͺ Well-tested: Comprehensive unit tests covering all widgets and core functionality
β’ π Easy integration: Simple API with minimal setupβjust provide file type, URL, and optional customization parameters
β’ π± Platform optimized: Works seamlessly on Android and iOS with proper theme integration and Material Design support
β’ π― Flexible: Use default widgets or provide completely custom header and error widgets for full control over the viewing experience
Getting Started
1) Install
Add the dependency to your pubspec.yaml:
dependencies:
rspl_network_file_viewer: ^1.0.1
Then run:
flutter pub get
2) Import
import 'package:rspl_network_file_viewer/rspl_network_file_viewer.dart';
Usage
Minimal
NetworkFileViewer(
fileType: NetworkFileType.image,
fileUrl: "https://example.com/image.jpg",
fileName: "Sample Image",
).showViewer(context);
Common example with authentication and customization
NetworkFileViewer(
fileType: NetworkFileType.pdf,
fileUrl: "https://api.example.com/documents/report.pdf",
fileName: "Annual Report 2024",
customHttpHeaders: {
"Authorization": "Bearer $token",
"Accept": "application/pdf",
},
backGroundColor: Colors.grey.shade100,
contentPadding: const EdgeInsets.all(16.0),
customHeaderWidget: CustomHeaderWidget(
title: "Annual Report 2024",
onClose: () => Navigator.of(context).pop(),
),
errorWidget: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.error_outline, size: 48, color: Colors.red),
const SizedBox(height: 16),
Text(
"Failed to load document",
style: Theme.of(context).textTheme.titleMedium,
),
],
),
),
).showViewer(context);
Image with double-tap zoom
NetworkFileViewer(
fileType: NetworkFileType.image,
fileUrl: "https://example.com/photo.jpg",
fileName: "Photo",
backGroundColor: Colors.black,
contentPadding: EdgeInsets.zero,
).showViewer(context);
Configuration
| Property | Type | Default | Description |
|---|---|---|---|
fileType |
NetworkFileType |
required | Type of file to display: NetworkFileType.image or NetworkFileType.pdf |
fileUrl |
String |
required | Network URL of the file to load and display |
fileName |
String? |
null |
File name displayed in the header. Required if customHeaderWidget is null |
customHttpHeaders |
Map<String, String>? |
null |
Optional HTTP headers for authentication or custom requests (e.g., {"Authorization": "Bearer token"}) |
backGroundColor |
Color? |
Theme.colorScheme.surface |
Background color of the file viewer container |
contentPadding |
EdgeInsetsGeometry? |
EdgeInsets.zero |
Padding around the file viewer content |
customHeaderWidget |
Widget? |
DefaultHeaderWidget |
Custom widget to replace the default header. If null, uses DefaultHeaderWidget with fileName |
errorWidget |
Widget? |
DefaultErrorWidget |
Custom widget displayed when file loading fails. If null, uses DefaultErrorWidget |
Note:
fileNameis required whencustomHeaderWidgetisnull(enforced by assertion)- Images support double-tap zoom functionality automatically
- PDFs are cached automatically for offline access
- All default widgets use theme-aware colors from
ThemeData.colorScheme
Theming & Accessibility
β’ Theme integration: Uses Theme.of(context).colorScheme by default:
colorScheme.surfacefor the main viewer container backgroundcolorScheme.errorfor error icons inDefaultErrorWidgetcolorScheme.onSurfacefor text colors with proper alpha valuestextTheme.headlineSmallfor header titles with theme-aware typography
β’ Theme-aware widgets: Default widgets (DefaultHeaderWidget, DefaultErrorWidget) automatically adapt to your app's ThemeData and ColorScheme without additional configuration
β’ Customizable colors: Optional backGroundColor parameter allows overriding the default theme color while maintaining theme consistency for other elements
β’ Contrast: Text colors use theme-aware onSurface with alpha values, but no explicit contrast validation
Performance
β’ Automatic caching: PDFs are cached using flutter_cached_pdfview for offline access and faster subsequent loads. Images use Flutter's built-in Image.network caching.
β’ StatelessWidget architecture: All widgets use StatelessWidget to avoid unnecessary rebuilds and minimize memory overhead.
β’ No custom shaders or painters: Uses standard Flutter widgets that work efficiently across web, mobile, and desktop platforms.
β’ Asynchronous loading: Files load asynchronously with progress indicators, preventing UI blocking during network requests.
β’ Optimized modal presentation: Uses showModalBottomSheet with isScrollControlled for efficient rendering and memory management.
β’ For lists: When displaying multiple file viewers in a list, wrap individual items in RepaintBoundary and avoid rebuilding the NetworkFileViewer instance unnecessarily.
Folder Structure
rspl_network_file_viewer/
ββ lib/
β ββ rspl_network_file_viewer.dart # Main package export file
β ββ src/
β ββ enum/
β β ββ network_file_type.dart # Enum for file types (image, PDF, etc.)
β ββ network_file_viewer.dart # Main NetworkFileViewer widget implementation
β ββ widgets/
β ββ default_error_widget.dart # Default error display widget
β ββ default_header_widget.dart # Default header widget for file viewer
ββ example/
β ββ lib/
β ββ example_page.dart # Example page demonstrating the package
β ββ main.dart # Example app entry point
ββ test/
β ββ src/
β ββ network_file_viewer_test.dart # Tests for main NetworkFileViewer widget
β ββ widgets/
β ββ default_error_widget_test.dart # Tests for error widget
β ββ default_header_widget_test.dart # Tests for header widget
ββ analysis_options.yaml # Dart/Flutter linting configuration
ββ CHANGELOG.md # Package version history
ββ LICENSE # License file
ββ CODE_OF_CONDUCT.md # Code of conduct file
ββ CONTRIBUTING.md # Contributing file
ββ README.md # Package documentation
ββ pubspec.yaml # Package dependencies and metadata
Example
For a complete example, see the example directory.
Keywords and Tags
flutter dart network file-viewer pdf-viewer image-viewer document-viewer network-file cached-pdf image-zoom file-display http-headers authentication modal-viewer
Contributing
Contributions welcome! Please read:
- CONTRIBUTING.md β setup, branch strategy, commit convention
- CODE_OF_CONDUCT.md
Run checks before push:
dart format .flutter analyzeflutter test
User Privacy Notes
- This package does not collect any user information or share data with third-party services.
Author, Maintainers & Acknowledgements
- Developed by Rishabh Software.
- Thanks to the Flutter community for the amazing packages used in this project.
License
This package is licensed under the MIT License. See LICENSE for details.