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