You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.2 KiB
75 lines
2.2 KiB
2 years ago
|
part of '../neon_files.dart';
|
||
2 years ago
|
|
||
|
class FilePreview extends StatelessWidget {
|
||
|
const FilePreview({
|
||
|
required this.bloc,
|
||
|
required this.details,
|
||
|
this.width = 40,
|
||
|
this.height = 40,
|
||
|
this.color,
|
||
2 years ago
|
this.borderRadius,
|
||
2 years ago
|
this.withBackground = false,
|
||
2 years ago
|
super.key,
|
||
2 years ago
|
}) : assert(
|
||
|
(borderRadius != null && withBackground) || borderRadius == null,
|
||
|
'withBackground needs to be true when borderRadius is set',
|
||
|
);
|
||
2 years ago
|
|
||
|
final FilesBloc bloc;
|
||
|
final FileDetails details;
|
||
|
final int width;
|
||
|
final int height;
|
||
|
final Color? color;
|
||
2 years ago
|
final BorderRadius? borderRadius;
|
||
2 years ago
|
final bool withBackground;
|
||
2 years ago
|
|
||
|
@override
|
||
2 years ago
|
Widget build(final BuildContext context) {
|
||
2 years ago
|
final color = this.color ?? Theme.of(context).colorScheme.primary;
|
||
|
return SizedBox(
|
||
|
width: width.toDouble(),
|
||
|
height: height.toDouble(),
|
||
|
child: StreamBuilder<bool?>(
|
||
|
stream: bloc.options.showPreviewsOption.stream,
|
||
|
builder: (final context, final showPreviewsSnapshot) {
|
||
2 years ago
|
if ((showPreviewsSnapshot.data ?? false) && (details.hasPreview ?? false)) {
|
||
2 years ago
|
final account = Provider.of<AccountsBloc>(context, listen: false).activeAccount.value!;
|
||
2 years ago
|
final child = CachedAPIImage(
|
||
|
account: account,
|
||
|
cacheKey: 'preview-${details.path.join('/')}-$width-$height',
|
||
|
etag: details.etag,
|
||
|
download: () async => account.client.core.getPreview(
|
||
|
file: details.path.join('/'),
|
||
|
x: width,
|
||
|
y: height,
|
||
|
),
|
||
2 years ago
|
);
|
||
2 years ago
|
if (withBackground) {
|
||
|
return ImageWrapper(
|
||
|
color: Colors.white,
|
||
|
borderRadius: borderRadius,
|
||
|
child: child,
|
||
|
);
|
||
|
}
|
||
|
return child;
|
||
2 years ago
|
}
|
||
|
|
||
|
if (details.isDirectory) {
|
||
|
return Icon(
|
||
|
MdiIcons.folder,
|
||
|
color: color,
|
||
|
size: min(width.toDouble(), height.toDouble()),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
return FileIcon(
|
||
|
details.name,
|
||
|
color: color,
|
||
|
size: min(width.toDouble(), height.toDouble()),
|
||
|
);
|
||
|
},
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|