diff --git a/lib/home_page.dart b/lib/home_page.dart index 3dc8053..463003b 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:sheetless/sheetview.dart'; +import 'package:sheetless/sheet_viewer_page.dart'; import 'package:sheetless/storage_helper.dart'; import 'api.dart'; diff --git a/lib/sheet_viewer_page.dart b/lib/sheet_viewer_page.dart new file mode 100644 index 0000000..154d425 --- /dev/null +++ b/lib/sheet_viewer_page.dart @@ -0,0 +1,101 @@ +import 'package:flutter/material.dart'; +import 'package:pdfrx/pdfrx.dart'; +import 'package:sheetless/api.dart'; +import 'package:sheetless/sheet.dart'; + +class SheetViewerPage extends StatefulWidget { + final Sheet sheet; + final ApiClient apiClient; + + const SheetViewerPage( + {super.key, required this.sheet, required this.apiClient}); + + @override + State createState() => _SheetViewerPageState(); +} + +class _SheetViewerPageState extends State { + int page = 1; + int numPages = 1; + + @override + void initState() { + super.initState(); + } + + Future loadPdf() async { + var file = await widget.apiClient.getPdfFileCached(widget.sheet.uuid); + if (file == null) { + throw Exception("Failed fetching pdf file"); + } + + var document = await PdfDocument.openFile(file.path); + + return document; + } + + @override + Widget build(BuildContext context) { + print("Building with page: $page"); + return Scaffold( + appBar: AppBar( + title: Text(widget.sheet.name), + ), + body: FutureBuilder( + future: loadPdf(), + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.hasData) { + var document = snapshot.data; + if (document != null) { + numPages = document.pages.length; + } + return GestureDetector( + onTapUp: (TapUpDetails details) { + // Get the size of the screen + final screenWidth = MediaQuery.of(context).size.width; + + // Check where the user tapped + if (details.localPosition.dx < screenWidth / 2) { + // Left half of the screen + setState(() { + page = page > 1 ? page - 1 : 1; + }); + } else { + // Right half of the screen + setState(() { + page = page < numPages ? page + 1 : numPages; + }); + } + }, + child: Stack( + children: [ + PdfPageView( + key: ValueKey(page), + document: document, + pageNumber: page, + alignment: Alignment.center, + ), + Container( + child: Text('$page / $numPages'), + alignment: Alignment.bottomCenter, + padding: EdgeInsets.only(bottom: 5), + ), + ], + ), + ); + } else if (snapshot.hasError) { + return Center( + child: Text( + style: Theme.of(context) + .textTheme + .displaySmall! + .copyWith(color: Colors.red), + textAlign: TextAlign.center, + snapshot.error.toString())); + } else { + return const Center(child: CircularProgressIndicator()); + } + }), + ); + } +} diff --git a/lib/sheetview.dart b/lib/sheetview.dart index f4370d5..8b13789 100644 --- a/lib/sheetview.dart +++ b/lib/sheetview.dart @@ -1,63 +1 @@ -import 'package:flutter/material.dart'; -import 'package:pdfx/pdfx.dart'; -import 'package:sheetless/api.dart'; -import 'package:sheetless/sheet.dart'; -class SheetViewerPage extends StatefulWidget { - final Sheet sheet; - final ApiClient apiClient; - - const SheetViewerPage( - {super.key, required this.sheet, required this.apiClient}); - - @override - State createState() => _SheetViewerPageState(); -} - -class _SheetViewerPageState extends State { - @override - void initState() { - super.initState(); - } - - Future loadPdf() async { - var file = await widget.apiClient.getPdfFileCached(widget.sheet.uuid); - if (file == null) { - throw Exception("Failed fetching pdf file"); - } - - return PdfController(document: PdfDocument.openFile(file.path)); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text(widget.sheet.name), - ), - body: FutureBuilder( - future: loadPdf(), - builder: - (BuildContext context, AsyncSnapshot snapshot) { - if (snapshot.hasData) { - return PdfView( - controller: snapshot.data!, - pageSnapping: false, - scrollDirection: Axis.vertical, - ); - } else if (snapshot.hasError) { - return Center( - child: Text( - style: Theme.of(context) - .textTheme - .displaySmall! - .copyWith(color: Colors.red), - textAlign: TextAlign.center, - snapshot.error.toString())); - } else { - return const Center(child: CircularProgressIndicator()); - } - }), - ); - } -} diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index d0e7f79..38dd0bc 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -7,9 +7,13 @@ #include "generated_plugin_registrant.h" #include +#include void fl_register_plugins(FlPluginRegistry* registry) { g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin"); flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar); + g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin"); + url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar); } diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index b29e9ba..c51f243 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -4,9 +4,11 @@ list(APPEND FLUTTER_PLUGIN_LIST flutter_secure_storage_linux + url_launcher_linux ) list(APPEND FLUTTER_FFI_PLUGIN_LIST + pdfrx ) set(PLUGIN_BUNDLED_LIBRARIES) diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index db046a8..0a1ca75 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -10,6 +10,7 @@ import flutter_secure_storage_macos import path_provider_foundation import pdfx import sqflite_darwin +import url_launcher_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin")) @@ -17,4 +18,5 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) PdfxPlugin.register(with: registry.registrar(forPlugin: "PdfxPlugin")) SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) + UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) } diff --git a/pubspec.lock b/pubspec.lock index 73c2720..74dd023 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -336,6 +336,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.3.0" + pdfrx: + dependency: "direct main" + description: + name: pdfrx + sha256: "29c7b03d27d647c80da8cc08bd1256c74df90e5640fdd676646e4bd04f90553a" + url: "https://pub.dev" + source: hosted + version: "1.0.94" pdfx: dependency: "direct main" description: @@ -549,6 +557,70 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" + url_launcher: + dependency: transitive + description: + name: url_launcher + sha256: "9d06212b1362abc2f0f0d78e6f09f726608c74e3b9462e8368bb03314aa8d603" + url: "https://pub.dev" + source: hosted + version: "6.3.1" + url_launcher_android: + dependency: transitive + description: + name: url_launcher_android + sha256: "6fc2f56536ee873eeb867ad176ae15f304ccccc357848b351f6f0d8d4a40d193" + url: "https://pub.dev" + source: hosted + version: "6.3.14" + url_launcher_ios: + dependency: transitive + description: + name: url_launcher_ios + sha256: "16a513b6c12bb419304e72ea0ae2ab4fed569920d1c7cb850263fe3acc824626" + url: "https://pub.dev" + source: hosted + version: "6.3.2" + url_launcher_linux: + dependency: transitive + description: + name: url_launcher_linux + sha256: "4e9ba368772369e3e08f231d2301b4ef72b9ff87c31192ef471b380ef29a4935" + url: "https://pub.dev" + source: hosted + version: "3.2.1" + url_launcher_macos: + dependency: transitive + description: + name: url_launcher_macos + sha256: "17ba2000b847f334f16626a574c702b196723af2a289e7a93ffcb79acff855c2" + url: "https://pub.dev" + source: hosted + version: "3.2.2" + url_launcher_platform_interface: + dependency: transitive + description: + name: url_launcher_platform_interface + sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029" + url: "https://pub.dev" + source: hosted + version: "2.3.2" + url_launcher_web: + dependency: transitive + description: + name: url_launcher_web + sha256: "772638d3b34c779ede05ba3d38af34657a05ac55b06279ea6edd409e323dca8e" + url: "https://pub.dev" + source: hosted + version: "2.3.3" + url_launcher_windows: + dependency: transitive + description: + name: url_launcher_windows + sha256: "44cf3aabcedde30f2dba119a9dea3b0f2672fbe6fa96e85536251d678216b3c4" + url: "https://pub.dev" + source: hosted + version: "3.1.3" uuid: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 1bd5ba0..90ea1a0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -45,6 +45,7 @@ dependencies: flutter_cache_manager: ^3.4.1 flutter_secure_storage: ^9.2.2 jwt_decoder: ^2.0.1 + pdfrx: ^1.0.94 dev_dependencies: flutter_test: diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 1513f40..5d41db7 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -9,6 +9,7 @@ #include #include #include +#include void RegisterPlugins(flutter::PluginRegistry* registry) { FlutterSecureStorageWindowsPluginRegisterWithRegistrar( @@ -17,4 +18,6 @@ void RegisterPlugins(flutter::PluginRegistry* registry) { registry->GetRegistrarForPlugin("PdfxPlugin")); PermissionHandlerWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin")); + UrlLauncherWindowsRegisterWithRegistrar( + registry->GetRegistrarForPlugin("UrlLauncherWindows")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 326b594..749ee5c 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -6,9 +6,11 @@ list(APPEND FLUTTER_PLUGIN_LIST flutter_secure_storage_windows pdfx permission_handler_windows + url_launcher_windows ) list(APPEND FLUTTER_FFI_PLUGIN_LIST + pdfrx ) set(PLUGIN_BUNDLED_LIBRARIES)