nc-photos/app/lib/widget/collection_list_item.dart

109 lines
2.9 KiB
Dart
Raw Normal View History

2022-08-28 16:10:28 +02:00
import 'package:flutter/material.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/theme.dart';
2022-12-18 07:20:51 +01:00
import 'package:nc_photos/widget/network_thumbnail.dart';
2022-08-28 16:10:28 +02:00
class CollectionListSmall extends StatelessWidget {
const CollectionListSmall({
Key? key,
required this.account,
required this.label,
required this.coverUrl,
required this.fallbackBuilder,
this.onTap,
}) : super(key: key);
@override
build(BuildContext context) {
Widget content = Stack(
children: [
SizedBox.expand(
child: _buildCoverImage(context),
),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: 24,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.black.withOpacity(0),
2022-11-12 10:55:33 +01:00
Colors.black.withOpacity(.5),
2022-08-28 16:10:28 +02:00
],
),
),
),
Container(
2022-11-12 10:55:33 +01:00
color: Colors.black.withOpacity(.5),
2022-08-28 16:10:28 +02:00
constraints: const BoxConstraints(minWidth: double.infinity),
padding: const EdgeInsets.fromLTRB(8, 0, 8, 4),
child: Text(
label,
2022-11-12 10:55:33 +01:00
style: Theme.of(context).textTheme.labelLarge!.copyWith(
color: Theme.of(context).onDarkSurface,
),
2022-08-28 16:10:28 +02:00
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
],
),
),
],
);
if (onTap != null) {
content = Stack(
fit: StackFit.expand,
children: [
content,
Positioned.fill(
child: Material(
type: MaterialType.transparency,
child: InkWell(
onTap: onTap,
),
),
),
],
);
}
return Container(
2022-11-12 10:55:33 +01:00
color: Theme.of(context).listPlaceholderBackgroundColor,
2022-08-28 16:10:28 +02:00
constraints: const BoxConstraints.expand(),
child: content,
);
}
Widget _buildCoverImage(BuildContext context) {
Widget buildPlaceholder() => Padding(
2022-12-18 07:20:51 +01:00
padding: const EdgeInsets.all(8),
2022-08-28 16:10:28 +02:00
child: fallbackBuilder(context),
);
try {
2022-12-18 07:20:51 +01:00
return NetworkRectThumbnail(
account: account,
imageUrl: coverUrl,
errorBuilder: (_) => buildPlaceholder(),
2022-08-28 16:10:28 +02:00
);
} catch (_) {
return FittedBox(
child: buildPlaceholder(),
);
}
}
final Account account;
final String label;
final String coverUrl;
final Widget Function(BuildContext context) fallbackBuilder;
final VoidCallback? onTap;
}