Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
23
lib/utils/FileSaver.dart
Normal file
23
lib/utils/FileSaver.dart
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
|
||||||
|
// only tested on android!
|
||||||
|
class FileSaver {
|
||||||
|
static Future<String> getExternalDocumentPath() async {
|
||||||
|
var permission = await Permission.storage.status;
|
||||||
|
if(!permission.isGranted) {
|
||||||
|
await Permission.storage.request();
|
||||||
|
}
|
||||||
|
var directory = Directory('/storage/emulated/0/Download');
|
||||||
|
final externalPath = directory.path;
|
||||||
|
await Directory(externalPath).create(recursive: true);
|
||||||
|
return externalPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<File> writeBytes(List<int> bytes, String name) async {
|
||||||
|
final path = await getExternalDocumentPath();
|
||||||
|
var file = File('$path/$name');
|
||||||
|
return file.writeAsBytes(bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,8 @@ import 'package:share_plus/share_plus.dart';
|
|||||||
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
||||||
|
|
||||||
import '../storage/base/settingsProvider.dart';
|
import '../storage/base/settingsProvider.dart';
|
||||||
|
import '../utils/FileSaver.dart';
|
||||||
|
import 'infoDialog.dart';
|
||||||
import 'placeholderView.dart';
|
import 'placeholderView.dart';
|
||||||
import 'sharePositionOrigin.dart';
|
import 'sharePositionOrigin.dart';
|
||||||
|
|
||||||
@@ -21,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();
|
||||||
|
|
||||||
@@ -38,22 +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>(
|
||||||
MaterialPageRoute(builder: (context) => FileViewer(path: widget.path, openExternal: true))
|
onSelected: (value) async {
|
||||||
),
|
switch(value) {
|
||||||
icon: const Icon(Icons.open_in_new)
|
case FileViewingActions.openExternal:
|
||||||
),
|
Navigator.of(context).push(
|
||||||
IconButton(
|
MaterialPageRoute(builder: (context) => FileViewer(path: widget.path, openExternal: true))
|
||||||
onPressed: () {
|
);
|
||||||
Share.shareXFiles(
|
break;
|
||||||
[XFile(widget.path)],
|
case FileViewingActions.share:
|
||||||
sharePositionOrigin: SharePositionOrigin.get(context),
|
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.share_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
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ dependencies:
|
|||||||
open_filex: ^4.7.0
|
open_filex: ^4.7.0
|
||||||
package_info_plus: ^8.1.3
|
package_info_plus: ^8.1.3
|
||||||
path_provider: ^2.1.5
|
path_provider: ^2.1.5
|
||||||
|
permission_handler: ^12.0.1
|
||||||
persistent_bottom_nav_bar_v2: ^6.1.0
|
persistent_bottom_nav_bar_v2: ^6.1.0
|
||||||
photo_view: ^0.15.0
|
photo_view: ^0.15.0
|
||||||
pretty_json: ^2.0.0
|
pretty_json: ^2.0.0
|
||||||
|
|||||||
Reference in New Issue
Block a user