-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from p2panda/delete-sighting
Delete sighting
- Loading branch information
Showing
7 changed files
with
142 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
|
||
import 'package:app/io/p2panda/publish.dart'; | ||
import 'package:app/models/sightings.dart'; | ||
import 'package:app/router.dart'; | ||
import 'package:app/ui/widgets/confirm_dialog.dart'; | ||
import 'package:app/ui/widgets/refresh_provider.dart'; | ||
|
||
class SightingPopupMenu extends StatelessWidget { | ||
final DocumentViewId viewId; | ||
|
||
const SightingPopupMenu({super.key, required this.viewId}); | ||
|
||
void _onDelete(BuildContext context) { | ||
final messenger = ScaffoldMessenger.of(context); | ||
final t = AppLocalizations.of(context)!; | ||
final refreshProvider = RefreshProvider.of(context); | ||
|
||
showDialog<String>( | ||
context: context, | ||
builder: (BuildContext context) => ConfirmDialog( | ||
title: t.sightingDeleteAlertTitle, | ||
message: t.sightingDeleteAlertBody, | ||
labelAbort: t.sightingDeleteAlertCancel, | ||
labelConfirm: t.sightingDeleteAlertConfirm, | ||
onConfirm: () async { | ||
// @TODO: also delete all uses documents and hive location documents. | ||
await deleteSighting(viewId); | ||
|
||
// Set flag for other widgets to tell them that they might need to | ||
// re-render their data. This will make sure that our updates are | ||
// reflected in the UI | ||
refreshProvider.setDirty(RefreshKeys.DeletedSighting); | ||
|
||
// First pop closes this dialog, second goes back to the view we came | ||
// from | ||
router.pop(); | ||
router.pop(); | ||
|
||
messenger.showSnackBar( | ||
SnackBar(content: Text(t.sightingDeleteConfirmation))); | ||
}, | ||
), | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return PopupMenuButton( | ||
itemBuilder: (BuildContext context) => [ | ||
PopupMenuItem<void>( | ||
child: Text(AppLocalizations.of(context)!.deleteSighting), | ||
onTap: () { | ||
_onDelete(context); | ||
}), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters