Add folder selection
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:sheetless/sheetview.dart';
|
||||
|
||||
import 'sheet.dart';
|
||||
@@ -31,6 +33,40 @@ class MyHomePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
Future<String?> getSavedSheetsPath() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getString("sheets-path");
|
||||
}
|
||||
|
||||
Future<void> saveSheetsPath(String path) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
prefs.setString("sheets-path", path);
|
||||
}
|
||||
|
||||
Future<String?> askForSheetsPath() async {
|
||||
return await FilePicker.platform.getDirectoryPath();
|
||||
}
|
||||
|
||||
Future<String> findAndSaveSheetsPath() async {
|
||||
String? savedSheetsPath = await getSavedSheetsPath();
|
||||
if (savedSheetsPath != null) {
|
||||
return savedSheetsPath;
|
||||
}
|
||||
|
||||
String? selectedSheetsPath = await askForSheetsPath();
|
||||
if (selectedSheetsPath != null) {
|
||||
await saveSheetsPath(selectedSheetsPath);
|
||||
return selectedSheetsPath;
|
||||
}
|
||||
|
||||
return "No path selected";
|
||||
}
|
||||
|
||||
Future<List<Sheet>> acquireSheets() async {
|
||||
var sheetsPath = await findAndSaveSheetsPath();
|
||||
return loadSheetsSorted(sheetsPath);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -38,7 +74,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
title: const Text("My Sheets"),
|
||||
),
|
||||
body: FutureBuilder(
|
||||
future: loadSheetsSorted(),
|
||||
future: acquireSheets(),
|
||||
builder: (BuildContext context, AsyncSnapshot<List<Sheet>> snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return SheetsWidget(
|
||||
|
||||
@@ -11,17 +11,16 @@ class Sheet {
|
||||
Sheet(this.author, this.name, this.path);
|
||||
}
|
||||
|
||||
Future<List<Sheet>> loadSheetsSorted() async {
|
||||
var sheets = await _loadSheets();
|
||||
Future<List<Sheet>> loadSheetsSorted(String path) async {
|
||||
var sheets = await _loadSheets(path);
|
||||
sheets.sort((left, right) => left.name.compareTo(right.name));
|
||||
return sheets;
|
||||
}
|
||||
|
||||
Future<List<Sheet>> _loadSheets() async {
|
||||
// TODO: Handle directory not found
|
||||
var dir = Directory("/home/julian/Nextcloud/jhome/Klavier-Noten/");
|
||||
Future<List<Sheet>> _loadSheets(String path) async {
|
||||
var dir = Directory(path);
|
||||
if (!dir.existsSync()) {
|
||||
throw Exception("Folder does not exist");
|
||||
throw Exception("Specified path '$path' does not exist");
|
||||
}
|
||||
final List<Sheet> sheets = List.empty(growable: true);
|
||||
await for (final FileSystemEntity x in dir.list()) {
|
||||
|
||||
@@ -7,8 +7,10 @@ import Foundation
|
||||
|
||||
import device_info_plus_macos
|
||||
import pdfx
|
||||
import shared_preferences_foundation
|
||||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
|
||||
PdfxPlugin.register(with: registry.registrar(forPlugin: "PdfxPlugin"))
|
||||
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
||||
}
|
||||
|
||||
120
pubspec.lock
120
pubspec.lock
@@ -137,6 +137,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.1.4"
|
||||
file_picker:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: file_picker
|
||||
sha256: d090ae03df98b0247b82e5928f44d1b959867049d18d73635e2e0bc3f49542b9
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.2.5"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
@@ -150,6 +158,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
flutter_plugin_android_lifecycle:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_plugin_android_lifecycle
|
||||
sha256: "60fc7b78455b94e6de2333d2f95196d32cf5c22f4b0b0520a628804cb463503b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.7"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
@@ -208,6 +224,30 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.8.2"
|
||||
path_provider_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_linux
|
||||
sha256: "2e32f1640f07caef0d3cb993680f181c79e54a3827b997d5ee221490d131fbd9"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.8"
|
||||
path_provider_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_platform_interface
|
||||
sha256: f0abc8ebd7253741f05488b4813d936b4d07c6bae3e86148a09e342ee4b08e76
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.5"
|
||||
path_provider_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_windows
|
||||
sha256: bcabbe399d4042b8ee687e17548d5d3f527255253b4a639f5f8d2094a9c2b45c
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.3"
|
||||
pdfx:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -224,6 +264,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.14.0"
|
||||
platform:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: platform
|
||||
sha256: "4a451831508d7d6ca779f7ac6e212b4023dd5a7d08a27a63da33756410e32b76"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.0"
|
||||
plugin_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -232,6 +280,70 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.3"
|
||||
process:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: process
|
||||
sha256: "53fd8db9cec1d37b0574e12f07520d582019cb6c44abf5479a01505099a34a09"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.2.4"
|
||||
shared_preferences:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: shared_preferences
|
||||
sha256: "5949029e70abe87f75cfe59d17bf5c397619c4b74a099b10116baeb34786fad9"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.17"
|
||||
shared_preferences_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_android
|
||||
sha256: "955e9736a12ba776bdd261cf030232b30eadfcd9c79b32a3250dd4a494e8c8f7"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.15"
|
||||
shared_preferences_foundation:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_foundation
|
||||
sha256: "2b55c18636a4edc529fa5cd44c03d3f3100c00513f518c5127c951978efcccd0"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.3"
|
||||
shared_preferences_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_linux
|
||||
sha256: f8ea038aa6da37090093974ebdcf4397010605fd2ff65c37a66f9d28394cb874
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.3"
|
||||
shared_preferences_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_platform_interface
|
||||
sha256: da9431745ede5ece47bc26d5d73a9d3c6936ef6945c101a5aca46f62e52c1cf3
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
shared_preferences_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_web
|
||||
sha256: a4b5bc37fe1b368bbc81f953197d55e12f49d0296e7e412dfe2d2d77d6929958
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.4"
|
||||
shared_preferences_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_windows
|
||||
sha256: "5eaf05ae77658d3521d0e993ede1af962d4b326cd2153d312df716dc250f00c9"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.3"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
@@ -333,6 +445,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.3"
|
||||
xdg_directories:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: xdg_directories
|
||||
sha256: ee1505df1426458f7f60aac270645098d318a8b4766d85fde75f76f2e21807d1
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
sdks:
|
||||
dart: ">=2.19.2 <3.0.0"
|
||||
flutter: ">=3.0.0"
|
||||
|
||||
@@ -38,6 +38,8 @@ dependencies:
|
||||
|
||||
path: ^1.8.2
|
||||
pdfx: ^2.3.0
|
||||
file_picker: ^5.2.5
|
||||
shared_preferences: ^2.0.17
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user