ente/lib/ui/tabs/shared/quick_link_album_item.dart

133 lines
5.3 KiB
Dart
Raw Normal View History

2023-06-06 16:43:32 +00:00
import "package:flutter/material.dart";
2023-06-24 16:00:07 +00:00
import "package:photos/db/files_db.dart";
2023-06-06 16:43:32 +00:00
import "package:photos/generated/l10n.dart";
import "package:photos/models/collection.dart";
2023-06-06 16:43:32 +00:00
import "package:photos/models/collection_items.dart";
import "package:photos/models/file.dart";
2023-06-06 16:43:32 +00:00
import "package:photos/models/gallery_type.dart";
import "package:photos/services/collections_service.dart";
2023-06-24 16:00:07 +00:00
import "package:photos/theme/colors.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/common/loading_widget.dart";
import "package:photos/ui/viewer/file/no_thumbnail_widget.dart";
2023-06-06 16:43:32 +00:00
import "package:photos/ui/viewer/file/thumbnail_widget.dart";
import "package:photos/ui/viewer/gallery/collection_page.dart";
import "package:photos/utils/navigation_util.dart";
class QuickLinkAlbumItem extends StatelessWidget {
final Collection c;
2023-06-19 05:49:39 +00:00
static const heroTagPrefix = "outgoing_collection";
2023-06-06 16:43:32 +00:00
const QuickLinkAlbumItem({super.key, required this.c});
2023-06-06 16:43:32 +00:00
@override
Widget build(BuildContext context) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
child: Container(
margin: const EdgeInsets.fromLTRB(16, 12, 16, 12),
child: Row(
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.circular(1),
child: SizedBox(
height: 60,
width: 60,
child: FutureBuilder<File?>(
future: CollectionsService.instance.getCover(c),
builder: (context, snapshot) {
if (snapshot.hasData) {
2023-06-19 05:49:39 +00:00
final String heroTag = heroTagPrefix + snapshot.data!.tag;
return Hero(
tag: heroTag,
child: ThumbnailWidget(
snapshot.data!,
key: ValueKey(heroTag),
),
);
} else {
return const NoThumbnailWidget();
}
},
),
2023-06-06 16:43:32 +00:00
),
),
const Padding(padding: EdgeInsets.all(8)),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2023-06-24 16:00:07 +00:00
Text(
c.displayName,
style: getEnteTextTheme(context).body,
),
Padding(
padding: const EdgeInsets.fromLTRB(0, 4, 0, 0),
child: FutureBuilder<int>(
future: FilesDB.instance.collectionFileCount(c.id),
builder: (context, snapshot) {
if (!snapshot.hasError) {
// final String textCount = NumberFormat().format(snapshot.data);
return Row(
children: [
(!snapshot.hasData)
? const Padding(
padding: EdgeInsets.symmetric(
horizontal: 16.0,
),
child: EnteLoadingWidget(size: 10),
)
: Padding(
padding:
const EdgeInsets.only(right: 8.0),
child: Text(
S.of(context).itemCount(snapshot.data!),
style: getEnteTextTheme(context)
.smallMuted,
),
),
const SizedBox(width: 6),
c.hasLink
? (c.publicURLs!.first!.isExpired
? const Icon(
Icons.link_outlined,
color: warning500,
)
: Icon(
Icons.link_outlined,
color: getEnteColorScheme(context)
.strokeMuted,
))
: const SizedBox.shrink(),
],
);
} else if (snapshot.hasError) {
return Text(S.of(context).somethingWentWrong);
} else {
return const EnteLoadingWidget(size: 10);
}
},
),
2023-06-06 16:43:32 +00:00
),
],
),
),
],
),
),
onTap: () async {
final thumbnail = await CollectionsService.instance.getCover(c);
2023-06-06 16:43:32 +00:00
final page = CollectionPage(
CollectionWithThumbnail(
c,
thumbnail,
),
2023-06-06 16:43:32 +00:00
appBarType: GalleryType.ownedCollection,
2023-06-19 05:49:39 +00:00
tagPrefix: heroTagPrefix,
2023-06-06 16:43:32 +00:00
);
routeToPage(context, page);
},
);
}
}