Prerequisites
- A working Flutter quickstart
- Advanced filters enabled for both native projects
- An asset declared in
pubspec.yaml
Load and apply an image
final data = await rootBundle.load( 'assets/backgrounds/studio.jpg', ); final bytes = Uint8List.sublistView(data); await NosmaiFlutter.instance.setBackgroundSegmentation( NosmaiBackgroundSegmentationConfig.image(bytes), );
Use NosmaiBackgroundSegmentationConfig.color for a solid color or NosmaiBackgroundSegmentationConfig.video(localPath) for a readable local video.
Declare the asset
flutter:
assets:
- assets/backgrounds/studio.jpg
Clear it
await NosmaiFlutter.instance.clearBackgroundSegmentation();
Verify it worked
The background should change while the same preview widget remains mounted. Test iOS and Android separately because asset decoding and memory limits differ.
Common errors
| Symptom | Cause | Fix |
|---|---|---|
Unable to load asset | Asset is missing from pubspec.yaml | Declare the path, run flutter pub get, and rebuild |
| Video does not apply | A bundle URI or remote URL was passed | Copy it to a readable local file and pass the absolute path |
| Result works on one platform only | Native feature or project capability differs | Verify both app-bound keys and native artifact versions |