mirror of
https://github.com/Myzel394/quid_faciam_hodie.git
synced 2025-06-19 15:45: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 atIndex(final int index) => _timeline.values.elementAt(index);
|
||||||
|
|
||||||
MemoryPack get currentMemoryPack => atIndex(currentIndex);
|
MemoryPack get _currentMemoryPack => atIndex(currentIndex);
|
||||||
bool get isAtLastMemory =>
|
bool get _isAtLastMemory =>
|
||||||
_memoryIndex == currentMemoryPack.memories.length - 1;
|
_memoryIndex == _currentMemoryPack.memories.length - 1;
|
||||||
|
|
||||||
Memory get currentMemory =>
|
Memory get currentMemory =>
|
||||||
currentMemoryPack.memories.elementAt(_memoryIndex);
|
_currentMemoryPack.memories.elementAt(_memoryIndex);
|
||||||
|
|
||||||
void _removeEmptyDates() {
|
void _removeEmptyDates() {
|
||||||
_timeline.removeWhere((key, value) => value.memories.isEmpty);
|
_timeline.removeWhere((key, value) => value.memories.isEmpty);
|
||||||
@ -118,11 +117,11 @@ class TimelineModel extends PropertyChangeNotifier<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setCurrentIndex(currentIndex - 1);
|
setCurrentIndex(currentIndex - 1);
|
||||||
setMemoryIndex(currentMemoryPack.memories.length - 1);
|
setMemoryIndex(_currentMemoryPack.memories.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nextMemory() {
|
void nextMemory() {
|
||||||
if (isAtLastMemory) {
|
if (_isAtLastMemory) {
|
||||||
nextTimeline();
|
nextTimeline();
|
||||||
} else {
|
} else {
|
||||||
setMemoryIndex(memoryIndex + 1);
|
setMemoryIndex(memoryIndex + 1);
|
||||||
|
@ -7,7 +7,7 @@ enum TimelineState {
|
|||||||
completed,
|
completed,
|
||||||
}
|
}
|
||||||
|
|
||||||
class TimelineOverlay extends PropertyChangeNotifier<String> {
|
class TimelineOverlayModel extends PropertyChangeNotifier<String> {
|
||||||
bool _showOverlay = true;
|
bool _showOverlay = true;
|
||||||
TimelineState _state = TimelineState.loading;
|
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/controllers/status_controller.dart';
|
||||||
import 'package:share_location/enums.dart';
|
import 'package:share_location/enums.dart';
|
||||||
import 'package:share_location/foreign_types/memory.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.dart';
|
||||||
import 'package:share_location/models/timeline_overlay.dart';
|
import 'package:share_location/models/timeline_overlay.dart';
|
||||||
import 'package:share_location/widgets/status.dart';
|
import 'package:share_location/widgets/status.dart';
|
||||||
@ -31,13 +30,11 @@ class _MemorySlideState extends State<MemorySlide>
|
|||||||
|
|
||||||
Duration? duration;
|
Duration? duration;
|
||||||
|
|
||||||
MemoryPack getMemoryPack() => context.read<TimelineModel>().currentMemoryPack;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
final timelineOverlay = context.read<TimelineOverlay>();
|
final timelineOverlay = context.read<TimelineOverlayModel>();
|
||||||
|
|
||||||
timelineOverlay.addListener(() {
|
timelineOverlay.addListener(() {
|
||||||
if (!mounted) {
|
if (!mounted) {
|
||||||
@ -62,7 +59,7 @@ class _MemorySlideState extends State<MemorySlide>
|
|||||||
}
|
}
|
||||||
|
|
||||||
void initializeAnimation(final Duration newDuration) {
|
void initializeAnimation(final Duration newDuration) {
|
||||||
final timelineOverlay = context.read<TimelineOverlay>();
|
final timelineOverlay = context.read<TimelineOverlayModel>();
|
||||||
|
|
||||||
duration = newDuration;
|
duration = newDuration;
|
||||||
|
|
||||||
@ -88,7 +85,7 @@ class _MemorySlideState extends State<MemorySlide>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Consumer<TimelineOverlay>(
|
return Consumer<TimelineOverlayModel>(
|
||||||
builder: (_, timelineOverlay, __) => Consumer<TimelineModel>(
|
builder: (_, timelineOverlay, __) => Consumer<TimelineModel>(
|
||||||
builder: (___, timeline, ____) => Status(
|
builder: (___, timeline, ____) => Status(
|
||||||
controller: controller,
|
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 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
|
||||||
import 'package:provider/provider.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/memory_pack.dart';
|
||||||
import 'package:share_location/models/timeline.dart';
|
import 'package:share_location/models/timeline.dart';
|
||||||
import 'package:share_location/models/timeline_overlay.dart';
|
import 'package:share_location/models/timeline_overlay.dart';
|
||||||
import 'package:share_location/widgets/memory_sheet.dart';
|
import 'package:share_location/widgets/memory_sheet.dart';
|
||||||
import 'package:share_location/widgets/memory_slide.dart';
|
import 'package:share_location/widgets/memory_slide.dart';
|
||||||
|
import 'package:share_location/widgets/timeline_overlay.dart';
|
||||||
|
|
||||||
class TimelinePage extends StatefulWidget {
|
class TimelinePage extends StatefulWidget {
|
||||||
final DateTime date;
|
final DateTime date;
|
||||||
|
final MemoryPack memoryPack;
|
||||||
|
|
||||||
const TimelinePage({
|
const TimelinePage({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.date,
|
required this.date,
|
||||||
|
required this.memoryPack,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -23,13 +24,11 @@ class TimelinePage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _TimelinePageState extends State<TimelinePage> {
|
class _TimelinePageState extends State<TimelinePage> {
|
||||||
final timelineOverlayController = TimelineOverlay();
|
final timelineOverlayController = TimelineOverlayModel();
|
||||||
final pageController = PageController();
|
final pageController = PageController();
|
||||||
|
|
||||||
Timer? overlayRemover;
|
Timer? overlayRemover;
|
||||||
|
|
||||||
MemoryPack getMemoryPack() => context.read<TimelineModel>().currentMemoryPack;
|
|
||||||
|
|
||||||
void _handleOverlayChangeBasedOnMemoryPack() {
|
void _handleOverlayChangeBasedOnMemoryPack() {
|
||||||
if (!mounted) {
|
if (!mounted) {
|
||||||
return;
|
return;
|
||||||
@ -109,10 +108,10 @@ class _TimelinePageState extends State<TimelinePage> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return GestureDetector(
|
|
||||||
onDoubleTap: () async {
|
|
||||||
final timeline = context.read<TimelineModel>();
|
final timeline = context.read<TimelineModel>();
|
||||||
|
|
||||||
|
return GestureDetector(
|
||||||
|
onDoubleTap: () async {
|
||||||
timeline.pause();
|
timeline.pause();
|
||||||
|
|
||||||
await showModalBottomSheet(
|
await showModalBottomSheet(
|
||||||
@ -138,8 +137,6 @@ class _TimelinePageState extends State<TimelinePage> {
|
|||||||
timeline.resume();
|
timeline.resume();
|
||||||
},
|
},
|
||||||
onTapDown: (_) {
|
onTapDown: (_) {
|
||||||
final timeline = context.read<TimelineModel>();
|
|
||||||
|
|
||||||
timeline.pause();
|
timeline.pause();
|
||||||
|
|
||||||
overlayRemover = Timer(
|
overlayRemover = Timer(
|
||||||
@ -148,22 +145,16 @@ class _TimelinePageState extends State<TimelinePage> {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
onTapUp: (_) {
|
onTapUp: (_) {
|
||||||
final timeline = context.read<TimelineModel>();
|
|
||||||
|
|
||||||
overlayRemover?.cancel();
|
overlayRemover?.cancel();
|
||||||
timeline.resume();
|
timeline.resume();
|
||||||
timelineOverlayController.restoreOverlay();
|
timelineOverlayController.restoreOverlay();
|
||||||
},
|
},
|
||||||
onTapCancel: () {
|
onTapCancel: () {
|
||||||
final timeline = context.read<TimelineModel>();
|
|
||||||
|
|
||||||
overlayRemover?.cancel();
|
overlayRemover?.cancel();
|
||||||
timeline.resume();
|
timeline.resume();
|
||||||
timelineOverlayController.restoreOverlay();
|
timelineOverlayController.restoreOverlay();
|
||||||
},
|
},
|
||||||
onHorizontalDragEnd: (details) {
|
onHorizontalDragEnd: (details) {
|
||||||
final timeline = context.read<TimelineModel>();
|
|
||||||
|
|
||||||
if (details.primaryVelocity! < 0) {
|
if (details.primaryVelocity! < 0) {
|
||||||
timeline.nextMemory();
|
timeline.nextMemory();
|
||||||
} else if (details.primaryVelocity! > 0) {
|
} else if (details.primaryVelocity! > 0) {
|
||||||
@ -175,52 +166,20 @@ class _TimelinePageState extends State<TimelinePage> {
|
|||||||
child: Stack(
|
child: Stack(
|
||||||
fit: StackFit.expand,
|
fit: StackFit.expand,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Consumer<TimelineModel>(
|
PageView.builder(
|
||||||
builder: (_, timeline, __) => PageView.builder(
|
|
||||||
controller: pageController,
|
controller: pageController,
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
itemBuilder: (_, index) => MemorySlide(
|
itemBuilder: (_, index) => MemorySlide(
|
||||||
key: Key(timeline.currentMemoryPack.memories[index].filename),
|
key: Key(widget.memoryPack.memories[index].filename),
|
||||||
memory: timeline.currentMemoryPack.memories[index],
|
memory: widget.memoryPack.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,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
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(
|
itemBuilder: (_, index) => TimelinePage(
|
||||||
date: timeline.dateAtIndex(index),
|
date: timeline.dateAtIndex(index),
|
||||||
|
memoryPack: timeline.atIndex(index),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user