combined actions to popup menu
This commit is contained in:
@@ -23,6 +23,12 @@ class FileViewer extends StatefulWidget {
|
||||
State<FileViewer> createState() => _FileViewerState();
|
||||
}
|
||||
|
||||
enum FileViewingActions {
|
||||
openExternal,
|
||||
share,
|
||||
save
|
||||
}
|
||||
|
||||
class _FileViewerState extends State<FileViewer> {
|
||||
PhotoViewController photoViewController = PhotoViewController();
|
||||
|
||||
@@ -40,33 +46,57 @@ class _FileViewerState extends State<FileViewer> {
|
||||
AppBar appbar({List actions = const []}) => AppBar(
|
||||
title: Text(widget.path.split('/').last),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () => Navigator.of(context).push(
|
||||
...actions,
|
||||
PopupMenuButton<FileViewingActions>(
|
||||
onSelected: (value) async {
|
||||
switch(value) {
|
||||
case FileViewingActions.openExternal:
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(builder: (context) => FileViewer(path: widget.path, openExternal: true))
|
||||
),
|
||||
icon: const Icon(Icons.open_in_new)
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
Share.shareXFiles(
|
||||
[XFile(widget.path)],
|
||||
sharePositionOrigin: SharePositionOrigin.get(context),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.share_outlined),
|
||||
),
|
||||
Visibility(
|
||||
visible: Platform.isAndroid,
|
||||
child: IconButton(
|
||||
onPressed: () async {
|
||||
break;
|
||||
case FileViewingActions.share:
|
||||
SharePlus.instance.share(
|
||||
ShareParams(
|
||||
files: [XFile(widget.path)],
|
||||
sharePositionOrigin: SharePositionOrigin.get(context)
|
||||
)
|
||||
);
|
||||
break;
|
||||
case FileViewingActions.save:
|
||||
await FileSaver.writeBytes(await File(widget.path).readAsBytes(), widget.path.split('/').last);
|
||||
if(!context.mounted) return;
|
||||
InfoDialog.show(context, 'Die Datei wurde im Downloads Ordner gespeichert.');
|
||||
break;
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.save_alt_outlined)
|
||||
)
|
||||
itemBuilder: (context) => <PopupMenuEntry<FileViewingActions>>[
|
||||
const PopupMenuItem(
|
||||
value: FileViewingActions.openExternal,
|
||||
child: ListTile(
|
||||
leading: Icon(Icons.open_in_new),
|
||||
title: Text('Extern öffnen'),
|
||||
dense: true,
|
||||
),
|
||||
),
|
||||
const PopupMenuItem(
|
||||
value: FileViewingActions.share,
|
||||
child: ListTile(
|
||||
leading: Icon(Icons.share_outlined),
|
||||
title: Text('Teilen'),
|
||||
dense: true,
|
||||
),
|
||||
),
|
||||
if(Platform.isAndroid) const PopupMenuItem(
|
||||
value: FileViewingActions.save,
|
||||
child: ListTile(
|
||||
leading: Icon(Icons.save_alt_outlined),
|
||||
title: Text('Speichern'),
|
||||
dense: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
...actions
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user