pickMediaNative static method
Future<void>
pickMediaNative({
- AlbumPickerConfig? config,
- AlbumPickerTheme? theme,
- dynamic onPickConfirm(
- List<
AlbumMedia> pickedAlbumMedias, - String? textMessage
- List<
- dynamic onMediaProcessing(
- AlbumMedia albumMedia,
- double progress,
- bool error
- dynamic onMediaProcessed()?,
- dynamic onCancel()?,
Implementation
static Future<void> pickMediaNative({
AlbumPickerConfig? config,
AlbumPickerTheme? theme,
Function(List<AlbumMedia> pickedAlbumMedias, String? textMessage)?
onPickConfirm,
Function(AlbumMedia albumMedia, double progress, bool error)?
onMediaProcessing,
Function()? onMediaProcessed,
Function()? onCancel,
}) async {
if (!Platform.isAndroid && !Platform.isIOS) {
throw UnsupportedError(
'Native AlbumPicker is only supported on Android and iOS');
}
// Set up the persistent event listener (no-op if already active).
_ensureEventListenerSetup();
// Generate unique sessionId and store callbacks.
final sessionId = 'ps_${++_sessionCounter}_${DateTime.now().millisecondsSinceEpoch}';
_callbacksBySession[sessionId] = _CallbackGroup(
onPickConfirm: onPickConfirm,
onMediaProcessing: onMediaProcessing,
onMediaProcessed: onMediaProcessed,
onCancel: onCancel,
);
try {
await _methodChannel.invokeMethod(
'pickMedia',
{
'sessionId': sessionId,
'pickMode': config?.mediaFilter != null
? _convertMediaFilter(config!.mediaFilter!)
: null,
'maxCount': config?.maxSelectionCount,
'gridCount': config?.itemsPerRow,
'showsCameraItem': config?.showsCameraItem,
'style': config?.style != null
? _convertStyle(config!.style!)
: null,
'language': config?.language != null
? _convertLanguage(config!.language!)
: null,
'compressQuality': config?.compressQuality?.index,
'maxVideoDurationInSeconds': config?.maxVideoDurationInSeconds,
'maxOutputFileSizeInMB': config?.maxOutputFileSizeInMB,
'primaryColor': _convertColor(theme?.primaryColor),
'backgroundColor': _convertColor(theme?.backgroundColor),
'backgroundColorSecondary':
_convertColor(theme?.backgroundColorSecondary),
'textColor': _convertColor(theme?.textColor),
'textColorSecondary': _convertColor(theme?.textColorSecondary),
'confirmButtonIconAsset': theme?.confirmButtonIconAsset,
'bigFontSize': theme?.bigFontSize,
'normalFontSize': theme?.normalFontSize,
'smallFontSize': theme?.smallFontSize,
'bigRadius': theme?.bigRadius,
'normalRadius': theme?.normalRadius,
'smallRadius': theme?.smallRadius,
},
);
} catch (e) {
debugPrint('AlbumPickerPlatform.pickMediaNative error: $e');
_callbacksBySession.remove(sessionId);
rethrow;
}
}