handleImageButtonTap method Null safety
- BuildContext context,
- QuillController controller,
- ImageSource imageSource,
- OnImagePickCallback onImagePickCallback,
- {FilePickImpl? filePickImpl,
- WebImagePickImpl? webImagePickImpl}
For image picking logic
Implementation
static Future<void> handleImageButtonTap(
BuildContext context,
QuillController controller,
ImageSource imageSource,
OnImagePickCallback onImagePickCallback,
{FilePickImpl? filePickImpl,
WebImagePickImpl? webImagePickImpl}) async {
final index = controller.selection.baseOffset;
final length = controller.selection.extentOffset - index;
String? imageUrl;
if (kIsWeb) {
assert(
webImagePickImpl != null,
'Please provide webImagePickImpl for Web '
'(check out example directory for how to do it)');
imageUrl = await webImagePickImpl!(onImagePickCallback);
} else if (isMobile()) {
imageUrl = await _pickImage(imageSource, onImagePickCallback);
} else {
assert(filePickImpl != null, 'Desktop must provide filePickImpl');
imageUrl =
await _pickImageDesktop(context, filePickImpl!, onImagePickCallback);
}
if (imageUrl != null) {
controller.replaceText(index, length, BlockEmbed.image(imageUrl), null);
}
}