pick method

Future<List<MediaEntity>> pick(
  1. BuildContext context, {
  2. List<MediaEntity>? selectedEntities,
})

Implementation

Future<List<MediaEntity>> pick(
  BuildContext context, {
  List<MediaEntity>? selectedEntities,
}) async {
  final permission = await PhotoManager.requestPermissionExtend();
  if (permission != PermissionState.authorized &&
      permission != PermissionState.limited) {
    PhotoManager.openSetting();
    return [];
  }
  repository.fetchAlbums(setting.requestType, setting.filterOptionGroup);
  _completer = Completer<List<MediaEntity>>();
  galleryState.value = GalleryState.show;

  if (wrapperKey.currentState == null) {
    _fullScreenMode = true;
    final route = SlideTransitionPageRoute<List<MediaEntity>>(
      builder: GalleryView(controller: this),
    );
    await Navigator.of(context).push(route).then((result) {
      if (result == null && !_accessCamera) {
        _completer.complete(value.selectedEntities);
      }
    });
  } else {
    _fullScreenMode = false;
    panelController.openPanel();
    FocusManager.instance.primaryFocus?.unfocus();
  }
  if (!singleSelection && (selectedEntities?.isNotEmpty ?? false)) {
    internal = true;
    value = value.copyWith(
      selectedEntities: selectedEntities,
      previousSelection: true,
    );
  }
  return _completer.future;
}