From 1a13dc8710e378741c562137de61ddb5368cc785 Mon Sep 17 00:00:00 2001 From: Julian Mutter Date: Wed, 22 Feb 2023 18:26:07 +0100 Subject: [PATCH] Add pdf rendering --- lib/main.dart | 2 +- lib/sheet.dart | 24 +-- lib/sheetview.dart | 21 ++- macos/Flutter/GeneratedPluginRegistrant.swift | 4 + pubspec.lock | 150 ++++++++++++++++++ pubspec.yaml | 1 + .../flutter/generated_plugin_registrant.cc | 3 + windows/flutter/generated_plugins.cmake | 1 + 8 files changed, 189 insertions(+), 17 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index dd30f99..870588b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -51,7 +51,7 @@ class _MyHomePageState extends State { ), ); } else if (snapshot.hasError) { - return const Icon(Icons.error); + return Text(snapshot.error.toString()); } else { return const CircularProgressIndicator(); } diff --git a/lib/sheet.dart b/lib/sheet.dart index 3c6dd13..977280b 100644 --- a/lib/sheet.dart +++ b/lib/sheet.dart @@ -6,8 +6,9 @@ import 'package:path/path.dart' as p; class Sheet { final String author; final String name; + final String path; - Sheet(this.author, this.name); + Sheet(this.author, this.name, this.path); } Future> loadSheetsSorted() async { @@ -19,17 +20,18 @@ Future> loadSheetsSorted() async { Future> _loadSheets() async { // TODO: Handle directory not found var dir = Directory("/home/julian/Nextcloud/jhome/Klavier-Noten/"); + if (!dir.existsSync()) { + throw Exception("Folder does not exist"); + } final List sheets = List.empty(growable: true); - if (dir.existsSync()) { - await for (final FileSystemEntity x in dir.list()) { - if (x is Directory) { - var authorName = p.basename(x.path); - await for (final FileSystemEntity a in x.list()) { - if (a is File) { - var sheetName = p.basenameWithoutExtension(a.path); - sheetName = sheetName.capitalize(); - sheets.add(Sheet(authorName, sheetName)); - } + await for (final FileSystemEntity x in dir.list()) { + if (x is Directory) { + var authorName = p.basename(x.path); + await for (final FileSystemEntity a in x.list()) { + if (a is File) { + var sheetName = p.basenameWithoutExtension(a.path); + sheetName = sheetName.capitalize(); + sheets.add(Sheet(authorName, sheetName, a.path)); } } } diff --git a/lib/sheetview.dart b/lib/sheetview.dart index 09ffb13..737d2f8 100644 --- a/lib/sheetview.dart +++ b/lib/sheetview.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:pdfx/pdfx.dart'; import 'package:sheetless/sheet.dart'; class SheetViewerPage extends StatefulWidget { @@ -11,13 +12,23 @@ class SheetViewerPage extends StatefulWidget { } class _SheetViewerPageState extends State { + PdfControllerPinch? controller; + + @override + void initState() { + controller = + PdfControllerPinch(document: PdfDocument.openFile(widget.sheet.path)); + super.initState(); + } + @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: Text(widget.sheet.name), - ), - body: Center(child: Text(widget.sheet.author)), - ); + appBar: AppBar( + title: Text(widget.sheet.name), + ), + body: PdfViewPinch( + controller: controller!, + )); } } diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index cccf817..0e67812 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,6 +5,10 @@ import FlutterMacOS import Foundation +import device_info_plus_macos +import pdfx func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin")) + PdfxPlugin.register(with: registry.registrar(forPlugin: "PdfxPlugin")) } diff --git a/pubspec.lock b/pubspec.lock index afdf94b..d4ade6a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -41,6 +41,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.17.0" + crypto: + dependency: transitive + description: + name: crypto + sha256: aa274aa7774f8964e4f4f38cc994db7b6158dd36e9187aaceaddc994b35c6c67 + url: "https://pub.dev" + source: hosted + version: "3.0.2" cupertino_icons: dependency: "direct main" description: @@ -49,6 +57,62 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.5" + device_info_plus: + dependency: transitive + description: + name: device_info_plus + sha256: b809c4ed5f7fcdb325ccc70b80ad934677dc4e2aa414bf46859a42bfdfafcbb6 + url: "https://pub.dev" + source: hosted + version: "4.1.3" + device_info_plus_linux: + dependency: transitive + description: + name: device_info_plus_linux + sha256: "77a8b3c4af06bc46507f89304d9f49dfc64b4ae004b994532ed23b34adeae4b3" + url: "https://pub.dev" + source: hosted + version: "3.0.0" + device_info_plus_macos: + dependency: transitive + description: + name: device_info_plus_macos + sha256: "37961762fbd46d3620c7b69ca606671014db55fc1b7a11e696fd90ed2e8fe03d" + url: "https://pub.dev" + source: hosted + version: "3.0.0" + device_info_plus_platform_interface: + dependency: transitive + description: + name: device_info_plus_platform_interface + sha256: "83fdba24fcf6846d3b10f10dfdc8b6c6d7ada5f8ed21d62ea2909c2dfa043773" + url: "https://pub.dev" + source: hosted + version: "3.0.0" + device_info_plus_web: + dependency: transitive + description: + name: device_info_plus_web + sha256: "5890f6094df108181c7a29720bc23d0fd6159f17d82787fac093d1fefcaf6325" + url: "https://pub.dev" + source: hosted + version: "3.0.0" + device_info_plus_windows: + dependency: transitive + description: + name: device_info_plus_windows + sha256: "23a2874af0e23ee6e3a2a0ebcecec3a9da13241f2cb93a93a44c8764df123dd7" + url: "https://pub.dev" + source: hosted + version: "4.1.0" + extension: + dependency: transitive + description: + name: extension + sha256: "7df1ee2de6ccd05fd3e4d63acb194ae97e6525a2e8da067161c0cccb6a0a5305" + url: "https://pub.dev" + source: hosted + version: "0.5.0" fake_async: dependency: transitive description: @@ -57,6 +121,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.1" + ffi: + dependency: transitive + description: + name: ffi + sha256: a38574032c5f1dd06c4aee541789906c12ccaab8ba01446e800d9c5b79c4a978 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + file: + dependency: transitive + description: + name: file + sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d" + url: "https://pub.dev" + source: hosted + version: "6.1.4" flutter: dependency: "direct main" description: flutter @@ -75,6 +155,11 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" js: dependency: transitive description: @@ -123,6 +208,30 @@ packages: url: "https://pub.dev" source: hosted version: "1.8.2" + pdfx: + dependency: "direct main" + description: + name: pdfx + sha256: cad7eab6358a89922c8ea592b738891b3984edab43300558d25dc9b15a94a35e + url: "https://pub.dev" + source: hosted + version: "2.3.0" + photo_view: + dependency: transitive + description: + name: photo_view + sha256: "8036802a00bae2a78fc197af8a158e3e2f7b500561ed23b4c458107685e645bb" + url: "https://pub.dev" + source: hosted + version: "0.14.0" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + sha256: dbf0f707c78beedc9200146ad3cb0ab4d5da13c246336987be6940f026500d3a + url: "https://pub.dev" + source: hosted + version: "2.1.3" sky_engine: dependency: transitive description: flutter @@ -160,6 +269,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.0" + synchronized: + dependency: transitive + description: + name: synchronized + sha256: "33b31b6beb98100bf9add464a36a8dd03eb10c7a8cf15aeec535e9b054aaf04b" + url: "https://pub.dev" + source: hosted + version: "3.0.1" term_glyph: dependency: transitive description: @@ -176,6 +293,30 @@ packages: url: "https://pub.dev" source: hosted version: "0.4.16" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5" + url: "https://pub.dev" + source: hosted + version: "1.3.1" + universal_platform: + dependency: transitive + description: + name: universal_platform + sha256: d315be0f6641898b280ffa34e2ddb14f3d12b1a37882557869646e0cc363d0cc + url: "https://pub.dev" + source: hosted + version: "1.0.0+1" + uuid: + dependency: transitive + description: + name: uuid + sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313" + url: "https://pub.dev" + source: hosted + version: "3.0.7" vector_math: dependency: transitive description: @@ -184,5 +325,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + win32: + dependency: transitive + description: + name: win32 + sha256: c9ebe7ee4ab0c2194e65d3a07d8c54c5d00bb001b76081c4a04cdb8448b59e46 + url: "https://pub.dev" + source: hosted + version: "3.1.3" sdks: dart: ">=2.19.2 <3.0.0" + flutter: ">=3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 86f745c..4babbff 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -37,6 +37,7 @@ dependencies: cupertino_icons: ^1.0.2 path: ^1.8.2 + pdfx: ^2.3.0 dev_dependencies: flutter_test: diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 8b6d468..338e020 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,6 +6,9 @@ #include "generated_plugin_registrant.h" +#include void RegisterPlugins(flutter::PluginRegistry* registry) { + PdfxPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("PdfxPlugin")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index b93c4c3..73e221f 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + pdfx ) list(APPEND FLUTTER_FFI_PLUGIN_LIST