From 336be6cb723aa7a2697854b9d36b2c144f373bc2 Mon Sep 17 00:00:00 2001 From: marco Date: Fri, 23 Jan 2026 16:41:53 +0100 Subject: [PATCH] visually changed settings page --- lib/pages/settings_page.dart | 100 +++++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 33 deletions(-) diff --git a/lib/pages/settings_page.dart b/lib/pages/settings_page.dart index babf159..0bf1b5f 100644 --- a/lib/pages/settings_page.dart +++ b/lib/pages/settings_page.dart @@ -17,55 +17,89 @@ class SettingsPage extends StatefulWidget { } class _SettingsPageState extends State { + bool storagePermissionIsGranted = false; + final tileSpacing = 16.0; + + @override + void initState() { + PermissionService.storagePermissionStatus.then((value) { + storagePermissionIsGranted = value.isGranted; + if (context.mounted) setState(() {}); + }); + super.initState(); + } + @override Widget build(BuildContext context) { + final titlePadding = Theme.of(context).listTileTheme.contentPadding!; + checkStoragePermission; return Scaffold( appBar: AppBar(title: Text(AppLocalizations.of(context)!.settings)), - body: SizedBox( - width: MediaQuery.of(context).size.width * 0.9, - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - AppLocalizations.of(context)!.appData, - style: Theme.of(context).textTheme.titleLarge, - ), - ElevatedButton( - onPressed: () => onActivateJsonImportPressed(), - child: Text(AppLocalizations.of(context)!.import), - ), - ElevatedButton( - onPressed: () => onActivateJsonExportPressed(), - child: Text(AppLocalizations.of(context)!.export), - ), - ], + body: Center( + child: SizedBox( + width: MediaQuery.of(context).size.width * 0.9, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: titlePadding, + child: Text( + AppLocalizations.of(context)!.appData, + style: Theme.of(context).textTheme.titleLarge, + ), + ), + SizedBox(height: tileSpacing), + ListTile( + title: Text('Grant storage permisson'), + subtitle: Text( + 'For app-data settings to work, you need to grant the app permissions to manage internal storage.', + ), + onTap: () => PermissionService.requestStoragePermission, + trailing: Icon(Icons.arrow_forward_ios_rounded), + enabled: !storagePermissionIsGranted, + ), + SizedBox(height: tileSpacing), + ListTile( + title: Text(AppLocalizations.of(context)!.import), + subtitle: Text('Import app-data from a json file.'), + onTap: () => onActivateJsonImportPressed(), + trailing: Icon(Icons.arrow_forward_ios_rounded), + enabled: storagePermissionIsGranted, + ), + SizedBox(height: tileSpacing), + ListTile( + title: Text(AppLocalizations.of(context)!.export), + subtitle: Text( + 'Export app-data to a json file in the selected directory.', + ), + onTap: () => onActivateJsonExportPressed(), + trailing: Icon(Icons.arrow_forward_ios_rounded), + enabled: storagePermissionIsGranted, + ), + ], + ), ), ), ); } void onActivateJsonExportPressed() async { - if (!await checkStoragePermission) return; - + if (!await PermissionService.storagePermissionStatus.isGranted) return; Storage.exportToJsonFile().then(showExportInfo); } void onActivateJsonImportPressed() async { - if (!await checkStoragePermission) return; + if (!await PermissionService.storagePermissionStatus.isGranted) return; Storage.importFromJsonFile().then(showImportInfo); } - Future get checkStoragePermission async { - if (!(await PermissionService.requestStoragePermission).isGranted) { - if (mounted) { - Notifying.showErrorSnackbar( - context, - AppLocalizations.of(context)!.errorStoragePermisson, - ); - return false; + Future get checkStoragePermission async { + PermissionService.storagePermissionStatus.then((value) { + storagePermissionIsGranted = value.isGranted; + if (context.mounted && value.isGranted != storagePermissionIsGranted) { + setState(() {}); } - } - return true; + }); } void showExportInfo(bool success) => Notifying.showSnackbar( @@ -73,7 +107,7 @@ class _SettingsPageState extends State { text: success ? AppLocalizations.of(context)!.exportSuccess : AppLocalizations.of(context)!.exportFailed, - isError: success, + isError: !success, ); void showImportInfo(bool success) => Notifying.showSnackbar( @@ -81,6 +115,6 @@ class _SettingsPageState extends State { text: success ? AppLocalizations.of(context)!.importSuccess : AppLocalizations.of(context)!.importFailed, - isError: success, + isError: !success, ); }