deepar_flutter_perfect 0.0.3
deepar_flutter_perfect: ^0.0.3 copied to clipboard
DeepAR Flutter plugin with full support for all Android devices—including Xiaomi—and iOS. Easily load AR effects from assets, file paths, or URLs for smooth, reliable performance everywhere.
deepar_flutter_perfect #
An enhanced Flutter plugin based on the official DeepAR SDK, providing robust support for loading AR effects from assets, file paths, and URLs with automatic caching. This enables loading effects stored locally or directly from the internet, ensuring smooth AR experiences on all Android devices—including Xiaomi—and iOS.
This plugin is a fork of the official DeepAR Flutter SDK. Supported platforms: Android (SDK 23+) and iOS (13.0+).
Features #
- Load AR effects from assets, file paths, and remote URLs with caching ✨ (New!)
- Live AR preview ✅
- Take screenshots ✅
- Record videos ✅
- Flip camera ✅
- Toggle flash ✅
Android SDK 23+
Breaking Changes #
- v0.1.7: The
initialize()method now returns anInitializeResultobject withsuccessandmessageproperties (not just a boolean). See Flutter usage for updated code. - v0.1.9: Updated iOS implementation with improved compatibility and effect loading.
- v0.1.8: Improved iOS camera initialization and error handling.
Installation #
Before you begin #
Visit the DeepAR developer site to create a project and obtain license keys for Android and iOS.
Android #
-
Set
compileSdkVersionto 33 or higher andminSdkVersionto 23 or higher. -
Download native Android dependencies from downloads and place
deepar.aarintoandroid/app/libs/. -
Run:
flutter clean flutter pub upgrade -
Add these permissions to your
AndroidManifest.xml:<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.RECORD_AUDIO"/> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.INTERNET" /> -
Add these rules to
proguard-rules.proto prevent release crashes:-keepclassmembers class ai.deepar.ar.DeepAR { *; } -keepclassmembers class ai.deepar.ar.core.videotexture.VideoTextureAndroidJava { *; } -keep class ai.deepar.ar.core.videotexture.VideoTextureAndroidJava
iOS #
-
Set deployment target to iOS 13.0 or later.
-
Run:
flutter clean flutter pub upgrade cd ios pod install -
Add these keys to your
Info.plistto request camera and microphone permissions:<key>NSCameraUsageDescription</key> <string>Camera access is required for AR effects</string> <key>NSMicrophoneUsageDescription</key> <string>Microphone access is required for recording videos</string> -
Add this snippet to your
ios/Podfilefor permission handler support:post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [ '$(inherited)', 'PERMISSION_CAMERA=1', 'PERMISSION_MICROPHONE=1', ] end end end
Flutter Usage #
- Initialize
DeepArControllerPerfectby passing your license keys:
final DeepArControllerPerfect _controller = DeepArControllerPerfect();
final result = await _controller.initialize(
androidLicenseKey: "---android key---",
iosLicenseKey: "---iOS key---",
resolution: Resolution.medium,
);
if (result.success) {
print("Initialization successful: ${result.message}");
if (Platform.isIOS) {
Timer.periodic(Duration(milliseconds: 500), (timer) {
if (_controller.isInitialized) {
print('iOS view fully initialized');
setState(() {});
timer.cancel();
} else if (timer.tick > 20) {
print('Timeout waiting for iOS view initialization');
timer.cancel();
}
});
}
} else {
print("Initialization failed: ${result.message}");
}
- Display the preview widget:
@override
Widget build(BuildContext context) {
return _controller.isInitialized
? DeepArPreviewPerfect(_controller)
: const Center(child: Text("Loading Preview"));
}
- Load effects from assets, file paths, or URLs:
await _controller.switchEffect("assets/effects/my_effect.deepar");
await _controller.switchEffect("/path/to/effect/file.deepar");
await _controller.switchEffect("https://example.com/effects/my_effect.deepar");
- Take screenshots:
final File file = await _controller.takeScreenshot();
- Record videos:
if (_controller.isRecording) {
_controller.stopVideoRecording();
} else {
final File videoFile = _controller.startVideoRecording();
}
For more details, visit DeepAR Developer Help.