Flutter
Add Nosmai Effects to a Flutter app: camera preview, beauty, makeup, color, filters, capture and recording.
Install
Add the plugin to pubspec.yaml, then run flutter pub get.
dependencies:
nosmai_camera_sdk: ^3.0.5
iOS. Set the platform to 14.0 and use static frameworks in ios/Podfile:
platform :ios, '14.0'
target 'Runner' do
use_frameworks! :linkage => :static
use_modular_headers!
flutter_install_all_ios_pods(File.dirname(File.realpath(__FILE__)))
end
Add NSCameraUsageDescription, NSMicrophoneUsageDescription and NSPhotoLibraryAddUsageDescription to ios/Runner/Info.plist.
Android. Download nosmai-release.aar from the Flutter plugin releases into android/app/libs/, then:
allprojects {
repositories {
google()
mavenCentral()
flatDir { dirs "${rootProject.projectDir}/app/libs" }
}
}
dependencies {
implementation files('libs/nosmai-release.aar')
}
Add the CAMERA, RECORD_AUDIO and INTERNET permissions to android/app/src/main/AndroidManifest.xml.
Requirements: Flutter 3.22.0+, Dart 3.4.0+, iOS 14.0+ / Android API 26+, a physical device with a camera.
Initialize
import 'package:nosmai_camera_sdk/nosmai_camera_sdk.dart';
final ok = await NosmaiFlutter.initialize('YOUR_LICENSE_KEY');
Camera preview
// in your widget tree
const NosmaiCameraPreview();
final nosmai = NosmaiFlutter.instance;
await nosmai.startProcessing();
// later
await nosmai.stopProcessing();
Camera controls
await nosmai.configureCamera(NosmaiCameraPosition.front);
await nosmai.switchCamera();
if (await nosmai.hasTorch()) {
await nosmai.setTorchMode(NosmaiTorchMode.on);
}
await nosmai.setFlashMode(NosmaiFlashMode.auto);
Beauty and makeup
Beauty and makeup intensities are 0.0 to 10.0.
await nosmai.applySkinSmoothing(5.0);
await nosmai.applySkinWhitening(3.0);
await nosmai.applyFaceSlimming(4.0);
await nosmai.applyEyeEnlargement(4.0);
await nosmai.applyNoseSize(3.0);
await nosmai.applyLipstick(6.0);
await nosmai.applyBlusher(4.0);
await nosmai.applyMakeupBlendLevel('lipstick', 0.7); // 0.0 - 1.0
Color adjustments
await nosmai.applyBrightnessFilter(0.2); // -1.0 to 1.0
await nosmai.applyContrastFilter(1.2); // 0.0 to 2.0
await nosmai.applySharpening(4.0); // 0.0 to 10.0
await nosmai.applyRGBFilter(red: 1.1, green: 1.0, blue: 0.9);
await nosmai.adjustHSB(hue: 10.0, saturation: 1.2, brightness: 0.1);
await nosmai.applyWhiteBalance(temperature: 5500.0, tint: 0.0);
await nosmai.applyGrayscaleFilter();
await nosmai.resetHSBFilter();
Filters
// Local filters from assets/filters/
final localFilters = await nosmai.getLocalFilters();
// All filters (local and cloud); pass forceRefresh to bypass the 5 minute cache
final allFilters = await nosmai.getFilters();
// Apply by path or name
await nosmai.applyFilter('assets/filters/vintage.nosmai');
await nosmai.removeAllFilters(); // remove everything
await nosmai.removeBuiltInFilters(); // keep .nosmai filters, drop beauty/color
Cloud filters.
if (await nosmai.isCloudFilterEnabled()) {
final cloud = await nosmai.getCloudFilters();
final result = await nosmai.downloadCloudFilter('halloween_2024');
if (result['success'] == true) {
await nosmai.applyFilter(result['path']);
}
}
Capture and recording
final photo = await nosmai.capturePhoto(); // NosmaiPhotoResult
await nosmai.saveImageToGallery(photo.imageData!, name: 'my_photo');
await nosmai.startRecording();
final video = await nosmai.stopRecording(); // NosmaiRecordingResult
await nosmai.saveVideoToGallery(video.videoPath!, name: 'my_video');
Event streams
nosmai.onError.listen((e) { /* NosmaiError */ });
nosmai.onDownloadProgress.listen((p) { /* download progress */ });
nosmai.onRecordingProgress.listen((seconds) { /* recording duration */ });
Navigation and cleanup
When you navigate away from and back to the camera screen, detach and reinitialize the preview. Always clean up on dispose.
await nosmai.detachCameraView(); // before leaving
await nosmai.reinitializePreview(); // when returning
await nosmai.cleanup();
await nosmai.dispose();
NOTE
Beauty and color methods are async. They run native processing off the platform thread, so the UI stays responsive.