handleVideoButtonTap method Null safety

Future<void> handleVideoButtonTap(
  1. BuildContext context,
  2. QuillController controller,
  3. ImageSource videoSource,
  4. OnVideoPickCallback onVideoPickCallback,
  5. {FilePickImpl? filePickImpl,
  6. WebVideoPickImpl? webVideoPickImpl}
)

For video picking logic

Implementation

static Future<void> handleVideoButtonTap(
    BuildContext context,
    QuillController controller,
    ImageSource videoSource,
    OnVideoPickCallback onVideoPickCallback,
    {FilePickImpl? filePickImpl,
    WebVideoPickImpl? webVideoPickImpl}) async {
  final index = controller.selection.baseOffset;
  final length = controller.selection.extentOffset - index;

  String? videoUrl;
  if (kIsWeb) {
    assert(
        webVideoPickImpl != null,
        'Please provide webVideoPickImpl for Web '
        '(check out example directory for how to do it)');
    videoUrl = await webVideoPickImpl!(onVideoPickCallback);
  } else if (isMobile()) {
    videoUrl = await _pickVideo(videoSource, onVideoPickCallback);
  } else {
    assert(filePickImpl != null, 'Desktop must provide filePickImpl');
    videoUrl =
        await _pickVideoDesktop(context, filePickImpl!, onVideoPickCallback);
  }

  if (videoUrl != null) {
    controller.replaceText(index, length, BlockEmbed.video(videoUrl), null);
  }
}