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