mirror of
https://github.com/Myzel394/quid_faciam_hodie.git
synced 2025-06-19 07:35:26 +02:00
improved code
This commit is contained in:
parent
ffcaec244a
commit
b146957c69
@ -56,12 +56,11 @@ class TimelineModel extends PropertyChangeNotifier<String> {
|
||||
|
||||
MemoryPack atIndex(final int index) => _timeline.values.elementAt(index);
|
||||
|
||||
MemoryPack get currentMemoryPack => atIndex(currentIndex);
|
||||
bool get isAtLastMemory =>
|
||||
_memoryIndex == currentMemoryPack.memories.length - 1;
|
||||
|
||||
MemoryPack get _currentMemoryPack => atIndex(currentIndex);
|
||||
bool get _isAtLastMemory =>
|
||||
_memoryIndex == _currentMemoryPack.memories.length - 1;
|
||||
Memory get currentMemory =>
|
||||
currentMemoryPack.memories.elementAt(_memoryIndex);
|
||||
_currentMemoryPack.memories.elementAt(_memoryIndex);
|
||||
|
||||
void _removeEmptyDates() {
|
||||
_timeline.removeWhere((key, value) => value.memories.isEmpty);
|
||||
@ -118,11 +117,11 @@ class TimelineModel extends PropertyChangeNotifier<String> {
|
||||
}
|
||||
|
||||
setCurrentIndex(currentIndex - 1);
|
||||
setMemoryIndex(currentMemoryPack.memories.length - 1);
|
||||
setMemoryIndex(_currentMemoryPack.memories.length - 1);
|
||||
}
|
||||
|
||||
void nextMemory() {
|
||||
if (isAtLastMemory) {
|
||||
if (_isAtLastMemory) {
|
||||
nextTimeline();
|
||||
} else {
|
||||
setMemoryIndex(memoryIndex + 1);
|
||||
|
@ -7,7 +7,7 @@ enum TimelineState {
|
||||
completed,
|
||||
}
|
||||
|
||||
class TimelineOverlay extends PropertyChangeNotifier<String> {
|
||||
class TimelineOverlayModel extends PropertyChangeNotifier<String> {
|
||||
bool _showOverlay = true;
|
||||
TimelineState _state = TimelineState.loading;
|
||||
|
||||
|
@ -3,7 +3,6 @@ import 'package:provider/provider.dart';
|
||||
import 'package:share_location/controllers/status_controller.dart';
|
||||
import 'package:share_location/enums.dart';
|
||||
import 'package:share_location/foreign_types/memory.dart';
|
||||
import 'package:share_location/models/memory_pack.dart';
|
||||
import 'package:share_location/models/timeline.dart';
|
||||
import 'package:share_location/models/timeline_overlay.dart';
|
||||
import 'package:share_location/widgets/status.dart';
|
||||
@ -31,13 +30,11 @@ class _MemorySlideState extends State<MemorySlide>
|
||||
|
||||
Duration? duration;
|
||||
|
||||
MemoryPack getMemoryPack() => context.read<TimelineModel>().currentMemoryPack;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
final timelineOverlay = context.read<TimelineOverlay>();
|
||||
final timelineOverlay = context.read<TimelineOverlayModel>();
|
||||
|
||||
timelineOverlay.addListener(() {
|
||||
if (!mounted) {
|
||||
@ -62,7 +59,7 @@ class _MemorySlideState extends State<MemorySlide>
|
||||
}
|
||||
|
||||
void initializeAnimation(final Duration newDuration) {
|
||||
final timelineOverlay = context.read<TimelineOverlay>();
|
||||
final timelineOverlay = context.read<TimelineOverlayModel>();
|
||||
|
||||
duration = newDuration;
|
||||
|
||||
@ -88,7 +85,7 @@ class _MemorySlideState extends State<MemorySlide>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<TimelineOverlay>(
|
||||
return Consumer<TimelineOverlayModel>(
|
||||
builder: (_, timelineOverlay, __) => Consumer<TimelineModel>(
|
||||
builder: (___, timeline, ____) => Status(
|
||||
controller: controller,
|
||||
|
78
lib/widgets/timeline_overlay.dart
Normal file
78
lib/widgets/timeline_overlay.dart
Normal file
@ -0,0 +1,78 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:share_location/constants/spacing.dart';
|
||||
import 'package:share_location/models/timeline.dart';
|
||||
import 'package:share_location/models/timeline_overlay.dart';
|
||||
|
||||
class TimelineOverlay extends StatelessWidget {
|
||||
final DateTime date;
|
||||
final int memoryIndex;
|
||||
final int memoriesAmount;
|
||||
|
||||
const TimelineOverlay({
|
||||
Key? key,
|
||||
required this.date,
|
||||
required this.memoryIndex,
|
||||
required this.memoriesAmount,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final timeline = context.watch<TimelineModel>();
|
||||
final overlayController = context.watch<TimelineOverlayModel>();
|
||||
|
||||
return Stack(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: LARGE_SPACE,
|
||||
left: MEDIUM_SPACE,
|
||||
right: MEDIUM_SPACE,
|
||||
),
|
||||
child: AnimatedOpacity(
|
||||
duration: const Duration(milliseconds: 500),
|
||||
curve: Curves.linearToEaseOut,
|
||||
opacity: overlayController.showOverlay ? 1.0 : 0.0,
|
||||
child: Text(
|
||||
DateFormat('dd. MMMM yyyy').format(date),
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.headline1,
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
right: SMALL_SPACE,
|
||||
bottom: SMALL_SPACE * 2,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: SMALL_SPACE),
|
||||
child: AnimatedOpacity(
|
||||
duration: const Duration(milliseconds: 500),
|
||||
curve: Curves.linearToEaseOut,
|
||||
opacity: overlayController.showOverlay ? 1.0 : 0.0,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
AnimatedOpacity(
|
||||
opacity: timeline.currentMemory.isPublic ? 1.0 : 0.0,
|
||||
duration: const Duration(milliseconds: 500),
|
||||
curve: Curves.linearToEaseOut,
|
||||
child: Icon(
|
||||
Icons.public,
|
||||
size: theme.textTheme.titleSmall!.fontSize,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: SMALL_SPACE),
|
||||
Text(
|
||||
'$memoryIndex/$memoriesAmount',
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -1,21 +1,22 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:share_location/constants/spacing.dart';
|
||||
import 'package:share_location/models/memory_pack.dart';
|
||||
import 'package:share_location/models/timeline.dart';
|
||||
import 'package:share_location/models/timeline_overlay.dart';
|
||||
import 'package:share_location/widgets/memory_sheet.dart';
|
||||
import 'package:share_location/widgets/memory_slide.dart';
|
||||
import 'package:share_location/widgets/timeline_overlay.dart';
|
||||
|
||||
class TimelinePage extends StatefulWidget {
|
||||
final DateTime date;
|
||||
final MemoryPack memoryPack;
|
||||
|
||||
const TimelinePage({
|
||||
Key? key,
|
||||
required this.date,
|
||||
required this.memoryPack,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@ -23,13 +24,11 @@ class TimelinePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _TimelinePageState extends State<TimelinePage> {
|
||||
final timelineOverlayController = TimelineOverlay();
|
||||
final timelineOverlayController = TimelineOverlayModel();
|
||||
final pageController = PageController();
|
||||
|
||||
Timer? overlayRemover;
|
||||
|
||||
MemoryPack getMemoryPack() => context.read<TimelineModel>().currentMemoryPack;
|
||||
|
||||
void _handleOverlayChangeBasedOnMemoryPack() {
|
||||
if (!mounted) {
|
||||
return;
|
||||
@ -109,10 +108,10 @@ class _TimelinePageState extends State<TimelinePage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onDoubleTap: () async {
|
||||
final timeline = context.read<TimelineModel>();
|
||||
|
||||
return GestureDetector(
|
||||
onDoubleTap: () async {
|
||||
timeline.pause();
|
||||
|
||||
await showModalBottomSheet(
|
||||
@ -138,8 +137,6 @@ class _TimelinePageState extends State<TimelinePage> {
|
||||
timeline.resume();
|
||||
},
|
||||
onTapDown: (_) {
|
||||
final timeline = context.read<TimelineModel>();
|
||||
|
||||
timeline.pause();
|
||||
|
||||
overlayRemover = Timer(
|
||||
@ -148,22 +145,16 @@ class _TimelinePageState extends State<TimelinePage> {
|
||||
);
|
||||
},
|
||||
onTapUp: (_) {
|
||||
final timeline = context.read<TimelineModel>();
|
||||
|
||||
overlayRemover?.cancel();
|
||||
timeline.resume();
|
||||
timelineOverlayController.restoreOverlay();
|
||||
},
|
||||
onTapCancel: () {
|
||||
final timeline = context.read<TimelineModel>();
|
||||
|
||||
overlayRemover?.cancel();
|
||||
timeline.resume();
|
||||
timelineOverlayController.restoreOverlay();
|
||||
},
|
||||
onHorizontalDragEnd: (details) {
|
||||
final timeline = context.read<TimelineModel>();
|
||||
|
||||
if (details.primaryVelocity! < 0) {
|
||||
timeline.nextMemory();
|
||||
} else if (details.primaryVelocity! > 0) {
|
||||
@ -175,52 +166,20 @@ class _TimelinePageState extends State<TimelinePage> {
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: <Widget>[
|
||||
Consumer<TimelineModel>(
|
||||
builder: (_, timeline, __) => PageView.builder(
|
||||
PageView.builder(
|
||||
controller: pageController,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemBuilder: (_, index) => MemorySlide(
|
||||
key: Key(timeline.currentMemoryPack.memories[index].filename),
|
||||
memory: timeline.currentMemoryPack.memories[index],
|
||||
),
|
||||
itemCount: timeline.currentMemoryPack.memories.length,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: LARGE_SPACE,
|
||||
left: MEDIUM_SPACE,
|
||||
right: MEDIUM_SPACE,
|
||||
),
|
||||
child: AnimatedOpacity(
|
||||
duration: const Duration(milliseconds: 500),
|
||||
curve: Curves.linearToEaseOut,
|
||||
opacity: timelineOverlayController.showOverlay ? 1.0 : 0.0,
|
||||
child: Text(
|
||||
DateFormat('dd. MMMM yyyy').format(widget.date),
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.headline1,
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
right: SMALL_SPACE,
|
||||
bottom: SMALL_SPACE * 2,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: SMALL_SPACE),
|
||||
child: AnimatedOpacity(
|
||||
duration: const Duration(milliseconds: 500),
|
||||
curve: Curves.linearToEaseOut,
|
||||
opacity: timelineOverlayController.showOverlay ? 1.0 : 0.0,
|
||||
child: Consumer<TimelineModel>(
|
||||
builder: (_, timeline, __) => Text(
|
||||
'${timeline.memoryIndex + 1}/${timeline.currentMemoryPack.memories.length}',
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
),
|
||||
),
|
||||
key: Key(widget.memoryPack.memories[index].filename),
|
||||
memory: widget.memoryPack.memories[index],
|
||||
),
|
||||
itemCount: widget.memoryPack.memories.length,
|
||||
),
|
||||
TimelineOverlay(
|
||||
date: widget.date,
|
||||
memoriesAmount: widget.memoryPack.memories.length,
|
||||
memoryIndex: timeline.memoryIndex,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@ -75,6 +75,7 @@ class _TimelineScrollState extends State<TimelineScroll> with Loadable {
|
||||
},
|
||||
itemBuilder: (_, index) => TimelinePage(
|
||||
date: timeline.dateAtIndex(index),
|
||||
memoryPack: timeline.atIndex(index),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user