pickImage method

  1. @action
Future<void> pickImage(
  1. BuildContext context
)

The action for the pick image.

Implementation

@action
Future<void> pickImage(BuildContext context) async {
  if (_isSending || _isPickingImage) {
    return;
  }
  _isPickingImage = true;
  final isAtBottom = chatScrollController.isAtBottom();
  final results = await showAssetPicker(
    context,
    config: AssetPickerConfig(
      maxSelection: config.imageMaxCount,
      selectIndicatorColor: context.coloredTheme.primary,
      loadingIndicatorColor: context.coloredTheme.primary,
      permissionDeniedText: config.photoPermissionDeniedText ??
          'Please grant permission to access your photo library',
      permissionDeniedButtonText:
          config.photoPermissionDeniedButtonText ?? 'Open Settings',
    ),
  );
  _imageFiles = ObservableList<AssetImageInfo>.of(results ?? []);
  if (isAtBottom) {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      chatScrollController.scrollToBottom();
    });
  }
  _isPickingImage = false;
}