ocarina2/lib/widgets/image_cover.dart

79 lines
2.2 KiB
Dart
Raw Permalink Normal View History

2024-05-23 19:14:08 +02:00
import 'package:auto_size_text/auto_size_text.dart';
2024-05-27 21:46:18 +02:00
import 'package:cached_network_image/cached_network_image.dart';
2024-05-23 19:14:08 +02:00
import 'package:flutter/material.dart';
import 'package:shimmer/shimmer.dart';
import 'package:text_scroll/text_scroll.dart';
class ImageCover extends StatelessWidget {
const ImageCover({
required this.imageUrl,
required this.title,
this.heroTag = "VeryUnconspicous",
2024-05-28 18:54:05 +02:00
this.cacheKey,
2024-05-23 19:14:08 +02:00
super.key,
});
final String imageUrl;
final String title;
final double _width = 180;
final String heroTag;
2024-05-28 18:54:05 +02:00
final String? cacheKey;
2024-05-23 19:14:08 +02:00
@override
Widget build(BuildContext context) {
return Column(
children: [
SizedBox(
width: _width,
height: _width,
child: Hero(
tag: heroTag,
2024-05-23 20:36:42 +02:00
child: ClipRRect(
borderRadius: BorderRadius.circular(8),
2024-05-27 21:46:18 +02:00
child: CachedNetworkImage(
2024-05-28 18:54:05 +02:00
cacheKey: cacheKey,
2024-05-27 21:46:18 +02:00
imageUrl: imageUrl,
placeholder: (c, d) => Shimmer.fromColors(
2024-05-23 20:36:42 +02:00
baseColor: Colors.grey.shade300,
highlightColor: Colors.grey.shade100,
child: Container(
color: Colors.grey,
),
2024-05-23 19:14:08 +02:00
),
2024-05-27 21:46:18 +02:00
errorWidget: (c, _, __) {
2024-05-23 20:36:42 +02:00
return ColoredBox(
color: Theme.of(context).colorScheme.primaryContainer,
child: Center(
child: Icon(
Icons.music_note,
color: Theme.of(context).colorScheme.onPrimaryContainer,
),
2024-05-23 19:14:08 +02:00
),
2024-05-23 20:36:42 +02:00
);
},
),
2024-05-23 19:14:08 +02:00
),
),
),
const SizedBox(
height: 5,
),
SizedBox(
width: _width * 0.7,
child: AutoSizeText(
title,
textAlign: TextAlign.center,
style: const TextStyle(fontWeight: FontWeight.bold),
overflowReplacement: TextScroll(
title,
style: const TextStyle(fontWeight: FontWeight.bold),
),
),
),
const SizedBox(
height: 10,
),
],
);
}
}