dart format
This commit is contained in:
+93
-78
@@ -25,11 +25,7 @@ class FileViewer extends StatefulWidget {
|
||||
State<FileViewer> createState() => _FileViewerState();
|
||||
}
|
||||
|
||||
enum FileViewingActions {
|
||||
openExternal,
|
||||
share,
|
||||
save
|
||||
}
|
||||
enum FileViewingActions { openExternal, share, save }
|
||||
|
||||
/// Workaround for a Syncfusion PDF viewer race: SfPdfViewer's internal
|
||||
/// LayoutBuilder calls `localToGlobal` during build, which asserts when an
|
||||
@@ -88,7 +84,9 @@ class _FileViewerState extends State<FileViewer> {
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
openExternal = settings.val().fileViewSettings.alwaysOpenExternally || widget.openExternal;
|
||||
openExternal =
|
||||
settings.val().fileViewSettings.alwaysOpenExternally ||
|
||||
widget.openExternal;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@@ -101,96 +99,113 @@ class _FileViewerState extends State<FileViewer> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
AppBar appbar({List<Widget> actions = const []}) => AppBar(
|
||||
title: Text(widget.path.split('/').last),
|
||||
actions: [
|
||||
...actions,
|
||||
PopupMenuButton<FileViewingActions>(
|
||||
onSelected: (value) async {
|
||||
switch(value) {
|
||||
case FileViewingActions.openExternal:
|
||||
AppRoutes.openFileViewer(context, widget.path, openExternal: true);
|
||||
break;
|
||||
case FileViewingActions.share:
|
||||
unawaited(SharePlus.instance.share(
|
||||
title: Text(widget.path.split('/').last),
|
||||
actions: [
|
||||
...actions,
|
||||
PopupMenuButton<FileViewingActions>(
|
||||
onSelected: (value) async {
|
||||
switch (value) {
|
||||
case FileViewingActions.openExternal:
|
||||
AppRoutes.openFileViewer(
|
||||
context,
|
||||
widget.path,
|
||||
openExternal: true,
|
||||
);
|
||||
break;
|
||||
case FileViewingActions.share:
|
||||
unawaited(
|
||||
SharePlus.instance.share(
|
||||
ShareParams(
|
||||
files: [XFile(widget.path)],
|
||||
sharePositionOrigin: SharePositionOrigin.get(context),
|
||||
),
|
||||
));
|
||||
break;
|
||||
case FileViewingActions.save:
|
||||
try {
|
||||
final bytes = await File(widget.path).readAsBytes();
|
||||
final saved = await FilePicker.saveFile(
|
||||
fileName: widget.path.split('/').last,
|
||||
bytes: bytes,
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
if (saved != null) InfoDialog.show(context, 'Datei gespeichert.');
|
||||
} on Object catch (e) {
|
||||
if (!context.mounted) return;
|
||||
InfoDialog.show(context, 'Speichern fehlgeschlagen: $e', copyable: true, title: 'Fehler');
|
||||
),
|
||||
);
|
||||
break;
|
||||
case FileViewingActions.save:
|
||||
try {
|
||||
final bytes = await File(widget.path).readAsBytes();
|
||||
final saved = await FilePicker.saveFile(
|
||||
fileName: widget.path.split('/').last,
|
||||
bytes: bytes,
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
if (saved != null) {
|
||||
InfoDialog.show(context, 'Datei gespeichert.');
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
itemBuilder: (context) => <PopupMenuEntry<FileViewingActions>>[
|
||||
const PopupMenuItem(
|
||||
value: FileViewingActions.openExternal,
|
||||
child: ListTile(
|
||||
leading: Icon(Icons.open_in_new),
|
||||
title: Text('Extern öffnen'),
|
||||
dense: true,
|
||||
),
|
||||
} on Object catch (e) {
|
||||
if (!context.mounted) return;
|
||||
InfoDialog.show(
|
||||
context,
|
||||
'Speichern fehlgeschlagen: $e',
|
||||
copyable: true,
|
||||
title: 'Fehler',
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
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,
|
||||
),
|
||||
),
|
||||
const PopupMenuItem(
|
||||
value: FileViewingActions.share,
|
||||
child: ListTile(
|
||||
leading: Icon(Icons.share_outlined),
|
||||
title: Text('Teilen'),
|
||||
dense: true,
|
||||
),
|
||||
const PopupMenuItem(
|
||||
value: FileViewingActions.save,
|
||||
child: ListTile(
|
||||
leading: Icon(Icons.save_alt_outlined),
|
||||
title: Text('Speichern'),
|
||||
dense: true,
|
||||
),
|
||||
),
|
||||
const PopupMenuItem(
|
||||
value: FileViewingActions.save,
|
||||
child: ListTile(
|
||||
leading: Icon(Icons.save_alt_outlined),
|
||||
title: Text('Speichern'),
|
||||
dense: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
switch(openExternal ? '' : widget.path.split('.').last.toLowerCase()) {
|
||||
switch (openExternal ? '' : widget.path.split('.').last.toLowerCase()) {
|
||||
case 'png':
|
||||
case 'jpg':
|
||||
case 'jpeg':
|
||||
case 'webp':
|
||||
case 'gif':
|
||||
return Scaffold(
|
||||
appBar: appbar(
|
||||
actions: [
|
||||
IconButton(onPressed: () {
|
||||
setState(() {
|
||||
photoViewController.rotation += pi/2;
|
||||
});
|
||||
}, icon: const Icon(Icons.rotate_right)),
|
||||
]
|
||||
appBar: appbar(
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
photoViewController.rotation += pi / 2;
|
||||
});
|
||||
},
|
||||
icon: const Icon(Icons.rotate_right),
|
||||
),
|
||||
],
|
||||
),
|
||||
backgroundColor: Colors.white,
|
||||
body: PhotoView(
|
||||
controller: photoViewController,
|
||||
maxScale: 3.0,
|
||||
minScale: 0.1,
|
||||
imageProvider: Image.file(File(widget.path)).image,
|
||||
backgroundDecoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
),
|
||||
backgroundColor: Colors.white,
|
||||
body: PhotoView(
|
||||
controller: photoViewController,
|
||||
maxScale: 3.0,
|
||||
minScale: 0.1,
|
||||
imageProvider: Image.file(File(widget.path)).image,
|
||||
backgroundDecoration: BoxDecoration(color: Theme.of(context).colorScheme.surface),
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
case 'pdf':
|
||||
return Scaffold(
|
||||
appBar: appbar(),
|
||||
|
||||
Reference in New Issue
Block a user