mirror of
https://github.com/Myzel394/quid_faciam_hodie.git
synced 2025-06-19 07:35:26 +02:00
fixed empty calendar dates could be selected
This commit is contained in:
parent
c817452d06
commit
4a1d1c9026
@ -2,4 +2,7 @@ extension DateExtensions on DateTime {
|
|||||||
bool isSameDay(final DateTime other) {
|
bool isSameDay(final DateTime other) {
|
||||||
return year == other.year && month == other.month && day == other.day;
|
return year == other.year && month == other.month && day == other.day;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DateTime asNormalizedDate() => DateTime(year, month, day);
|
||||||
|
DateTime asNormalizedDateTime() => DateTime(year, month, day, hour, minute);
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:share_location/extensions/date.dart';
|
||||||
import 'package:share_location/foreign_types/memory.dart';
|
import 'package:share_location/foreign_types/memory.dart';
|
||||||
import 'package:share_location/helpers/iterate_months.dart';
|
import 'package:share_location/helpers/iterate_months.dart';
|
||||||
|
|
||||||
@ -8,15 +9,12 @@ class CalendarManager {
|
|||||||
required final List<Memory> memories,
|
required final List<Memory> memories,
|
||||||
}) : _values = mapFromMemoriesList(memories);
|
}) : _values = mapFromMemoriesList(memories);
|
||||||
|
|
||||||
static DateTime createDateKey(final DateTime date) =>
|
|
||||||
DateTime(date.year, date.month, date.day);
|
|
||||||
|
|
||||||
static Map<DateTime, Set<String>> mapFromMemoriesList(
|
static Map<DateTime, Set<String>> mapFromMemoriesList(
|
||||||
final List<Memory> memories) {
|
final List<Memory> memories) {
|
||||||
final map = <DateTime, Set<String>>{};
|
final map = <DateTime, Set<String>>{};
|
||||||
|
|
||||||
for (final memory in memories) {
|
for (final memory in memories) {
|
||||||
final key = createDateKey(memory.creationDate);
|
final key = memory.creationDate.asNormalizedDate();
|
||||||
|
|
||||||
if (map.containsKey(key)) {
|
if (map.containsKey(key)) {
|
||||||
map[key]!.add(memory.id);
|
map[key]!.add(memory.id);
|
||||||
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:property_change_notifier/property_change_notifier.dart';
|
import 'package:property_change_notifier/property_change_notifier.dart';
|
||||||
|
import 'package:share_location/extensions/date.dart';
|
||||||
import 'package:share_location/foreign_types/memory.dart';
|
import 'package:share_location/foreign_types/memory.dart';
|
||||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||||
|
|
||||||
@ -43,9 +44,6 @@ class TimelineModel extends PropertyChangeNotifier<String> {
|
|||||||
_timeline.removeWhere((key, memories) => memories.isEmpty);
|
_timeline.removeWhere((key, memories) => memories.isEmpty);
|
||||||
}
|
}
|
||||||
|
|
||||||
static DateTime createDateKey(final DateTime date) =>
|
|
||||||
DateTime(date.year, date.month, date.day);
|
|
||||||
|
|
||||||
void restoreOverlay() => setShowOverlay(true);
|
void restoreOverlay() => setShowOverlay(true);
|
||||||
void hideOverlay() => setShowOverlay(false);
|
void hideOverlay() => setShowOverlay(false);
|
||||||
|
|
||||||
@ -55,7 +53,7 @@ class TimelineModel extends PropertyChangeNotifier<String> {
|
|||||||
final map = <DateTime, List<Memory>>{};
|
final map = <DateTime, List<Memory>>{};
|
||||||
|
|
||||||
for (final memory in memories) {
|
for (final memory in memories) {
|
||||||
final key = createDateKey(memory.creationDate);
|
final key = memory.creationDate.asNormalizedDate();
|
||||||
|
|
||||||
if (map.containsKey(key)) {
|
if (map.containsKey(key)) {
|
||||||
map[key]!.add(memory);
|
map[key]!.add(memory);
|
||||||
|
@ -5,6 +5,7 @@ import 'package:flutter_calendar_widget/flutter_calendar_widget.dart';
|
|||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:share_location/constants/spacing.dart';
|
import 'package:share_location/constants/spacing.dart';
|
||||||
import 'package:share_location/constants/values.dart';
|
import 'package:share_location/constants/values.dart';
|
||||||
|
import 'package:share_location/extensions/date.dart';
|
||||||
import 'package:share_location/screens/timeline_screen.dart';
|
import 'package:share_location/screens/timeline_screen.dart';
|
||||||
import 'package:share_location/widgets/delay_render.dart';
|
import 'package:share_location/widgets/delay_render.dart';
|
||||||
import 'package:share_location/widgets/fade_and_move_in_animation.dart';
|
import 'package:share_location/widgets/fade_and_move_in_animation.dart';
|
||||||
@ -113,6 +114,8 @@ class CalendarMonth extends StatelessWidget {
|
|||||||
DateTime get firstDate => DateTime(year, month, 1);
|
DateTime get firstDate => DateTime(year, month, 1);
|
||||||
DateTime get lastDate =>
|
DateTime get lastDate =>
|
||||||
DateTime(year, month, DateUtils.getDaysInMonth(year, month));
|
DateTime(year, month, DateUtils.getDaysInMonth(year, month));
|
||||||
|
bool doesDateExist(final DateTime date) =>
|
||||||
|
dayAmountMap.keys.contains(date.asNormalizedDate());
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -139,6 +142,10 @@ class CalendarMonth extends StatelessWidget {
|
|||||||
maxDate: lastDate,
|
maxDate: lastDate,
|
||||||
startingDayOfWeek: DayOfWeek.mon,
|
startingDayOfWeek: DayOfWeek.mon,
|
||||||
onDayPressed: (date) {
|
onDayPressed: (date) {
|
||||||
|
if (!doesDateExist(date)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user