Fix: Delete files from memory widget (#1111)
This commit is contained in:
commit
e5af9ab928
1 changed files with 35 additions and 17 deletions
|
@ -3,6 +3,7 @@ import "dart:io";
|
||||||
import "package:flutter/cupertino.dart";
|
import "package:flutter/cupertino.dart";
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:intl/intl.dart";
|
import "package:intl/intl.dart";
|
||||||
|
import 'package:photos/models/file.dart';
|
||||||
import "package:photos/models/memory.dart";
|
import "package:photos/models/memory.dart";
|
||||||
import "package:photos/services/memories_service.dart";
|
import "package:photos/services/memories_service.dart";
|
||||||
import "package:photos/theme/text_style.dart";
|
import "package:photos/theme/text_style.dart";
|
||||||
|
@ -124,6 +125,7 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
|
||||||
),
|
),
|
||||||
extendBodyBehindAppBar: true,
|
extendBodyBehindAppBar: true,
|
||||||
body: Container(
|
body: Container(
|
||||||
|
key: ValueKey(widget.memories.length),
|
||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
child: Stack(
|
child: Stack(
|
||||||
alignment: Alignment.bottomCenter,
|
alignment: Alignment.bottomCenter,
|
||||||
|
@ -138,18 +140,33 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onFileDeleted() {
|
Future<void> onFileDeleted(Memory removedMemory) async {
|
||||||
if (widget.memories.length == 1) {
|
if (!mounted) {
|
||||||
Navigator.pop(context);
|
return;
|
||||||
} else {
|
}
|
||||||
|
final totalFiles = widget.memories.length;
|
||||||
|
if (totalFiles == 1) {
|
||||||
|
// Deleted the only file
|
||||||
|
Navigator.of(context).pop(); // Close pageview
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_index == totalFiles - 1) {
|
||||||
|
// Deleted the last file
|
||||||
|
await _pageController!.previousPage(
|
||||||
|
duration: const Duration(milliseconds: 200),
|
||||||
|
curve: Curves.easeInOut,
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
widget.memories.remove(removedMemory);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await _pageController!.nextPage(
|
||||||
|
duration: const Duration(milliseconds: 200),
|
||||||
|
curve: Curves.easeInOut,
|
||||||
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
if (_index != 0) {
|
|
||||||
_pageController?.jumpToPage(_index - 1);
|
|
||||||
}
|
|
||||||
widget.memories.removeAt(_index);
|
|
||||||
if (_index != 0) {
|
|
||||||
_index--;
|
_index--;
|
||||||
}
|
widget.memories.remove(removedMemory);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,7 +197,7 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildBottomIcons() {
|
Widget _buildBottomIcons() {
|
||||||
final file = widget.memories[_index].file;
|
final File currentFile = widget.memories[_index].file;
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
child: Container(
|
child: Container(
|
||||||
alignment: Alignment.bottomCenter,
|
alignment: Alignment.bottomCenter,
|
||||||
|
@ -194,7 +211,7 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
|
||||||
color: Colors.white, //same for both themes
|
color: Colors.white, //same for both themes
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
showDetailsSheet(context, file);
|
showDetailsSheet(context, currentFile);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
|
@ -207,14 +224,15 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await showSingleFileDeleteSheet(
|
await showSingleFileDeleteSheet(
|
||||||
context,
|
context,
|
||||||
file,
|
currentFile,
|
||||||
onFileRemoved: (file) => {onFileDeleted()},
|
onFileRemoved: (file) =>
|
||||||
|
{onFileDeleted(widget.memories[_index])},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 32,
|
height: 32,
|
||||||
child: FavoriteWidget(file),
|
child: FavoriteWidget(currentFile),
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
|
@ -222,7 +240,7 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
|
||||||
color: Colors.white, //same for both themes
|
color: Colors.white, //same for both themes
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
share(context, [file]);
|
share(context, [currentFile]);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
Loading…
Add table
Reference in a new issue