From e5a971f3a3afadac3b199ccbe03845d663ad5568 Mon Sep 17 00:00:00 2001 From: Juan Gilsanz Polo Date: Thu, 2 Nov 2023 18:26:58 +0100 Subject: [PATCH] Bug fixes --- lib/main.dart | 2 +- lib/screens/clients/added_list.dart | 1 - .../clients/client/added_client_tile.dart | 8 +- .../filters/filters_triple_column.dart | 508 +++++++++--------- .../logs/configuration/config_widgets.dart | 16 +- .../logs/configuration/logs_config_modal.dart | 12 +- 6 files changed, 273 insertions(+), 274 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index b2bb30d..8696561 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -214,7 +214,7 @@ class _MainState extends State
with WidgetsBindingObserver { isBeta: appConfigProvider.getAppInfo!.version.contains('beta'), ); if (result != null && appConfigProvider.doNotRememberVersion != result.tagName && mounted) { - await showDialog( + showDialog( context: context, builder: (context) => UpdateModal( gitHubRelease: result, diff --git a/lib/screens/clients/added_list.dart b/lib/screens/clients/added_list.dart index eea9dd6..2c93a04 100644 --- a/lib/screens/clients/added_list.dart +++ b/lib/screens/clients/added_list.dart @@ -188,7 +188,6 @@ class _AddedListState extends State { : null, onDelete: openDeleteModal, splitView: widget.splitView, - serverVersion: statusProvider.serverStatus!.serverVersion, ), noData: SizedBox( width: double.maxFinite, diff --git a/lib/screens/clients/client/added_client_tile.dart b/lib/screens/clients/client/added_client_tile.dart index 9db4edb..aa3c31e 100644 --- a/lib/screens/clients/client/added_client_tile.dart +++ b/lib/screens/clients/client/added_client_tile.dart @@ -5,6 +5,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:adguard_home_manager/widgets/custom_list_tile.dart'; +import 'package:adguard_home_manager/providers/status_provider.dart'; import 'package:adguard_home_manager/functions/compare_versions.dart'; import 'package:adguard_home_manager/functions/copy_clipboard.dart'; import 'package:adguard_home_manager/models/clients.dart'; @@ -18,7 +19,6 @@ class AddedClientTile extends StatelessWidget { final void Function(Client) onDelete; final Client? selectedClient; final bool? splitView; - final String serverVersion; const AddedClientTile({ Key? key, @@ -29,11 +29,11 @@ class AddedClientTile extends StatelessWidget { required this.onDelete, this.selectedClient, required this.splitView, - required this.serverVersion }) : super(key: key); @override Widget build(BuildContext context) { + final statusProvider = Provider.of(context); final appConfigProvider = Provider.of(context); if (splitView == true) { @@ -147,7 +147,7 @@ class AddedClientTile extends StatelessWidget { Icons.search_rounded, size: 19, color: serverVersionIsAhead( - currentVersion: serverVersion, + currentVersion: statusProvider.serverStatus!.serverVersion, referenceVersion: 'v0.107.28', referenceVersionBeta: 'v0.108.0-b.33' ) == true @@ -261,7 +261,7 @@ class AddedClientTile extends StatelessWidget { Icons.search_rounded, size: 19, color: serverVersionIsAhead( - currentVersion: serverVersion, + currentVersion: statusProvider.serverStatus!.serverVersion, referenceVersion: 'v0.107.28', referenceVersionBeta: 'v0.108.0-b.33' ) == true diff --git a/lib/screens/filters/filters_triple_column.dart b/lib/screens/filters/filters_triple_column.dart index 3a8bfa2..6ecdd8f 100644 --- a/lib/screens/filters/filters_triple_column.dart +++ b/lib/screens/filters/filters_triple_column.dart @@ -73,258 +73,7 @@ class FiltersTripleColumn extends StatelessWidget { else { return null; } - } - - Widget content() { - switch (filteringProvider.loadStatus) { - case LoadStatus.loading: - return Row( - mainAxisAlignment: MainAxisAlignment.center, - mainAxisSize: MainAxisSize.max, - children: [ - Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - const CircularProgressIndicator(), - const SizedBox(height: 30), - Text( - AppLocalizations.of(context)!.loadingFilters, - style: TextStyle( - fontSize: 22, - color: Theme.of(context).colorScheme.onSurfaceVariant, - ), - ) - ], - ), - ], - ); - - case LoadStatus.loaded: - return Row( - children: [ - Expanded( - flex: 1, - child: Column( - children: [ - Padding( - padding: const EdgeInsets.all(16), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - AppLocalizations.of(context)!.whitelists, - style: const TextStyle( - fontSize: 18, - fontWeight: FontWeight.w500 - ), - ), - AddFiltersButton( - type: 'whitelist', - widget: (fn) => IconButton( - onPressed: fn, - icon: const Icon(Icons.add_rounded), - tooltip: AppLocalizations.of(context)!.addWhitelist, - ), - ) - ], - ), - ), - Expanded( - child: ListView.builder( - itemCount: filteringProvider.filtering!.whitelistFilters.length, - itemBuilder: (context, index) => ListOptionsMenu( - list: filteringProvider.filtering!.whitelistFilters[index], - listType: 'whitelist', - child: CustomListTile( - title: filteringProvider.filtering!.whitelistFilters[index].name, - subtitle: "${intFormat(filteringProvider.filtering!.whitelistFilters[index].rulesCount, Platform.localeName)} ${AppLocalizations.of(context)!.enabledRules}", - trailing: Icon( - filteringProvider.filtering!.whitelistFilters[index].enabled == true - ? Icons.check_circle_rounded - : Icons.cancel, - color: filteringProvider.filtering!.whitelistFilters[index].enabled == true - ? appConfigProvider.useThemeColorForStatus == true - ? Theme.of(context).colorScheme.primary - : Colors.green - : appConfigProvider.useThemeColorForStatus == true - ? Colors.grey - : Colors.red - ), - onTap: () => onOpenDetailsModal(filteringProvider.filtering!.whitelistFilters[index], 'whitelist'), - ), - ), - ), - ) - ], - ), - ), - Expanded( - flex: 1, - child: Column( - children: [ - Padding( - padding: const EdgeInsets.all(16), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - AppLocalizations.of(context)!.blacklists, - style: const TextStyle( - fontSize: 18, - fontWeight: FontWeight.w500 - ), - ), - AddFiltersButton( - type: 'blacklist', - widget: (fn) => IconButton( - onPressed: fn, - icon: const Icon(Icons.add_rounded), - tooltip: AppLocalizations.of(context)!.addBlacklist, - ) - ) - ], - ), - ), - Expanded( - child: ListView.builder( - itemCount: filteringProvider.filtering!.filters.length, - itemBuilder: (context, index) => ListOptionsMenu( - list: filteringProvider.filtering!.filters[index], - listType: 'blacklist', - child: CustomListTile( - title: filteringProvider.filtering!.filters[index].name, - subtitle: "${intFormat(filteringProvider.filtering!.filters[index].rulesCount, Platform.localeName)} ${AppLocalizations.of(context)!.enabledRules}", - trailing: Icon( - filteringProvider.filtering!.filters[index].enabled == true - ? Icons.check_circle_rounded - : Icons.cancel, - color: filteringProvider.filtering!.filters[index].enabled == true - ? appConfigProvider.useThemeColorForStatus == true - ? Theme.of(context).colorScheme.primary - : Colors.green - : appConfigProvider.useThemeColorForStatus == true - ? Colors.grey - : Colors.red - ), - onTap: () => onOpenDetailsModal(filteringProvider.filtering!.filters[index], 'blacklist'), - ), - ), - ), - ) - ], - ), - ), - Expanded( - flex: 1, - child: Column( - children: [ - Padding( - padding: const EdgeInsets.all(16), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - AppLocalizations.of(context)!.customRules, - style: const TextStyle( - fontSize: 18, - fontWeight: FontWeight.w500 - ), - ), - AddFiltersButton( - type: '', - widget: (fn) => IconButton( - onPressed: fn, - icon: const Icon(Icons.add_rounded), - tooltip: AppLocalizations.of(context)!.addCustomRule, - ) - ) - ], - ), - ), - Expanded( - child: ListView.builder( - itemCount: filteringProvider.filtering!.userRules.length, - itemBuilder: (context, index) => ContextMenuArea( - builder: (context) => [ - CustomListTile( - title: AppLocalizations.of(context)!.copyClipboard, - icon: Icons.copy_rounded, - onTap: () { - copyToClipboard( - value: filteringProvider.filtering!.userRules[index], - successMessage: AppLocalizations.of(context)!.copiedClipboard, - ); - Navigator.pop(context); - } - ), - ], - child: CustomListTile( - onLongPress: () => showDialog( - context: context, - builder: (context) => OptionsModal( - options: [ - MenuOption( - title: AppLocalizations.of(context)!.copyClipboard, - icon: Icons.copy_rounded, - action: () => copyToClipboard( - value: filteringProvider.filtering!.userRules[index], - successMessage: AppLocalizations.of(context)!.copiedClipboard, - ) - ) - ] - ) - ), - title: filteringProvider.filtering!.userRules[index], - subtitleWidget: generateSubtitle(filteringProvider.filtering!.userRules[index]), - trailing: IconButton( - onPressed: () => onRemoveCustomRule(filteringProvider.filtering!.userRules[index]), - icon: const Icon(Icons.delete), - tooltip: AppLocalizations.of(context)!.delete, - ), - ), - ), - ), - ) - ], - ), - ), - ], - ); - - case LoadStatus.error: - return SizedBox.expand( - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - mainAxisSize: MainAxisSize.max, - children: [ - Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - const Icon( - Icons.error, - color: Colors.red, - size: 50, - ), - const SizedBox(height: 30), - Text( - AppLocalizations.of(context)!.filtersNotLoaded, - style: TextStyle( - fontSize: 22, - color: Theme.of(context).colorScheme.onSurfaceVariant, - ), - ) - ], - ), - ], - ), - ); - - default: - return const SizedBox(); - } - } + } return Scaffold( appBar: AppBar( @@ -334,7 +83,7 @@ class FiltersTripleColumn extends StatelessWidget { IconButton( onPressed: () async { final result = await filteringProvider.fetchFilters(); - if (result == false) { + if (result == false && context.mounted) { showSnacbkar( appConfigProvider: appConfigProvider, label: AppLocalizations.of(context)!.errorLoadFilters, @@ -348,7 +97,258 @@ class FiltersTripleColumn extends StatelessWidget { ...actions ], ), - body: content(), + body: Builder( + builder: (context) { + switch (filteringProvider.loadStatus) { + case LoadStatus.loading: + return Row( + mainAxisAlignment: MainAxisAlignment.center, + mainAxisSize: MainAxisSize.max, + children: [ + Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const CircularProgressIndicator(), + const SizedBox(height: 30), + Text( + AppLocalizations.of(context)!.loadingFilters, + style: TextStyle( + fontSize: 22, + color: Theme.of(context).colorScheme.onSurfaceVariant, + ), + ) + ], + ), + ], + ); + + case LoadStatus.loaded: + return Row( + children: [ + Expanded( + flex: 1, + child: Column( + children: [ + Padding( + padding: const EdgeInsets.all(16), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + AppLocalizations.of(context)!.whitelists, + style: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.w500 + ), + ), + AddFiltersButton( + type: 'whitelist', + widget: (fn) => IconButton( + onPressed: fn, + icon: const Icon(Icons.add_rounded), + tooltip: AppLocalizations.of(context)!.addWhitelist, + ), + ) + ], + ), + ), + Expanded( + child: ListView.builder( + itemCount: filteringProvider.filtering!.whitelistFilters.length, + itemBuilder: (context, index) => ListOptionsMenu( + list: filteringProvider.filtering!.whitelistFilters[index], + listType: 'whitelist', + child: CustomListTile( + title: filteringProvider.filtering!.whitelistFilters[index].name, + subtitle: "${intFormat(filteringProvider.filtering!.whitelistFilters[index].rulesCount, Platform.localeName)} ${AppLocalizations.of(context)!.enabledRules}", + trailing: Icon( + filteringProvider.filtering!.whitelistFilters[index].enabled == true + ? Icons.check_circle_rounded + : Icons.cancel, + color: filteringProvider.filtering!.whitelistFilters[index].enabled == true + ? appConfigProvider.useThemeColorForStatus == true + ? Theme.of(context).colorScheme.primary + : Colors.green + : appConfigProvider.useThemeColorForStatus == true + ? Colors.grey + : Colors.red + ), + onTap: () => onOpenDetailsModal(filteringProvider.filtering!.whitelistFilters[index], 'whitelist'), + ), + ), + ), + ) + ], + ), + ), + Expanded( + flex: 1, + child: Column( + children: [ + Padding( + padding: const EdgeInsets.all(16), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + AppLocalizations.of(context)!.blacklists, + style: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.w500 + ), + ), + AddFiltersButton( + type: 'blacklist', + widget: (fn) => IconButton( + onPressed: fn, + icon: const Icon(Icons.add_rounded), + tooltip: AppLocalizations.of(context)!.addBlacklist, + ) + ) + ], + ), + ), + Expanded( + child: ListView.builder( + itemCount: filteringProvider.filtering!.filters.length, + itemBuilder: (context, index) => ListOptionsMenu( + list: filteringProvider.filtering!.filters[index], + listType: 'blacklist', + child: CustomListTile( + title: filteringProvider.filtering!.filters[index].name, + subtitle: "${intFormat(filteringProvider.filtering!.filters[index].rulesCount, Platform.localeName)} ${AppLocalizations.of(context)!.enabledRules}", + trailing: Icon( + filteringProvider.filtering!.filters[index].enabled == true + ? Icons.check_circle_rounded + : Icons.cancel, + color: filteringProvider.filtering!.filters[index].enabled == true + ? appConfigProvider.useThemeColorForStatus == true + ? Theme.of(context).colorScheme.primary + : Colors.green + : appConfigProvider.useThemeColorForStatus == true + ? Colors.grey + : Colors.red + ), + onTap: () => onOpenDetailsModal(filteringProvider.filtering!.filters[index], 'blacklist'), + ), + ), + ), + ) + ], + ), + ), + Expanded( + flex: 1, + child: Column( + children: [ + Padding( + padding: const EdgeInsets.all(16), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + AppLocalizations.of(context)!.customRules, + style: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.w500 + ), + ), + AddFiltersButton( + type: '', + widget: (fn) => IconButton( + onPressed: fn, + icon: const Icon(Icons.add_rounded), + tooltip: AppLocalizations.of(context)!.addCustomRule, + ) + ) + ], + ), + ), + Expanded( + child: ListView.builder( + itemCount: filteringProvider.filtering!.userRules.length, + itemBuilder: (context, index) => ContextMenuArea( + builder: (context) => [ + CustomListTile( + title: AppLocalizations.of(context)!.copyClipboard, + icon: Icons.copy_rounded, + onTap: () { + copyToClipboard( + value: filteringProvider.filtering!.userRules[index], + successMessage: AppLocalizations.of(context)!.copiedClipboard, + ); + Navigator.pop(context); + } + ), + ], + child: CustomListTile( + onLongPress: () => showDialog( + context: context, + builder: (context) => OptionsModal( + options: [ + MenuOption( + title: AppLocalizations.of(context)!.copyClipboard, + icon: Icons.copy_rounded, + action: () => copyToClipboard( + value: filteringProvider.filtering!.userRules[index], + successMessage: AppLocalizations.of(context)!.copiedClipboard, + ) + ) + ] + ) + ), + title: filteringProvider.filtering!.userRules[index], + subtitleWidget: generateSubtitle(filteringProvider.filtering!.userRules[index]), + trailing: IconButton( + onPressed: () => onRemoveCustomRule(filteringProvider.filtering!.userRules[index]), + icon: const Icon(Icons.delete), + tooltip: AppLocalizations.of(context)!.delete, + ), + ), + ), + ), + ) + ], + ), + ), + ], + ); + + case LoadStatus.error: + return SizedBox.expand( + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + mainAxisSize: MainAxisSize.max, + children: [ + Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const Icon( + Icons.error, + color: Colors.red, + size: 50, + ), + const SizedBox(height: 30), + Text( + AppLocalizations.of(context)!.filtersNotLoaded, + style: TextStyle( + fontSize: 22, + color: Theme.of(context).colorScheme.onSurfaceVariant, + ), + ) + ], + ), + ], + ), + ); + + default: + return const SizedBox(); + } + }, + ) ); } } \ No newline at end of file diff --git a/lib/screens/logs/configuration/config_widgets.dart b/lib/screens/logs/configuration/config_widgets.dart index 44523f3..2d70285 100644 --- a/lib/screens/logs/configuration/config_widgets.dart +++ b/lib/screens/logs/configuration/config_widgets.dart @@ -11,8 +11,8 @@ class LogsConfigOptions extends StatelessWidget { final bool anonymizeClientIp; final void Function(bool) updateAnonymizeClientIp; final List retentionItems; - final String? retentionTime; - final void Function(String?) updateRetentionTime; + final double? retentionTime; + final void Function(double?) updateRetentionTime; final void Function() onClear; final void Function() onConfirm; @@ -130,14 +130,12 @@ class LogsConfigOptions extends StatelessWidget { Padding( padding: const EdgeInsets.symmetric(horizontal: 24), child: DropdownButtonFormField( - items: retentionItems.map>((item) { - return DropdownMenuItem( - value: item.value.toString(), - child: Text(item.label), - ); - }).toList(), + items: retentionItems.map((item) => DropdownMenuItem( + value: item.value, + child: Text(item.label), + )).toList(), value: retentionTime, - onChanged: (value) => updateRetentionTime(value), + onChanged: (value) => updateRetentionTime(value as double), decoration: InputDecoration( border: const OutlineInputBorder( borderRadius: BorderRadius.all( diff --git a/lib/screens/logs/configuration/logs_config_modal.dart b/lib/screens/logs/configuration/logs_config_modal.dart index 698348c..8db61ba 100644 --- a/lib/screens/logs/configuration/logs_config_modal.dart +++ b/lib/screens/logs/configuration/logs_config_modal.dart @@ -79,7 +79,7 @@ class LogsConfigModalWidget extends StatefulWidget { class _LogsConfigModalWidgetState extends State { bool generalSwitch = false; bool anonymizeClientIp = false; - String? retentionTime = ""; + double? retentionTime; List retentionItems = []; @@ -101,8 +101,10 @@ class _LogsConfigModalWidgetState extends State { setState(() { generalSwitch = result['data']['enabled']; anonymizeClientIp = result['data']['anonymize_client_ip']; - retentionTime = result['data']['interval'].toString(); - loadStatus = LoadStatus.loading; + retentionTime = result['data']['interval'] != null + ? double.parse(result['data']['interval'].toString()) + : null; + loadStatus = LoadStatus.loaded; }); } else { @@ -191,7 +193,7 @@ class _LogsConfigModalWidgetState extends State { onClear: () => widget.onClear(), onConfirm: () => widget.onConfirm({ "enabled": generalSwitch, - "interval": double.parse(retentionTime!), + "interval": retentionTime, "anonymize_client_ip": anonymizeClientIp }) ); @@ -235,7 +237,7 @@ class _LogsConfigModalWidgetState extends State { onClear: () => widget.onClear(), onConfirm: () => widget.onConfirm({ "enabled": generalSwitch, - "interval": double.parse(retentionTime!), + "interval": retentionTime, "anonymize_client_ip": anonymizeClientIp }) );