image function

ToolbarItem image({
  1. Future<ImageProvider<Object>?> pickImage(
    1. BuildContext
    )?,
  2. Future<ImageProvider<Object>?> snapImage(
    1. BuildContext
    )?,
})

Create a toolbar item for inserting ImageEmbed.

At least one of pickImage and snapImage must not be null.

Use pickImage for the action that picks an image from the device gallery. Use snapImage to take a new photo using the device camera.

If both are specified a submenu will be added to select whether the camera or the gallery should be opened.

Implementation

ToolbarItem image({
  Future<ImageProvider<Object>?> Function(BuildContext)? pickImage,
  Future<ImageProvider<Object>?> Function(BuildContext)? snapImage,
}) {
  assert(pickImage != null || snapImage != null,
      'At least one of the callbacks should not be null.');
  final snapImageItem = _buildImageButton(
    icon: Icons.photo_camera,
    tooltip: 'Camera',
    getImage: snapImage,
  );
  final pickImageItem = _buildImageButton(
    icon: Icons.photo_library,
    tooltip: 'Gallery',
    getImage: pickImage,
  );

  if (snapImageItem == null) {
    return pickImageItem!;
  }

  if (pickImageItem == null) {
    return snapImageItem;
  }

  return ToolbarItem.sublist(
    title: const Icon(Icons.photo),
    items: [
      snapImageItem,
      pickImageItem,
    ],
    tooltip: 'Image',
  );
}