import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../data/directory_listing.dart'; import '../ui/sessions/chat_adaptive.dart'; /// Confirms deleting [entry]. A folder is described as deleted only when /// empty; the server refuses a folder with contents and the panel then asks /// again with [confirmDeleteRecursive]. Future confirmDeleteEntry(BuildContext context, DirectoryEntry entry) => _confirm( context, title: 'Delete “${entry.name}”?', body: entry.isDir ? 'The folder is removed from the server if it is empty. ' 'This cannot be undone.' : 'The file is removed from the server. This cannot be undone.', action: 'Delete', ); /// Asks again once the server reported the folder is not empty; confirming /// deletes the folder and everything inside it. Future confirmDeleteRecursive( BuildContext context, DirectoryEntry entry, ) => _confirm( context, title: 'Delete “${entry.name}” and its contents?', body: '“${entry.name}” is not empty. Delete the folder and everything ' 'inside it? This cannot be undone.', action: 'Delete all', ); Future _confirm( BuildContext context, { required String title, required String body, required String action, }) async { final confirmed = chatControlsStyleOf(context) == ChatControlsStyle.cupertino ? await showCupertinoDialog( context: context, builder: (context) => CupertinoAlertDialog( title: Text(title), content: Text(body), actions: [ CupertinoDialogAction( onPressed: () => Navigator.pop(context, false), child: const Text('Cancel'), ), CupertinoDialogAction( isDestructiveAction: true, onPressed: () => Navigator.pop(context, true), child: Text(action), ), ], ), ) : await showDialog( context: context, builder: (context) => AlertDialog( title: Text(title), content: Text(body), actions: [ TextButton( onPressed: () => Navigator.pop(context, false), child: const Text('Cancel'), ), FilledButton( onPressed: () => Navigator.pop(context, true), child: Text(action), ), ], ), ); return confirmed == true; }