This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Flutter plugin that provides native PDF viewing capabilities for iOS and Android platforms. The plugin wraps platform-specific PDF rendering libraries:
- iOS: Uses native PDFKit (iOS 11.0+)
- Android: Uses AndroidPdfViewer library (com.github.mhiew:android-pdf-viewer:3.2.0-beta.3)
# Install dependencies
flutter pub get
# Run tests
flutter test
# Run tests for a specific file
flutter test test/flutter_pdfview_test.dart
# Analyze code
flutter analyze
# Format code
dart format .# Run the example app
cd example
flutter pub get
flutter run
# Build example for specific platform
flutter build ios
flutter build apk# Dry run before publishing
flutter pub publish --dry-run
# Publish to pub.dev
flutter pub publishThe plugin follows Flutter's federated plugin architecture with platform-specific implementations:
-
Core Dart Interface (
lib/flutter_pdfview.dart):PDFViewwidget - Main widget that creates platform viewsPDFViewController- Controller for interacting with the PDF (page navigation, etc.)- Platform view creation using
UiKitView(iOS) andPlatformViewLink(Android)
-
Android Implementation (
android/src/main/java/io/endigo/plugins/pdfviewflutter/):PDFViewFlutterPlugin.java- Plugin registrationFlutterPDFView.java- Android view implementation wrapping AndroidPdfViewerPDFViewFactory.java- Factory for creating platform viewsPDFLinkHandler.java- Handles PDF link navigation
-
iOS Implementation (
ios/flutter_pdfview/Sources/flutter_pdfview/):PDFViewFlutterPlugin.m- Plugin registrationFlutterPDFView.m- iOS view implementation using PDFKit- Uses PDFView from PDFKit framework for rendering
- Flutter app creates
PDFViewwidget with configuration - Platform view is created via
plugins.endigo.io/pdfviewchannel - Native implementation renders PDF and sends callbacks via method channel
- Events flow back to Flutter:
onRender,onPageChanged,onError, etc.
- File Loading: From file path or binary data (Uint8List)
- Navigation: Page navigation, swipe gestures, horizontal/vertical scrolling
- Rendering Options: Night mode, auto-spacing, page snap, fit policies
- Security: Password-protected PDF support
- Callbacks: Page change, render complete, error handling, link handling
- Controller Methods:
getPageCount(),getCurrentPage(),setPage()
- Minimum iOS version: 11.0 (PDFKit requirement)
- Uses Swift Package Manager for dependency management
- Background color handling uses deprecated
.valuemethod (as of v1.4.1+1)
- Minimum SDK: 21
- Compile SDK: 35
- Uses AndroidX libraries
- ProGuard rules included for release builds
- Gradle 8.1.0 build tools
Tests are located in test/flutter_pdfview_test.dart and include:
- Widget creation and configuration tests
- Settings validation tests
- Error handling tests
- Mock method channel for platform communication
The example app (example/lib/main.dart) provides comprehensive testing scenarios:
- Loading from assets
- Loading from URL
- Corrupted PDF handling
- Landscape PDF rendering
- PDF with links
- Define the feature in the Dart interface (
lib/flutter_pdfview.dart) - Implement in Android (
android/src/main/java/) - Implement in iOS (
ios/flutter_pdfview/Sources/) - Add tests in
test/flutter_pdfview_test.dart - Update example app to demonstrate the feature
- Update README.md with feature documentation
- Android: Open
android/in Android Studio, attach debugger - iOS: Open
example/ios/Runner.xcworkspacein Xcode, use breakpoints
- Update version in
pubspec.yaml - Update CHANGELOG.md with changes
- Run tests and example app
- Publish using
flutter pub publish