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(
|
||||
|
||||
Reference in New Issue
Block a user