pickAssets method

Future<List<AssetEntity>?> pickAssets(
  1. BuildContext context, {
  2. Key? key,
  3. AssetPickerConfig pickerConfig = const AssetPickerConfig(),
  4. bool useRootNavigator = true,
  5. AssetPickerPageRouteBuilder<List<AssetEntity>>? pageRouteBuilder,
})

Pick assets with the given pickerConfig. 根据给定的 pickerConfig 选择资源。

Set useRootNavigator to determine whether the picker route should use the root Navigator. 使用 useRootNavigator 来控制选择器的路由是否使用最顶层的 Navigator

By extending the AssetPickerPageRoute, users can customize the route and use it with the pageRouteBuilder. 继承 AssetPickerPageRoute 可以自定义路由, 并且通过 pageRouteBuilder 进行使用。

See also:

Implementation

Future<List<AssetEntity>?> pickAssets(
  BuildContext context, {
  Key? key,
  AssetPickerConfig pickerConfig = const AssetPickerConfig(),
  bool useRootNavigator = true,
  AssetPickerPageRouteBuilder<List<AssetEntity>>? pageRouteBuilder,
}) async {
  final PermissionState ps = await permissionCheck();
  final AssetPickerPageRoute<List<AssetEntity>> route =
      pageRouteBuilder?.call(const SizedBox.shrink()) ??
          AssetPickerPageRoute<List<AssetEntity>>(
            builder: (_) => const SizedBox.shrink(),
          );
  final DefaultAssetPickerProvider provider = DefaultAssetPickerProvider(
    maxAssets: pickerConfig.maxAssets,
    pageSize: pickerConfig.pageSize,
    pathThumbnailSize: pickerConfig.pathThumbnailSize,
    selectedAssets: pickerConfig.selectedAssets,
    requestType: pickerConfig.requestType,
    sortPathDelegate: pickerConfig.sortPathDelegate,
    filterOptions: pickerConfig.filterOptions,
    initializeDelayDuration: route.transitionDuration,
  );
  final Widget picker = AssetPicker<AssetEntity, AssetPathEntity>(
    key: key,
    builder: DefaultAssetPickerBuilderDelegate(
      provider: provider,
      initialPermission: ps,
      gridCount: pickerConfig.gridCount,
      pickerTheme: pickerConfig.pickerTheme,
      gridThumbnailSize: pickerConfig.gridThumbnailSize,
      previewThumbnailSize: pickerConfig.previewThumbnailSize,
      specialPickerType: pickerConfig.specialPickerType,
      specialItemPosition: pickerConfig.specialItemPosition,
      specialItemBuilder: pickerConfig.specialItemBuilder,
      loadingIndicatorBuilder: pickerConfig.loadingIndicatorBuilder,
      selectPredicate: pickerConfig.selectPredicate,
      shouldRevertGrid: pickerConfig.shouldRevertGrid,
      limitedPermissionOverlayPredicate:
          pickerConfig.limitedPermissionOverlayPredicate,
      pathNameBuilder: pickerConfig.pathNameBuilder,
      textDelegate: pickerConfig.textDelegate,
      themeColor: pickerConfig.themeColor,
      locale: Localizations.maybeLocaleOf(context),
    ),
  );
  final List<AssetEntity>? result = await Navigator.of(
    context,
    rootNavigator: useRootNavigator,
  ).push<List<AssetEntity>>(
    pageRouteBuilder?.call(picker) ??
        AssetPickerPageRoute<List<AssetEntity>>(builder: (_) => picker),
  );
  return result;
}