mirror of
https://github.com/Myzel394/quid_faciam_hodie.git
synced 2025-06-18 23:35:25 +02:00
added save from calendar functionality
This commit is contained in:
parent
4170ec99ea
commit
ff63d87600
@ -3,6 +3,16 @@ extension DateExtensions on DateTime {
|
|||||||
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 asNormalizedDate() => DateTime(
|
||||||
DateTime asNormalizedDateTime() => DateTime(year, month, day, hour, minute);
|
year,
|
||||||
|
month,
|
||||||
|
day,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
DateTime asNormalizedDateTime() =>
|
||||||
|
DateTime(year, month, day, hour, minute, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:gallery_saver/gallery_saver.dart';
|
||||||
import 'package:path/path.dart';
|
import 'package:path/path.dart';
|
||||||
import 'package:quid_faciam_hodie/enums.dart';
|
import 'package:quid_faciam_hodie/enums.dart';
|
||||||
import 'package:quid_faciam_hodie/managers/file_manager.dart';
|
import 'package:quid_faciam_hodie/managers/file_manager.dart';
|
||||||
@ -44,4 +45,17 @@ class Memory {
|
|||||||
'memories',
|
'memories',
|
||||||
filePath,
|
filePath,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Future<void> saveFileToGallery() async {
|
||||||
|
final file = await downloadToFile();
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case MemoryType.photo:
|
||||||
|
await GallerySaver.saveImage(file.path);
|
||||||
|
break;
|
||||||
|
case MemoryType.video:
|
||||||
|
await GallerySaver.saveVideo(file.path);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,6 +166,17 @@
|
|||||||
|
|
||||||
|
|
||||||
"calendarScreenTitle": "Calendar",
|
"calendarScreenTitle": "Calendar",
|
||||||
|
"calendarScreenSelectionTitle": "Selected {memories,plural, =1{one memory} other{{memories} memories}}",
|
||||||
|
"@calendarScreenSelectionTitle": {
|
||||||
|
"placeholders": {
|
||||||
|
"days": {
|
||||||
|
"type": "int"
|
||||||
|
},
|
||||||
|
"memories": {
|
||||||
|
"type": "int"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
"timelineScreenTitle": "Timeline",
|
"timelineScreenTitle": "Timeline",
|
||||||
|
64
lib/models/calendar_model.dart
Normal file
64
lib/models/calendar_model.dart
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:quid_faciam_hodie/extensions/date.dart';
|
||||||
|
import 'package:quid_faciam_hodie/foreign_types/memory.dart';
|
||||||
|
|
||||||
|
// The `CalendarModel` is only used to give the calendar day's a way to
|
||||||
|
// send whether they have been pressed to the parent widget.
|
||||||
|
class CalendarModel extends ChangeNotifier {
|
||||||
|
bool _isSavingToGallery = false;
|
||||||
|
final Set<DateTime> _selectedDates = {};
|
||||||
|
|
||||||
|
bool get isInSelectMode => _selectedDates.isNotEmpty;
|
||||||
|
bool get isSavingToGallery => _isSavingToGallery;
|
||||||
|
Set<DateTime> get selectedDates => _selectedDates;
|
||||||
|
|
||||||
|
void setIsInSelectMode(final bool value) {
|
||||||
|
if (_isSavingToGallery) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!value) {
|
||||||
|
_selectedDates.clear();
|
||||||
|
}
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setIsSavingToGallery(final bool value) {
|
||||||
|
_isSavingToGallery = value;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void addDate(final DateTime date) {
|
||||||
|
_selectedDates.add(date.asNormalizedDate());
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void removeDate(final DateTime date) {
|
||||||
|
_selectedDates.removeWhere((element) => element == date.asNormalizedDate());
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearDates() {
|
||||||
|
_selectedDates.clear();
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void toggleDate(final DateTime date) {
|
||||||
|
if (checkWhetherDateIsSelected(date)) {
|
||||||
|
removeDate(date);
|
||||||
|
} else {
|
||||||
|
addDate(date);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterable<Memory> filterMemories(final Iterable<Memory> memories) =>
|
||||||
|
memories.where(
|
||||||
|
(memory) => _selectedDates.contains(
|
||||||
|
memory.creationDate.asNormalizedDate(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
bool checkWhetherDateIsSelected(final DateTime date) {
|
||||||
|
return _selectedDates.contains(date.asNormalizedDate());
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||||
@ -5,7 +6,9 @@ import 'package:flutter_sticky_header/flutter_sticky_header.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:quid_faciam_hodie/constants/spacing.dart';
|
import 'package:quid_faciam_hodie/constants/spacing.dart';
|
||||||
import 'package:quid_faciam_hodie/managers/calendar_manager.dart';
|
import 'package:quid_faciam_hodie/managers/calendar_manager.dart';
|
||||||
|
import 'package:quid_faciam_hodie/models/calendar_model.dart';
|
||||||
import 'package:quid_faciam_hodie/models/memories.dart';
|
import 'package:quid_faciam_hodie/models/memories.dart';
|
||||||
|
import 'package:quid_faciam_hodie/screens/calendar_screen/save_to_gallery_modal.dart';
|
||||||
|
|
||||||
import 'calendar_screen/calendar_month.dart';
|
import 'calendar_screen/calendar_month.dart';
|
||||||
import 'calendar_screen/days_of_week_strip.dart';
|
import 'calendar_screen/days_of_week_strip.dart';
|
||||||
@ -27,10 +30,54 @@ class CalendarScreen extends StatelessWidget {
|
|||||||
final monthMapping = calendarManager.getMappingForList();
|
final monthMapping = calendarManager.getMappingForList();
|
||||||
|
|
||||||
return Consumer<Memories>(
|
return Consumer<Memories>(
|
||||||
builder: (context, memories, _) => PlatformScaffold(
|
builder: (context, memories, _) => ChangeNotifierProvider<CalendarModel>(
|
||||||
appBar: isCupertino(context)
|
create: (_) => CalendarModel(),
|
||||||
|
child: Consumer<CalendarModel>(
|
||||||
|
builder: (_, calendar, __) => PlatformScaffold(
|
||||||
|
appBar: (calendar.isInSelectMode || isCupertino(context))
|
||||||
? PlatformAppBar(
|
? PlatformAppBar(
|
||||||
title: Text(localizations.calendarScreenTitle),
|
leading: calendar.isInSelectMode
|
||||||
|
? PlatformIconButton(
|
||||||
|
icon: Icon(context.platformIcons.clear),
|
||||||
|
onPressed: calendar.clearDates,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
trailingActions: calendar.isInSelectMode
|
||||||
|
? <Widget>[
|
||||||
|
IconButton(
|
||||||
|
onPressed: () async {
|
||||||
|
calendar.setIsSavingToGallery(true);
|
||||||
|
|
||||||
|
final memoriesToSave =
|
||||||
|
calendar.filterMemories(memories.memories);
|
||||||
|
|
||||||
|
final hasSavedAll = await showPlatformDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (_) => SaveToGalleryModal(
|
||||||
|
memories: memoriesToSave,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (hasSavedAll == true) {
|
||||||
|
calendar.clearDates();
|
||||||
|
}
|
||||||
|
|
||||||
|
calendar.setIsSavingToGallery(true);
|
||||||
|
},
|
||||||
|
icon: Icon(isMaterial(context)
|
||||||
|
? Icons.download
|
||||||
|
: CupertinoIcons.down_arrow),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
: null,
|
||||||
|
title: Text(
|
||||||
|
calendar.isInSelectMode
|
||||||
|
? localizations.calendarScreenSelectionTitle(
|
||||||
|
calendar.selectedDates.length,
|
||||||
|
calendar.filterMemories(memories.memories).length,
|
||||||
|
)
|
||||||
|
: localizations.calendarScreenTitle,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
body: Padding(
|
body: Padding(
|
||||||
@ -47,18 +94,20 @@ class CalendarScreen extends StatelessWidget {
|
|||||||
material: (data) => data.canvasColor,
|
material: (data) => data.canvasColor,
|
||||||
cupertino: (data) => data.barBackgroundColor,
|
cupertino: (data) => data.barBackgroundColor,
|
||||||
),
|
),
|
||||||
padding: const EdgeInsets.symmetric(vertical: SMALL_SPACE),
|
padding:
|
||||||
|
const EdgeInsets.symmetric(vertical: SMALL_SPACE),
|
||||||
child: const DaysOfWeekStrip(),
|
child: const DaysOfWeekStrip(),
|
||||||
),
|
),
|
||||||
sliver: SliverList(
|
sliver: SliverList(
|
||||||
delegate: SliverChildBuilderDelegate(
|
delegate: SliverChildBuilderDelegate(
|
||||||
(context, index) {
|
(context, index) {
|
||||||
if (index == monthMapping.length) {
|
if (index == monthMapping.length) {
|
||||||
return MemoriesData();
|
return const MemoriesData();
|
||||||
}
|
}
|
||||||
|
|
||||||
final date = monthMapping.keys.elementAt(index);
|
final date = monthMapping.keys.elementAt(index);
|
||||||
final dayMapping = monthMapping.values.elementAt(index);
|
final dayMapping =
|
||||||
|
monthMapping.values.elementAt(index);
|
||||||
|
|
||||||
return CalendarMonth(
|
return CalendarMonth(
|
||||||
year: date.year,
|
year: date.year,
|
||||||
@ -74,6 +123,8 @@ class CalendarScreen extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_calendar_widget/flutter_calendar_widget.dart';
|
import 'package:flutter_calendar_widget/flutter_calendar_widget.dart';
|
||||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
import 'package:quid_faciam_hodie/constants/spacing.dart';
|
import 'package:quid_faciam_hodie/constants/spacing.dart';
|
||||||
import 'package:quid_faciam_hodie/constants/values.dart';
|
import 'package:quid_faciam_hodie/constants/values.dart';
|
||||||
import 'package:quid_faciam_hodie/extensions/date.dart';
|
import 'package:quid_faciam_hodie/extensions/date.dart';
|
||||||
|
import 'package:quid_faciam_hodie/models/calendar_model.dart';
|
||||||
import 'package:quid_faciam_hodie/screens/timeline_screen.dart';
|
import 'package:quid_faciam_hodie/screens/timeline_screen.dart';
|
||||||
import 'package:quid_faciam_hodie/widgets/delay_render.dart';
|
import 'package:quid_faciam_hodie/widgets/delay_render.dart';
|
||||||
import 'package:quid_faciam_hodie/widgets/fade_and_move_in_animation.dart';
|
import 'package:quid_faciam_hodie/widgets/fade_and_move_in_animation.dart';
|
||||||
@ -30,7 +33,18 @@ class MonthCalendarBuilder extends CalendarBuilder {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildDate(DateTime dateTime, DateType type, List events) {
|
Widget buildDate(DateTime dateTime, DateType type, List events) {
|
||||||
|
final delay = Duration(
|
||||||
|
microseconds: Random().nextInt(CALENDAR_DATE_IN_MAX_DELAY.inMicroseconds),
|
||||||
|
);
|
||||||
|
|
||||||
|
return Consumer<CalendarModel>(
|
||||||
|
builder: (_, calendar, __) {
|
||||||
|
final isSelected = calendar.checkWhetherDateIsSelected(dateTime);
|
||||||
final backgroundPercentage = () {
|
final backgroundPercentage = () {
|
||||||
|
if (isSelected) {
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
if (events.isEmpty) {
|
if (events.isEmpty) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
@ -40,17 +54,13 @@ class MonthCalendarBuilder extends CalendarBuilder {
|
|||||||
return amount / highestAmountOfEvents;
|
return amount / highestAmountOfEvents;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
final delay = Duration(
|
|
||||||
microseconds: Random().nextInt(CALENDAR_DATE_IN_MAX_DELAY.inMicroseconds),
|
|
||||||
);
|
|
||||||
|
|
||||||
return DelayRender(
|
return DelayRender(
|
||||||
delay: delay,
|
delay: delay,
|
||||||
child: FadeAndMoveInAnimation(
|
child: FadeAndMoveInAnimation(
|
||||||
opacityDuration:
|
opacityDuration:
|
||||||
DEFAULT_OPACITY_DURATION * CALENDAR_DATE_IN_DURATION_MULTIPLIER,
|
DEFAULT_OPACITY_DURATION * CALENDAR_DATE_IN_DURATION_MULTIPLIER,
|
||||||
translationDuration:
|
translationDuration: DEFAULT_TRANSLATION_DURATION *
|
||||||
DEFAULT_TRANSLATION_DURATION * CALENDAR_DATE_IN_DURATION_MULTIPLIER,
|
CALENDAR_DATE_IN_DURATION_MULTIPLIER,
|
||||||
translationOffset: const Offset(0.0, -MEDIUM_SPACE),
|
translationOffset: const Offset(0.0, -MEDIUM_SPACE),
|
||||||
child: Opacity(
|
child: Opacity(
|
||||||
opacity: () {
|
opacity: () {
|
||||||
@ -64,19 +74,28 @@ class MonthCalendarBuilder extends CalendarBuilder {
|
|||||||
|
|
||||||
return 1.0;
|
return 1.0;
|
||||||
}(),
|
}(),
|
||||||
|
child: GestureDetector(
|
||||||
|
onLongPress: () {
|
||||||
|
if (events.isNotEmpty) {
|
||||||
|
HapticFeedback.heavyImpact();
|
||||||
|
|
||||||
|
calendar.addDate(dateTime);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Material(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(TINY_SPACE),
|
padding: const EdgeInsets.all(TINY_SPACE),
|
||||||
child: ClipRRect(
|
child: ClipRRect(
|
||||||
borderRadius: BorderRadius.circular(SMALL_SPACE),
|
borderRadius: BorderRadius.circular(SMALL_SPACE),
|
||||||
child: Stack(
|
child: Stack(
|
||||||
alignment: style.dayAlignment,
|
alignment: Alignment.center,
|
||||||
children: [
|
children: [
|
||||||
SizedBox(
|
Container(
|
||||||
child: Container(
|
color: isSelected
|
||||||
color: textStyle.selectedDayTextColor
|
? textStyle.outsideDayTextColor
|
||||||
|
: textStyle.selectedDayTextColor
|
||||||
.withOpacity(backgroundPercentage),
|
.withOpacity(backgroundPercentage),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
Container(
|
Container(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
child: Text(
|
child: Text(
|
||||||
@ -94,11 +113,15 @@ class MonthCalendarBuilder extends CalendarBuilder {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CalendarMonth extends StatelessWidget {
|
class CalendarMonth extends StatefulWidget {
|
||||||
final Map<DateTime, int> dayAmountMap;
|
final Map<DateTime, int> dayAmountMap;
|
||||||
final int year;
|
final int year;
|
||||||
final int month;
|
final int month;
|
||||||
@ -110,17 +133,27 @@ class CalendarMonth extends StatelessWidget {
|
|||||||
required this.month,
|
required this.month,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
int get highestAmount =>
|
@override
|
||||||
dayAmountMap.values.isEmpty ? 0 : dayAmountMap.values.reduce(max);
|
State<CalendarMonth> createState() => _CalendarMonthState();
|
||||||
DateTime get firstDate => DateTime(year, month, 1);
|
}
|
||||||
DateTime get lastDate =>
|
|
||||||
DateTime(year, month, DateUtils.getDaysInMonth(year, month));
|
class _CalendarMonthState extends State<CalendarMonth> {
|
||||||
|
int get highestAmount => widget.dayAmountMap.values.isEmpty
|
||||||
|
? 0
|
||||||
|
: widget.dayAmountMap.values.reduce(max);
|
||||||
|
|
||||||
|
DateTime get firstDate => DateTime(widget.year, widget.month, 1);
|
||||||
|
|
||||||
|
DateTime get lastDate => DateTime(widget.year, widget.month,
|
||||||
|
DateUtils.getDaysInMonth(widget.year, widget.month));
|
||||||
|
|
||||||
bool doesDateExist(final DateTime date) =>
|
bool doesDateExist(final DateTime date) =>
|
||||||
dayAmountMap.keys.contains(date.asNormalizedDate());
|
widget.dayAmountMap.keys.contains(date.asNormalizedDate());
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return FlutterCalendar(
|
return Consumer<CalendarModel>(
|
||||||
|
builder: (_, calendar, __) => FlutterCalendar(
|
||||||
focusedDate: firstDate,
|
focusedDate: firstDate,
|
||||||
selectionMode: CalendarSelectionMode.single,
|
selectionMode: CalendarSelectionMode.single,
|
||||||
calendarBuilder: MonthCalendarBuilder(),
|
calendarBuilder: MonthCalendarBuilder(),
|
||||||
@ -129,7 +162,7 @@ class CalendarMonth extends StatelessWidget {
|
|||||||
highestAmount,
|
highestAmount,
|
||||||
],
|
],
|
||||||
...Map.fromEntries(
|
...Map.fromEntries(
|
||||||
dayAmountMap.entries.map((entry) {
|
widget.dayAmountMap.entries.map((entry) {
|
||||||
return MapEntry(
|
return MapEntry(
|
||||||
entry.key,
|
entry.key,
|
||||||
[highestAmount, entry.value],
|
[highestAmount, entry.value],
|
||||||
@ -141,6 +174,14 @@ class CalendarMonth extends StatelessWidget {
|
|||||||
maxDate: lastDate,
|
maxDate: lastDate,
|
||||||
startingDayOfWeek: DayOfWeek.mon,
|
startingDayOfWeek: DayOfWeek.mon,
|
||||||
onDayPressed: (date) {
|
onDayPressed: (date) {
|
||||||
|
if (calendar.isInSelectMode &&
|
||||||
|
widget.dayAmountMap.keys.contains(date.asNormalizedDate())) {
|
||||||
|
HapticFeedback.selectionClick();
|
||||||
|
|
||||||
|
calendar.toggleDate(date);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!doesDateExist(date)) {
|
if (!doesDateExist(date)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -178,6 +219,13 @@ class CalendarMonth extends StatelessWidget {
|
|||||||
material: (data) => data.dialogBackgroundColor,
|
material: (data) => data.dialogBackgroundColor,
|
||||||
cupertino: (data) => data.barBackgroundColor,
|
cupertino: (data) => data.barBackgroundColor,
|
||||||
),
|
),
|
||||||
|
// Primary theme color
|
||||||
|
outsideDayTextColor: platformThemeData(
|
||||||
|
context,
|
||||||
|
material: (data) => data.colorScheme.primary,
|
||||||
|
cupertino: (data) => data.primaryColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
72
lib/screens/calendar_screen/save_to_gallery_modal.dart
Normal file
72
lib/screens/calendar_screen/save_to_gallery_modal.dart
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:quid_faciam_hodie/constants/spacing.dart';
|
||||||
|
import 'package:quid_faciam_hodie/foreign_types/memory.dart';
|
||||||
|
import 'package:quid_faciam_hodie/utils/theme.dart';
|
||||||
|
import 'package:quid_faciam_hodie/widgets/modal_sheet.dart';
|
||||||
|
|
||||||
|
class SaveToGalleryModal extends StatefulWidget {
|
||||||
|
final Iterable<Memory> memories;
|
||||||
|
|
||||||
|
const SaveToGalleryModal({
|
||||||
|
Key? key,
|
||||||
|
required this.memories,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<SaveToGalleryModal> createState() => _SaveToGalleryModalState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SaveToGalleryModalState extends State<SaveToGalleryModal> {
|
||||||
|
int currentMemory = 0;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
downloadMemories();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> downloadMemories() async {
|
||||||
|
for (final memory in widget.memories) {
|
||||||
|
await memory.saveFileToGallery();
|
||||||
|
|
||||||
|
if (widget.memories.last != memory) {
|
||||||
|
setState(() {
|
||||||
|
currentMemory = currentMemory + 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
Navigator.pop(context, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ModalSheet(
|
||||||
|
child: Column(
|
||||||
|
children: <Widget>[
|
||||||
|
Text(
|
||||||
|
'Saving to gallery',
|
||||||
|
style: getTitleTextStyle(context),
|
||||||
|
),
|
||||||
|
const SizedBox(height: LARGE_SPACE),
|
||||||
|
Text(
|
||||||
|
'${currentMemory}/${widget.memories.length}',
|
||||||
|
style: getBodyTextTextStyle(context),
|
||||||
|
),
|
||||||
|
const SizedBox(height: MEDIUM_SPACE),
|
||||||
|
LinearProgressIndicator(
|
||||||
|
value: currentMemory / widget.memories.length,
|
||||||
|
),
|
||||||
|
const SizedBox(height: MEDIUM_SPACE),
|
||||||
|
Text(
|
||||||
|
widget.memories.elementAt(currentMemory).annotation,
|
||||||
|
style: getSubTitleTextStyle(context),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -3,9 +3,7 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||||
import 'package:gallery_saver/gallery_saver.dart';
|
|
||||||
import 'package:quid_faciam_hodie/constants/spacing.dart';
|
import 'package:quid_faciam_hodie/constants/spacing.dart';
|
||||||
import 'package:quid_faciam_hodie/enums.dart';
|
|
||||||
import 'package:quid_faciam_hodie/extensions/snackbar.dart';
|
import 'package:quid_faciam_hodie/extensions/snackbar.dart';
|
||||||
import 'package:quid_faciam_hodie/foreign_types/memory.dart';
|
import 'package:quid_faciam_hodie/foreign_types/memory.dart';
|
||||||
import 'package:quid_faciam_hodie/managers/file_manager.dart';
|
import 'package:quid_faciam_hodie/managers/file_manager.dart';
|
||||||
@ -50,16 +48,7 @@ class _MemorySheetState extends State<MemorySheet> with Loadable {
|
|||||||
final localizations = AppLocalizations.of(context)!;
|
final localizations = AppLocalizations.of(context)!;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final file = await widget.memory.downloadToFile();
|
await widget.memory.saveFileToGallery();
|
||||||
|
|
||||||
switch (widget.memory.type) {
|
|
||||||
case MemoryType.photo:
|
|
||||||
await GallerySaver.saveImage(file.path);
|
|
||||||
break;
|
|
||||||
case MemoryType.video:
|
|
||||||
await GallerySaver.saveVideo(file.path);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mounted) {
|
if (!mounted) {
|
||||||
return;
|
return;
|
||||||
|
@ -14,12 +14,9 @@ class ModalSheet extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SingleChildScrollView(
|
return Align(
|
||||||
padding: const EdgeInsets.only(top: MEDIUM_SPACE),
|
alignment: Alignment.bottomCenter,
|
||||||
child: Column(
|
child: PlatformWidget(
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
PlatformWidget(
|
|
||||||
material: (_, __) => Container(
|
material: (_, __) => Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: const BorderRadius.only(
|
borderRadius: const BorderRadius.only(
|
||||||
@ -28,9 +25,11 @@ class ModalSheet extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
color: getSheetColor(context),
|
color: getSheetColor(context),
|
||||||
),
|
),
|
||||||
padding: const EdgeInsets.symmetric(vertical: LARGE_SPACE),
|
child: SingleChildScrollView(
|
||||||
child: Padding(
|
padding: const EdgeInsets.symmetric(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: MEDIUM_SPACE),
|
vertical: LARGE_SPACE,
|
||||||
|
horizontal: MEDIUM_SPACE,
|
||||||
|
),
|
||||||
child: child,
|
child: child,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -38,14 +37,15 @@ class ModalSheet extends StatelessWidget {
|
|||||||
isSurfacePainted: false,
|
isSurfacePainted: false,
|
||||||
child: Container(
|
child: Container(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
child: Padding(
|
child: SingleChildScrollView(
|
||||||
padding: const EdgeInsets.symmetric(vertical: LARGE_SPACE),
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: LARGE_SPACE,
|
||||||
|
horizontal: MEDIUM_SPACE,
|
||||||
|
),
|
||||||
child: child,
|
child: child,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user