A Flutter SDK for document capture and analysis using camera and WASM models. Easy to integrate and distribute.
- 📱 Flutter Native: Built entirely in Flutter for cross-platform compatibility
- 📷 Camera Integration: Direct camera access for high-quality image capture
- 🌐 WebView Integration: Loads local webapp with WASM models for analysis
- 🔒 Permission Handling: Automatic camera and storage permission management
- ⚡ Easy Integration: Simple function calls to start document capture
- 📦 Asset Bundling: Includes webapp and WASM models in the package
- 🎯 Customizable: Configurable image quality, max images, and more
Add this to your pubspec.yaml:
dependencies:
snapcap_flutter_sdk:
git:
url: https://github.com/your-org/snapcap_flutter_sdk.git
ref: maindependencies:
snapcap_flutter_sdk:
path: ../snapcap_flutter_sdkdependencies:
snapcap_flutter_sdk: ^0.0.1import 'package:snapcap_flutter_sdk/snapcap_flutter_sdk.dart';
void main() async {
// Initialize the SDK with your configuration
final config = SnapCapConfig(
token: 'YOUR_API_TOKEN',
cpf: 'USER_CPF_NUMBER', // Optional
environment: SnapCapEnvironment.dev,
maxImages: 5,
imageQuality: 0.8,
);
await SnapCapSDK.instance.initialize(config);
runApp(MyApp());
}class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('SnapCap Demo')),
body: Center(
child: ElevatedButton(
onPressed: () => _startDocumentCapture(context),
child: Text('Start Document Capture'),
),
),
);
}
Future<void> _startDocumentCapture(BuildContext context) async {
try {
await SnapCapSDK.instance.startDocumentCapture(
context,
callback: MySnapCapCallback(),
);
} catch (e) {
print('Error starting document capture: $e');
}
}
}class MySnapCapCallback implements SnapCapCallback {
@override
void onEvent(String event) {
print('SDK Event: $event');
}
@override
void onError(SnapCapError error) {
print('SDK Error: ${error.message}');
}
@override
void onDocumentCaptureComplete(SnapCapResult result) {
print('Document capture complete!');
print('Images: ${result.imagePaths}');
print('Analysis: ${result.analysisData}');
// Handle the captured images and analysis results
_processResults(result);
}
@override
void onCancelled() {
print('Document capture was cancelled');
}
// Implement other callback methods as needed...
@override
void onLoadingEnd() {}
@override
void onProcessingStatus(SnapCapProcessingStatus status) {}
@override
void onCameraReady() {}
@override
void onWebappLoaded() {}
@override
void onWasmModelsLoaded() {}
void _processResults(SnapCapResult result) {
// Process the captured images and analysis data
// You can save images, send to server, etc.
}
}| Parameter | Type | Default | Description |
|---|---|---|---|
token |
String | Required | API token for authentication |
cpf |
String? | null | User's CPF number (Brazilian ID) |
base64Photo |
String? | null | Base64 encoded registration photo |
environment |
SnapCapEnvironment | dev | Environment (dev/stg/prd) |
useTwa |
bool | false | Use Trusted Web Activity |
fallbackToWebView |
bool | true | Fallback to WebView if TWA fails |
customWebappUrl |
String? | null | Custom webapp URL |
customModelsUrl |
String? | null | Custom WASM models URL |
maxImages |
int | 5 | Maximum number of images to capture |
imageQuality |
double | 0.8 | Image quality (0.1 to 1.0) |
debugMode |
bool | false | Enable debug mode |
customHeaders |
Map<String, String> | {} | Custom headers for requests |
enum SnapCapEnvironment {
dev, // Development
stg, // Staging
prd, // Production
}The SDK provides comprehensive error handling through the SnapCapError enum:
enum SnapCapError {
invalidConfig, // Invalid configuration
cameraPermissionDenied, // Camera permission denied
cameraNotAvailable, // Camera not available
webViewError, // WebView error
networkError, // Network error
wasmModelError, // WASM model loading error
documentProcessingError, // Document processing error
unknown, // Unknown error
}The SnapCapResult class contains all the captured data:
class SnapCapResult {
final List<String> imagePaths; // Paths to captured images
final Map<String, dynamic> analysisData; // Analysis results from WASM
final SnapCapProcessingStatus status; // Processing status
final DateTime timestamp; // When result was generated
final Map<String, dynamic> metadata; // Additional metadata
}final config = SnapCapConfig(
token: 'YOUR_TOKEN',
customWebappUrl: 'https://your-custom-webapp.com',
customModelsUrl: 'https://your-models.com',
);final config = SnapCapConfig(
token: 'YOUR_TOKEN',
debugMode: true, // Enables detailed logging
);final config = SnapCapConfig(
token: 'YOUR_TOKEN',
customHeaders: {
'X-Custom-Header': 'value',
'Authorization': 'Bearer token',
},
);- ✅ Android: Full support with camera and WebView
- ✅ iOS: Full support with camera and WebView
- ❌ Web: Not supported (requires camera access)
- ❌ Desktop: Limited support (no camera access)
The SDK automatically requests these permissions:
- Camera: Required for document capture
- Storage: Required for saving captured images
-
Camera Permission Denied
- Ensure camera permission is granted in app settings
- Check if camera is available on the device
-
WebView Not Loading
- Verify internet connection if using custom webapp
- Check if bundled webapp assets are properly included
-
WASM Models Not Loading
- Ensure WASM models are properly bundled
- Check browser compatibility
Enable debug mode to get detailed logging:
final config = SnapCapConfig(
token: 'YOUR_TOKEN',
debugMode: true,
);- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- 📧 Email: support@snapcap.com
- 📱 GitHub Issues: Create an issue
- 📚 Documentation: Full documentation
- Initial release
- Basic document capture functionality
- Camera integration
- WebView integration
- WASM model support
- Permission handling
- Error handling
- Callback system