initialize method
Initialize the segmenter with optional configuration.
This may download models, allocate GPU resources, etc. Returns a Future that completes when ready.
Implementation
@override
Future<void> initialize([
SegmenterConfig config = const SegmenterConfig(),
]) async {
_config = config;
// On iOS, macOS, and Windows, initialize native segmentation for preview
if (_supportsNativeSegmentation) {
try {
final result = await _channel.invokeMethod<Map>('initialize', {
'useGpu': true,
});
_nativeInitialized = result?['success'] as bool? ?? false;
// Log initialization result with model status
final modelLoaded = result?['modelLoaded'] as bool? ?? false;
final engine = result?['engine'] as String? ?? 'unknown';
final message = result?['message'] as String? ?? '';
debugPrint(
'MobileSegmenter: Native init result - success=$_nativeInitialized, modelLoaded=$modelLoaded, engine=$engine, message=$message');
} catch (e) {
debugPrint('MobileSegmenter: Native init failed - $e');
_nativeInitialized = false;
}
}
_isReady = true;
}