Add functional login page
This commit is contained in:
104
lib/main.dart
104
lib/main.dart
@@ -1,10 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:saf/saf.dart';
|
||||
import 'package:sheetless/sheetview.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
import 'api.dart';
|
||||
import 'sheet.dart';
|
||||
import 'login_page.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
@@ -21,103 +17,7 @@ class MyApp extends StatelessWidget {
|
||||
useMaterial3: true,
|
||||
primarySwatch: Colors.blue,
|
||||
),
|
||||
home: const MyHomePage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key});
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
ApiClient apiClient = ApiClient();
|
||||
Future<bool> apiLoggedIn = Future.value(false);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
apiLoggedIn = apiClient.login("admin@admin.com", "sheetable");
|
||||
}
|
||||
|
||||
// Future<String?> getSafPickedSheetsDirectory() async {
|
||||
// await Permission.storage.request();
|
||||
// await Permission.manageExternalStorage.request();
|
||||
// var pickedDirectories = await Saf.getPersistedPermissionDirectories();
|
||||
// if (pickedDirectories == null || pickedDirectories.isEmpty) {
|
||||
// return null;
|
||||
// }
|
||||
// return pickedDirectories.last;
|
||||
// }
|
||||
|
||||
Future<List<Sheet>> acquireSheets() async {
|
||||
// await Permission.storage.request();
|
||||
// await Permission.manageExternalStorage.request();
|
||||
//
|
||||
|
||||
await apiLoggedIn; // TODO: check if really logged in (returns bool)
|
||||
return await apiClient.fetchSheets();
|
||||
// return api.main();
|
||||
|
||||
// final directory = await getApplicationDocumentsDirectory();
|
||||
// print("Directory is: $directory");
|
||||
// String? sheetsDirectory = "/home/julian/Klavier";
|
||||
// if (sheetsDirectory == null || sheetsDirectory.isEmpty) {
|
||||
// await Saf.getDynamicDirectoryPermission(grantWritePermission: false);
|
||||
// sheetsDirectory = "/home/julian/Klavier";
|
||||
// if (sheetsDirectory == null || sheetsDirectory.isEmpty) {
|
||||
// throw Exception("No Directory selected");
|
||||
// }
|
||||
// }
|
||||
// return List.empty();
|
||||
|
||||
// var sheetsDirectoryFiles = await Saf.getFilesPathFor(sheetsDirectory);
|
||||
// if (sheetsDirectoryFiles == null) {
|
||||
// await Saf.releasePersistedPermissions();
|
||||
// throw Exception(
|
||||
// "Permissions for directory no longer valid or Directory deleted. Please restart app.");
|
||||
// }
|
||||
// return loadSheetsSorted(sheetsDirectoryFiles);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("My Sheets"),
|
||||
),
|
||||
body: FutureBuilder(
|
||||
future: acquireSheets(),
|
||||
builder: (BuildContext context, AsyncSnapshot<List<Sheet>> snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return SheetsWidget(
|
||||
sheets: snapshot.data!,
|
||||
callback: (sheet) => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => SheetViewerPage(
|
||||
sheet: sheet,
|
||||
apiClient: apiClient,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} 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());
|
||||
}
|
||||
}),
|
||||
home: const LoginPage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user