use custom implementation for memories and remove use of infinite_carousel
This commit is contained in:
parent
463523e09e
commit
845e58d1ba
3 changed files with 41 additions and 44 deletions
|
@ -1,8 +1,8 @@
|
|||
import "dart:async";
|
||||
import "dart:math";
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import "package:flutter/rendering.dart";
|
||||
import "package:infinite_carousel/infinite_carousel.dart";
|
||||
import "package:photos/core/event_bus.dart";
|
||||
import "package:photos/events/memories_setting_changed.dart";
|
||||
import 'package:photos/models/memory.dart';
|
||||
|
@ -17,10 +17,15 @@ class MemoriesWidget extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _MemoriesWidgetState extends State<MemoriesWidget> {
|
||||
final double _itemExtent = 120;
|
||||
late InfiniteScrollController _controller;
|
||||
final double _widthOfItem = 85;
|
||||
late ScrollController _controller;
|
||||
late StreamSubscription<MemoriesSettingChanged> _subscription;
|
||||
|
||||
final _assetPaths = <String>[
|
||||
"assets/onboarding_safe.png",
|
||||
"assets/gallery_locked.png",
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
@ -29,7 +34,7 @@ class _MemoriesWidgetState extends State<MemoriesWidget> {
|
|||
setState(() {});
|
||||
}
|
||||
});
|
||||
_controller = InfiniteScrollController();
|
||||
_controller = ScrollController();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -63,6 +68,7 @@ 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) {
|
||||
|
@ -78,48 +84,47 @@ class _MemoriesWidgetState extends State<MemoriesWidget> {
|
|||
}
|
||||
return SizedBox(
|
||||
height: 150,
|
||||
child: InfiniteCarousel.builder(
|
||||
loop: false,
|
||||
child: ListView.builder(
|
||||
scrollDirection: Axis.horizontal,
|
||||
controller: _controller,
|
||||
itemCount: memoryWidgets.length,
|
||||
itemExtent: _itemExtent,
|
||||
itemBuilder: (context, itemIndex, realIndex) {
|
||||
final currentOffset = _itemExtent * realIndex;
|
||||
itemBuilder: (context, itemIndex) {
|
||||
final offsetOfItem = _widthOfItem * itemIndex;
|
||||
return AnimatedBuilder(
|
||||
animation: _controller,
|
||||
builder: (context, child) {
|
||||
final diff = (_controller.offset - currentOffset);
|
||||
const maxPadding = 10.0;
|
||||
final carouselRatio = _itemExtent / maxPadding;
|
||||
final diff =
|
||||
(_controller.offset - offsetOfItem) + widthOfScreen / 7;
|
||||
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: (diff / carouselRatio).abs(),
|
||||
bottom: (diff / carouselRatio).abs(),
|
||||
),
|
||||
return Transform.scale(
|
||||
scale: 1 - (diff / widthOfScreen).abs() / 3,
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(2.0),
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
alignment: Alignment.bottomCenter,
|
||||
children: [
|
||||
Image.asset(
|
||||
"assets/onboarding_safe.png",
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
Positioned(
|
||||
bottom: 8,
|
||||
child: SizedBox(
|
||||
width: _itemExtent - 16,
|
||||
child: const Text(
|
||||
"1 year ago",
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
child: SizedBox(
|
||||
width: 85,
|
||||
height: 125,
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
alignment: Alignment.bottomCenter,
|
||||
children: [
|
||||
Image.asset(
|
||||
_assetPaths[Random().nextInt(_assetPaths.length)],
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
Positioned(
|
||||
bottom: 8,
|
||||
child: SizedBox(
|
||||
width: _widthOfItem - 16,
|
||||
child: const Text(
|
||||
"1 year ago",
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -137,6 +142,7 @@ class _MemoriesWidgetState extends State<MemoriesWidget> {
|
|||
final List<Memory> collatedYearlyMemories = [];
|
||||
collatedYearlyMemories.addAll(yearlyMemories);
|
||||
collatedMemories.add(collatedYearlyMemories);
|
||||
|
||||
yearlyMemories.clear();
|
||||
}
|
||||
yearlyMemories.add(memories[index]);
|
||||
|
|
|
@ -1026,14 +1026,6 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.3.6+4"
|
||||
infinite_carousel:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: infinite_carousel
|
||||
sha256: fe04c3b08adad2ee00c9bf40b46e0ff7944d206081392c4ae0f6b82c89c6e70d
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.3"
|
||||
integration_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
|
|
|
@ -93,7 +93,6 @@ dependencies:
|
|||
image: ^4.0.17
|
||||
image_editor: ^1.3.0
|
||||
in_app_purchase: ^3.0.7
|
||||
infinite_carousel: ^1.0.3
|
||||
intl: ^0.18.0
|
||||
isar: ^3.1.0+1
|
||||
isar_flutter_libs: ^3.1.0+1
|
||||
|
|
Loading…
Add table
Reference in a new issue