Add pdf rendering
This commit is contained in:
@@ -51,7 +51,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
),
|
||||
);
|
||||
} else if (snapshot.hasError) {
|
||||
return const Icon(Icons.error);
|
||||
return Text(snapshot.error.toString());
|
||||
} else {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
|
||||
@@ -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<List<Sheet>> loadSheetsSorted() async {
|
||||
@@ -19,17 +20,18 @@ Future<List<Sheet>> loadSheetsSorted() async {
|
||||
Future<List<Sheet>> _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<Sheet> 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<SheetViewerPage> {
|
||||
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!,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user