Better rotation for image FileViewer
This commit is contained in:
parent
de132a2ed1
commit
3cb3e12c94
@ -1,4 +1,5 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:better_open_file/better_open_file.dart';
|
import 'package:better_open_file/better_open_file.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -8,54 +9,72 @@ import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
|||||||
import 'confirmDialog.dart';
|
import 'confirmDialog.dart';
|
||||||
import 'placeholderView.dart';
|
import 'placeholderView.dart';
|
||||||
|
|
||||||
class FileViewer extends StatelessWidget {
|
class FileViewer extends StatefulWidget {
|
||||||
final String path;
|
final String path;
|
||||||
final bool openExternal;
|
final bool openExternal;
|
||||||
final bool allowExternal;
|
final bool allowExternal;
|
||||||
const FileViewer({super.key, required this.path, this.openExternal = false, this.allowExternal = true});
|
const FileViewer({super.key, required this.path, this.openExternal = false, this.allowExternal = true});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<FileViewer> createState() => _FileViewerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FileViewerState extends State<FileViewer> {
|
||||||
|
PhotoViewController photoViewController = PhotoViewController();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
AppBar appbar = AppBar(
|
AppBar appbar({List actions = const []}) {
|
||||||
title: Text(path.split("/").last),
|
return AppBar(
|
||||||
|
title: Text(widget.path.split("/").last),
|
||||||
actions: [
|
actions: [
|
||||||
Visibility(
|
Visibility(
|
||||||
visible: allowExternal,
|
visible: widget.allowExternal,
|
||||||
child: IconButton(onPressed: () => ConfirmDialog(
|
child: IconButton(onPressed: () => ConfirmDialog(
|
||||||
title: "Extern öffnen",
|
title: "Extern öffnen",
|
||||||
content: "Möchtest du die Datei mit dem Systemdialog öffnen?",
|
content: "Möchtest du die Datei mit dem Systemdialog öffnen?",
|
||||||
onConfirm: () => Navigator.of(context).push(MaterialPageRoute(builder: (context) => FileViewer(path: path, openExternal: true))),
|
onConfirm: () => Navigator.of(context).push(MaterialPageRoute(builder: (context) => FileViewer(path: widget.path, openExternal: true))),
|
||||||
confirmButton: "Öffnen",
|
confirmButton: "Öffnen",
|
||||||
).asDialog(context), icon: const Icon(Icons.open_in_new)),
|
).asDialog(context), icon: const Icon(Icons.open_in_new)),
|
||||||
)
|
),
|
||||||
|
...actions
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
switch(openExternal ? "" : path.split(".").last) {
|
}
|
||||||
|
|
||||||
|
switch(widget.openExternal ? "" : widget.path.split(".").last) {
|
||||||
case "png":
|
case "png":
|
||||||
case "jpg":
|
case "jpg":
|
||||||
case "jpeg":
|
case "jpeg":
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: appbar,
|
appBar: appbar(
|
||||||
|
actions: [
|
||||||
|
IconButton(onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
photoViewController.rotation += pi/2;
|
||||||
|
});
|
||||||
|
}, icon: const Icon(Icons.rotate_right)),
|
||||||
|
]
|
||||||
|
),
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
body: PhotoView(
|
body: PhotoView(
|
||||||
imageProvider: Image.file(File(path)).image,
|
controller: photoViewController,
|
||||||
|
imageProvider: Image.file(File(widget.path)).image,
|
||||||
backgroundDecoration: BoxDecoration(color: Theme.of(context).colorScheme.surface),
|
backgroundDecoration: BoxDecoration(color: Theme.of(context).colorScheme.surface),
|
||||||
enableRotation: true,
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
case "pdf":
|
case "pdf":
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: appbar,
|
appBar: appbar(),
|
||||||
body: SfPdfViewer.file(
|
body: SfPdfViewer.file(
|
||||||
File(path),
|
File(widget.path),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
OpenFile.open(path).then((result) {
|
OpenFile.open(widget.path).then((result) {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
if(result.type != ResultType.done) {
|
if(result.type != ResultType.done) {
|
||||||
showDialog(context: context, builder: (context) {
|
showDialog(context: context, builder: (context) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user