diff --git a/lib/widgets/settings/privacy/access_grants.dart b/lib/widgets/settings/privacy/access_grants.dart index c6843bc7b..aed9627f3 100644 --- a/lib/widgets/settings/privacy/access_grants.dart +++ b/lib/widgets/settings/privacy/access_grants.dart @@ -52,59 +52,72 @@ class _StorageAccessPageState extends State { title: Text(context.l10n.settingsStorageAccessTitle), ), body: SafeArea( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16), - child: Row( + child: FutureBuilder>( + future: _pathLoader, + builder: (context, snapshot) { + if (snapshot.hasError) { + return Text(snapshot.error.toString()); + } + if (snapshot.connectionState != ConnectionState.done && _lastPaths == null) { + return const SizedBox.shrink(); + } + _lastPaths = snapshot.data!..sort(); + if (_lastPaths!.isEmpty) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const _Header(), + const Divider(), + Expanded( + child: Padding( + padding: const EdgeInsets.all(8), + child: EmptyContent( + text: context.l10n.settingsStorageAccessEmpty, + ), + ), + ), + ], + ); + } + + return ListView( children: [ - const Icon(AIcons.info), - const SizedBox(width: 16), - Expanded(child: Text(context.l10n.settingsStorageAccessBanner)), + const _Header(), + const Divider(), + ..._lastPaths!.map((path) => ListTile( + title: Text(path), + dense: true, + trailing: IconButton( + icon: const Icon(AIcons.clear), + onPressed: () async { + await storageService.revokeDirectoryAccess(path); + _load(); + setState(() {}); + }, + tooltip: context.l10n.settingsStorageAccessRevokeTooltip, + ), + )), ], - ), - ), - const Divider(), - Expanded( - child: FutureBuilder>( - future: _pathLoader, - builder: (context, snapshot) { - if (snapshot.hasError) { - return Text(snapshot.error.toString()); - } - if (snapshot.connectionState != ConnectionState.done && _lastPaths == null) { - return const SizedBox.shrink(); - } - _lastPaths = snapshot.data!..sort(); - if (_lastPaths!.isEmpty) { - return EmptyContent( - text: context.l10n.settingsStorageAccessEmpty, - ); - } - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: _lastPaths! - .map((path) => ListTile( - title: Text(path), - dense: true, - trailing: IconButton( - icon: const Icon(AIcons.clear), - onPressed: () async { - await storageService.revokeDirectoryAccess(path); - _load(); - setState(() {}); - }, - tooltip: context.l10n.settingsStorageAccessRevokeTooltip, - ), - )) - .toList(), - ); - }, - ), - ), - ], - ), + ); + }), + ), + ); + } +} + +class _Header extends StatelessWidget { + const _Header({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16), + child: Row( + children: [ + const Icon(AIcons.info), + const SizedBox(width: 16), + Expanded(child: Text(context.l10n.settingsStorageAccessBanner)), + ], ), ); }