### Install iOS pods Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Navigate to the ios directory and install the required pods. ```bash cd ios && pod install ``` -------------------------------- ### Install dependencies Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Run this command in your terminal to fetch the added package. ```bash flutter pub get ``` -------------------------------- ### Model Management Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Methods for managing the ML Kit model required for background removal on Android. ```APIDOC ## Model Management Methods ### NativeCutout.isModelAvailable() Checks if the ML model is downloaded and ready for use. ### NativeCutout.downloadModel() Downloads the required ML model. Returns `true` if successful. ### NativeCutout.downloadProgress A stream providing updates on the model download state and progress fraction. ### NativeCutout.clearModel() Removes the downloaded ML model from the device. ``` -------------------------------- ### NativeCutout.downloadProgress Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Broadcast stream of Android model download progress events. ```APIDOC ## NativeCutout.downloadProgress ### Description Broadcast stream of Android model download progress events. Only emits on Android while `downloadModel()` is running; returns an empty stream on iOS. ### Signature `Stream get NativeCutout.downloadProgress` ``` -------------------------------- ### NativeCutout.downloadModel method Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Triggers the download of the Android ML Kit segmentation module when needed. ```dart Future NativeCutout.downloadModel() ``` -------------------------------- ### NativeCutout.downloadModel Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Triggers download of the Android ML Kit segmentation module when needed. ```APIDOC ## NativeCutout.downloadModel ### Description Triggers download of the Android ML Kit segmentation module when needed. ### Signature `Future NativeCutout.downloadModel()` ``` -------------------------------- ### NativeCutout.clearModel Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Requests release of the downloaded Android ML Kit module. ```APIDOC ## NativeCutout.clearModel ### Description Requests release of the downloaded Android ML Kit module. Note: On Android, this is a best-effort request via Google Play services. ### Signature `Future NativeCutout.clearModel()` ``` -------------------------------- ### Default background removal flow Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Uses the default behavior to write the result to the app cache directory and return a file path. ```dart import 'dart:io'; import 'package:flutter/material.dart'; import 'package:native_cutout/native_cutout.dart'; final result = await NativeCutout.removeBackground( imagePath, options: const CutoutOptions( cropToSubject: true, writeToCache: true, ), ); late final Widget preview; switch (result) { case CutoutFileSuccess(:final path): preview = Image.file(File(path)); break; case CutoutBytesSuccess(:final pngBytes): preview = Image.memory(pngBytes); break; case CutoutFailure(:final code, :final message): debugPrint('Cutout failed: ${code.name} - $message'); return; } ``` -------------------------------- ### NativeCutout.isModelAvailable Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Checks whether the native model/runtime is ready to use. ```APIDOC ## NativeCutout.isModelAvailable ### Description Checks whether the native model/runtime is ready to use. ### Signature `Future NativeCutout.isModelAvailable()` ``` -------------------------------- ### Android model availability check Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Ensures the ML Kit model is available on Android before processing, downloading it if necessary. ```dart final isReady = await NativeCutout.isModelAvailable(); if (!isReady) { final downloaded = await NativeCutout.downloadModel(); if (!downloaded) { debugPrint('ML Kit model download failed'); return; } } final result = await NativeCutout.removeBackground(imagePath); ``` -------------------------------- ### Monitor model download progress Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Listens to the downloadProgress stream to track the state and fraction of the model download. ```dart final sub = NativeCutout.downloadProgress.listen((progress) { debugPrint('state=${progress.state} fraction=${progress.fraction}'); }); final ok = await NativeCutout.downloadModel(); await sub.cancel(); ``` -------------------------------- ### CutoutOptions configuration Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Configuration object for background removal. cropToSubject controls canvas size, and writeToCache determines if the result is cached or returned as bytes. ```dart const CutoutOptions( cropToSubject: false, writeToCache: true, ) ``` -------------------------------- ### NativeCutout.clearModel method Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Requests release of the downloaded Android ML Kit module. This is a best-effort request on Android. ```dart Future NativeCutout.clearModel() ``` -------------------------------- ### CutoutFileSuccess class definition Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Represents a successful cutout operation that returns a cached PNG file path. ```dart class CutoutFileSuccess extends CutoutSuccess { final String path; } ``` -------------------------------- ### NativeCutout.isModelAvailable method Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Checks whether the native model or runtime is ready to use. ```dart Future NativeCutout.isModelAvailable() ``` -------------------------------- ### Add dependency to pubspec.yaml Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Add the native_cutout package to your project dependencies. ```yaml dependencies: native_cutout: ^0.1.0 ``` -------------------------------- ### NativeCutout.clearCache Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Deletes PNG files previously written by the plugin into the app cache directory. ```APIDOC ## NativeCutout.clearCache ### Description Deletes PNG files previously written by the plugin into the app cache directory. ### Signature `Future NativeCutout.clearCache()` ``` -------------------------------- ### NativeCutout.clearCache method Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Deletes PNG files previously written by the plugin into the app cache directory. ```dart Future NativeCutout.clearCache() ``` -------------------------------- ### Cache Management Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Utility methods for managing cached files generated by the plugin. ```APIDOC ## NativeCutout.clearCache() ### Description Clears all previously generated PNG files stored in the app cache directory. ``` -------------------------------- ### In-memory background removal flow Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Returns raw PNG bytes directly by setting writeToCache to false. ```dart final result = await NativeCutout.removeBackground( imagePath, options: const CutoutOptions(writeToCache: false), ); ``` -------------------------------- ### CutoutBytesSuccess class definition Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Represents a successful cutout operation that returns the PNG data as bytes in memory. ```dart class CutoutBytesSuccess extends CutoutSuccess { final Uint8List pngBytes; } ``` -------------------------------- ### NativeCutout.clearCache() Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Clears all cached PNG files generated by the plugin. ```APIDOC ## NativeCutout.clearCache() ### Description Removes all cached PNG files from the application cache directory. ### Method Static Method ### Usage ```dart NativeCutout.clearCache(); ``` ``` -------------------------------- ### NativeCutout.removeBackground Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Performs background removal on an image at the specified path. Returns a result object containing either a file path, raw PNG bytes, or error details. ```APIDOC ## NativeCutout.removeBackground(String imagePath, {CutoutOptions options}) ### Description Processes an image to remove its background. The output format depends on the provided `CutoutOptions`. ### Parameters - **imagePath** (String) - Required - The local file path to the source image. - **options** (CutoutOptions) - Optional - Configuration for the operation, including `cropToSubject` (bool) and `writeToCache` (bool). ### Returns - **CutoutFileSuccess** - Contains the `path` to the generated PNG file. - **CutoutBytesSuccess** - Contains the `pngBytes` directly. - **CutoutFailure** - Contains an error `code` and `message`. ``` -------------------------------- ### NativeCutout.removeBackground method Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Removes the background from a local image file. Returns a CutoutFileSuccess, CutoutBytesSuccess, or CutoutFailure. ```dart Future NativeCutout.removeBackground( String imagePath, { CutoutOptions? options, }) ``` -------------------------------- ### NativeCutout.removeBackground Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Removes the background from a local image file using the specified options. ```APIDOC ## NativeCutout.removeBackground ### Description Removes the background from a local image file on device storage. ### Signature `Future NativeCutout.removeBackground(String imagePath, {CutoutOptions? options})` ### Parameters - **imagePath** (String) - Required - Absolute path to a local image file on device storage. - **options** (CutoutOptions) - Optional - Configuration for the cutout process. ### Returns - **CutoutFileSuccess** - Contains cached PNG file path (default). - **CutoutBytesSuccess** - Contains PNG bytes when `writeToCache` is `false`. - **CutoutFailure** - Contains `code` and `message`. ``` -------------------------------- ### Clear Android model Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Removes the downloaded model to test the first-download flow again. ```dart await NativeCutout.clearModel(); final isStillAvailable = await NativeCutout.isModelAvailable(); debugPrint('available after clear: $isStillAvailable'); ``` -------------------------------- ### NativeCutout.downloadProgress stream Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Broadcast stream of Android model download progress events. Returns an empty stream on iOS. ```dart Stream get NativeCutout.downloadProgress ``` -------------------------------- ### Clear generated cache Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Clears old generated PNG files from the cache. ```dart await NativeCutout.clearCache(); ``` -------------------------------- ### CutoutFailure class definition Source: https://github.com/xcc3641/flutter_native_cutout/blob/main/README.md Represents a failed cutout operation, providing a specific error code and a descriptive message. ```dart class CutoutFailure extends CutoutResult { final CutoutErrorCode code; final String message; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.