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. List<int>? previewThumbSize,
  7. List<AssetEntity>? selectedAssets,
  8. SpecialPickerType? specialPickerType,
  9. int? maxAssets,
})

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,
  List<int>? previewThumbSize,
  List<AssetEntity>? selectedAssets,
  SpecialPickerType? specialPickerType,
  int? maxAssets,
}) async {
  try {
    final Widget viewer = AssetPickerViewer<AssetEntity, AssetPathEntity>(
      builder: DefaultAssetPickerViewerBuilderDelegate(
        currentIndex: currentIndex,
        previewAssets: previewAssets,
        provider: selectedAssets != null
            ? AssetPickerViewerProvider<AssetEntity>(selectedAssets)
            : null,
        themeData: themeData,
        previewThumbSize: previewThumbSize,
        specialPickerType: specialPickerType,
        selectedAssets: selectedAssets,
        selectorProvider: selectorProvider,
        maxAssets: maxAssets,
      ),
    );
    final PageRouteBuilder<List<AssetEntity>> pageRoute =
        PageRouteBuilder<List<AssetEntity>>(
      pageBuilder: (
        BuildContext context,
        Animation<double> animation,
        Animation<double> secondaryAnimation,
      ) {
        return viewer;
      },
      transitionsBuilder: (
        BuildContext context,
        Animation<double> animation,
        Animation<double> secondaryAnimation,
        Widget child,
      ) {
        return FadeTransition(opacity: animation, child: child);
      },
    );
    final List<AssetEntity>? result =
        await Navigator.of(context).push<List<AssetEntity>>(pageRoute);
    return result;
  } catch (e) {
    realDebugPrint('Error when calling assets picker viewer: $e');
    return null;
  }
}