handleImageButtonTap method Null safety

Future<void> handleImageButtonTap(
  1. BuildContext context,
  2. QuillController controller,
  3. ImageSource imageSource,
  4. OnImagePickCallback onImagePickCallback,
  5. {FilePickImpl? filePickImpl,
  6. 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);
  }
}