Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Refactor

ashilkn2fc550b5429a
diff --git a/lib/ui/home/memories/memories_widget.dart b/lib/ui/home/memories/memories_widget.dart
index 69be673524..93445772b4 100644
--- a/lib/ui/home/memories/memories_widget.dart
+++ b/lib/ui/home/memories/memories_widget.dart
@@ -7,7 +7,6 @@ import 'package:photos/models/memory.dart';
import 'package:photos/services/memories_service.dart';
import "package:photos/ui/home/memories/memory_cover_widget.dart";
import "package:photos/ui/home/memories/memory_cover_widget_new.dart";
-import "package:photos/ui/viewer/file/thumbnail_widget.dart";
class MemoriesWidget extends StatefulWidget {
const MemoriesWidget({Key? key}) : super(key: key);
@@ -63,7 +62,6 @@ class _MemoriesWidgetState extends State<MemoriesWidget> {
}
Widget _buildMemories(List<Memory> memories) {
- final widthOfScreen = MediaQuery.sizeOf(context).width;
final collatedMemories = _collateMemories(memories);
final List<Widget> memoryWidgets = [];
for (final memories in collatedMemories) {
@@ -82,32 +80,10 @@ class _MemoriesWidgetState extends State<MemoriesWidget> {
itemCount: memoryWidgets.length,
itemBuilder: (context, itemIndex) {
final offsetOfItem = _widthOfItem * itemIndex;
- return AnimatedBuilder(
- animation: _controller,
- builder: (context, child) {
- final diff =
- (_controller.offset - offsetOfItem) + widthOfScreen / 7;
- final scale = 1 - (diff / widthOfScreen).abs() / 3;
- //Adding this row is a workaround for making height of memory cover
- //render as 125 * scale. Without this, height of rendered memory
- //cover will be 125.
- return Padding(
- padding: const EdgeInsets.symmetric(horizontal: 2.5),
- child: Row(
- children: [
- MemoryCoverWidgetNew(
- memories: memories,
- thumbnailWidget: child!,
- scale: scale,
- ),
- ],
- ),
- );
- },
- child: ThumbnailWidget(
- memories[0].file,
- shouldShowArchiveStatus: false,
- ),
+ return MemoryCoverWidgetNew(
+ memories: memories,
+ controller: _controller,
+ offsetOfItem: offsetOfItem,
);
},
),
diff --git a/lib/ui/home/memories/memory_cover_widget_new.dart b/lib/ui/home/memories/memory_cover_widget_new.dart
index 768398af48..6cdd850287 100644
--- a/lib/ui/home/memories/memory_cover_widget_new.dart
+++ b/lib/ui/home/memories/memory_cover_widget_new.dart
@@ -1,51 +1,80 @@
import "package:flutter/material.dart";
import "package:photos/models/memory.dart";
import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/viewer/file/thumbnail_widget.dart";
class MemoryCoverWidgetNew extends StatelessWidget {
- final double scale;
- final Widget thumbnailWidget;
final List<Memory> memories;
+ final ScrollController controller;
+ final double offsetOfItem;
const MemoryCoverWidgetNew({
required this.memories,
- required this.thumbnailWidget,
- required this.scale,
+ required this.controller,
+ required this.offsetOfItem,
super.key,
});
@override
Widget build(BuildContext context) {
- return SizedBox(
- height: 125 * scale,
- width: 85 * scale,
- child: ClipRRect(
- borderRadius: BorderRadius.circular(5),
- child: Stack(
- fit: StackFit.expand,
- alignment: Alignment.bottomCenter,
- children: [
- thumbnailWidget,
- Positioned(
- bottom: 8 * scale,
- child: Transform.scale(
- scale: scale,
- child: SizedBox(
- width: 85,
- child: Padding(
- padding: const EdgeInsets.symmetric(
- horizontal: 8.0,
- ),
- child: Text(
- "1 year ago",
- style: getEnteTextTheme(context).miniBold,
- ),
+ //memories will be empty if all memories are deleted and setState is called
+ //after FullScreenMemory screen is popped
+ if (memories.isEmpty) {
+ return const SizedBox.shrink();
+ }
+
+ final widthOfScreen = MediaQuery.sizeOf(context).width;
+ return AnimatedBuilder(
+ animation: controller,
+ builder: (context, child) {
+ final diff = (controller.offset - offsetOfItem) + widthOfScreen / 7;
+ final scale = 1 - (diff / widthOfScreen).abs() / 3;
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 2.5),
+ //Adding this row is a workaround for making height of memory cover
+ //render as 125 * scale. Without this, height of rendered memory
+ //cover will be 125.
+ child: Row(
+ children: [
+ SizedBox(
+ height: 125 * scale,
+ width: 85 * scale,
+ child: ClipRRect(
+ borderRadius: BorderRadius.circular(5),
+ child: Stack(
+ fit: StackFit.expand,
+ alignment: Alignment.bottomCenter,
+ children: [
+ child!,
+ Positioned(
+ bottom: 8 * scale,
+ child: Transform.scale(
+ scale: scale,
+ child: SizedBox(
+ width: 85,
+ child: Padding(
+ padding: const EdgeInsets.symmetric(
+ horizontal: 8.0,
+ ),
+ child: Text(
+ "1 year ago",
+ style: getEnteTextTheme(context).miniBold,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ],
),
),
),
- ),
- ],
- ),
+ ],
+ ),
+ );
+ },
+ child: ThumbnailWidget(
+ memories[0].file,
+ shouldShowArchiveStatus: false,
),
);
}