pushToViewer static method

Future<List<AssetEntity>?> pushToViewer(
  1. BuildContext context, {
  2. int currentIndex = 0,
  3. required List<AssetEntity> previewAssets,
  4. required ThemeData themeData,
  5. DefaultAssetPickerProvider? selectorProvider,
  6. ThumbnailSize? previewThumbnailSize,
  7. List<AssetEntity>? selectedAssets,
  8. SpecialPickerType? specialPickerType,
  9. int? maxAssets,
  10. bool shouldReversePreview = false,
  11. AssetSelectPredicate<AssetEntity>? selectPredicate,
  12. PermissionRequestOption permissionRequestOption = const PermissionRequestOption(),
  13. bool shouldAutoplayPreview = false,
})

Static method to push with the navigator. 跳转至选择预览的静态方法

Implementation

static Future<List<AssetEntity>?> pushToViewer(
  BuildContext context, {
  int currentIndex = 0,
  required List<AssetEntity> previewAssets,
  required ThemeData themeData,
  DefaultAssetPickerProvider? selectorProvider,
  ThumbnailSize? previewThumbnailSize,
  List<AssetEntity>? selectedAssets,
  SpecialPickerType? specialPickerType,
  int? maxAssets,
  bool shouldReversePreview = false,
  AssetSelectPredicate<AssetEntity>? selectPredicate,
  PermissionRequestOption permissionRequestOption =
      const PermissionRequestOption(),
  bool shouldAutoplayPreview = false,
}) async {
  if (previewAssets.isEmpty) {
    throw StateError('Previewing empty assets is not allowed.');
  }
  await AssetPicker.permissionCheck(requestOption: permissionRequestOption);
  final Widget viewer = AssetPickerViewer<AssetEntity, AssetPathEntity>(
    builder: DefaultAssetPickerViewerBuilderDelegate(
      currentIndex: currentIndex,
      previewAssets: previewAssets,
      provider: selectedAssets != null
          ? AssetPickerViewerProvider<AssetEntity>(
              selectedAssets,
              maxAssets: maxAssets ??
                  selectorProvider?.maxAssets ??
                  defaultMaxAssetsCount,
            )
          : null,
      themeData: themeData,
      previewThumbnailSize: previewThumbnailSize,
      specialPickerType: specialPickerType,
      selectedAssets: selectedAssets,
      selectorProvider: selectorProvider,
      maxAssets: maxAssets,
      shouldReversePreview: shouldReversePreview,
      selectPredicate: selectPredicate,
      shouldAutoplayPreview: shouldAutoplayPreview,
    ),
  );
  final PageRouteBuilder<List<AssetEntity>> pageRoute =
      PageRouteBuilder<List<AssetEntity>>(
    pageBuilder: (_, __, ___) => viewer,
    transitionsBuilder: (_, Animation<double> animation, __, Widget child) {
      return FadeTransition(opacity: animation, child: child);
    },
  );
  final List<AssetEntity>? result =
      await Navigator.maybeOf(context)?.push<List<AssetEntity>>(pageRoute);
  return result;
}