From f02406cf9d138331937ac776ff05984cc3ab51a7 Mon Sep 17 00:00:00 2001 From: Juan Gilsanz Polo Date: Thu, 2 Nov 2023 01:37:59 +0100 Subject: [PATCH 1/3] Theme changes --- lib/config/theme.dart | 94 ++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 59 deletions(-) diff --git a/lib/config/theme.dart b/lib/config/theme.dart index 7391677..a78a14a 100644 --- a/lib/config/theme.dart +++ b/lib/config/theme.dart @@ -1,64 +1,7 @@ import 'package:flutter/material.dart'; -ThemeData lightTheme(ColorScheme? dynamicColorScheme) => ThemeData( +final baseTheme = ThemeData( useMaterial3: true, - colorScheme: dynamicColorScheme, - snackBarTheme: SnackBarThemeData( - behavior: SnackBarBehavior.floating, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(5) - ), - elevation: 4, - ), - brightness: Brightness.light, listTileTheme: ListTileThemeData( - tileColor: Colors.transparent, - textColor: dynamicColorScheme != null ? dynamicColorScheme.onSurfaceVariant : const Color.fromRGBO(117, 117, 117, 1), - iconColor: dynamicColorScheme != null ? dynamicColorScheme.onSurfaceVariant : const Color.fromRGBO(117, 117, 117, 1), - ), - androidOverscrollIndicator: AndroidOverscrollIndicator.stretch, -); - -ThemeData darkTheme(ColorScheme? dynamicColorScheme) => ThemeData( - useMaterial3: true, - colorScheme: dynamicColorScheme, - snackBarTheme: SnackBarThemeData( - behavior: SnackBarBehavior.floating, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(5) - ), - elevation: 4, - ), - brightness: Brightness.dark, - listTileTheme: ListTileThemeData( - tileColor: Colors.transparent, - textColor: dynamicColorScheme != null ? dynamicColorScheme.onSurfaceVariant : const Color.fromRGBO(187, 187, 187, 1), - iconColor: dynamicColorScheme != null ? dynamicColorScheme.onSurfaceVariant : const Color.fromRGBO(187, 187, 187, 1), - ), - androidOverscrollIndicator: AndroidOverscrollIndicator.stretch, -); - -ThemeData lightThemeOldVersions(MaterialColor primaryColor) => ThemeData( - useMaterial3: true, - colorSchemeSeed: primaryColor, - snackBarTheme: SnackBarThemeData( - behavior: SnackBarBehavior.floating, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(5) - ), - elevation: 4, - ), - listTileTheme: const ListTileThemeData( - tileColor: Colors.transparent, - textColor: Color.fromRGBO(117, 117, 117, 1), - iconColor: Color.fromRGBO(117, 117, 117, 1), - ), - brightness: Brightness.light, - androidOverscrollIndicator: AndroidOverscrollIndicator.stretch -); - -ThemeData darkThemeOldVersions(MaterialColor primaryColor) => ThemeData( - useMaterial3: true, - colorSchemeSeed: primaryColor, snackBarTheme: SnackBarThemeData( contentTextStyle: const TextStyle( color: Colors.white @@ -69,11 +12,44 @@ ThemeData darkThemeOldVersions(MaterialColor primaryColor) => ThemeData( ), elevation: 4, ), +); + +ThemeData lightTheme(ColorScheme? dynamicColorScheme) => baseTheme.copyWith( + colorScheme: dynamicColorScheme, + brightness: Brightness.light, + listTileTheme: ListTileThemeData( + tileColor: Colors.transparent, + textColor: dynamicColorScheme != null ? dynamicColorScheme.onSurfaceVariant : const Color.fromRGBO(117, 117, 117, 1), + iconColor: dynamicColorScheme != null ? dynamicColorScheme.onSurfaceVariant : const Color.fromRGBO(117, 117, 117, 1), + ), +); + +ThemeData darkTheme(ColorScheme? dynamicColorScheme) => baseTheme.copyWith( + colorScheme: dynamicColorScheme, + brightness: Brightness.dark, + listTileTheme: ListTileThemeData( + tileColor: Colors.transparent, + textColor: dynamicColorScheme != null ? dynamicColorScheme.onSurfaceVariant : const Color.fromRGBO(187, 187, 187, 1), + iconColor: dynamicColorScheme != null ? dynamicColorScheme.onSurfaceVariant : const Color.fromRGBO(187, 187, 187, 1), + ), +); + +ThemeData lightThemeOldVersions(MaterialColor primaryColor) => baseTheme.copyWith( + colorScheme: ColorScheme.fromSeed(seedColor: primaryColor), + listTileTheme: const ListTileThemeData( + tileColor: Colors.transparent, + textColor: Color.fromRGBO(117, 117, 117, 1), + iconColor: Color.fromRGBO(117, 117, 117, 1), + ), + brightness: Brightness.light, +); + +ThemeData darkThemeOldVersions(MaterialColor primaryColor) => baseTheme.copyWith( + colorScheme: ColorScheme.fromSeed(seedColor: primaryColor), listTileTheme: const ListTileThemeData( tileColor: Colors.transparent, textColor: Color.fromRGBO(187, 187, 187, 1), iconColor: Color.fromRGBO(187, 187, 187, 1), ), brightness: Brightness.dark, - androidOverscrollIndicator: AndroidOverscrollIndicator.stretch ); \ No newline at end of file From 0e6cde57f00790ad8533243ca50115c549d8a917 Mon Sep 17 00:00:00 2001 From: Juan Gilsanz Polo Date: Thu, 2 Nov 2023 18:26:50 +0100 Subject: [PATCH 2/3] Revert theme changes --- lib/config/theme.dart | 94 +++++++++++++++++++++++++++---------------- 1 file changed, 59 insertions(+), 35 deletions(-) diff --git a/lib/config/theme.dart b/lib/config/theme.dart index a78a14a..7391677 100644 --- a/lib/config/theme.dart +++ b/lib/config/theme.dart @@ -1,7 +1,64 @@ import 'package:flutter/material.dart'; -final baseTheme = ThemeData( +ThemeData lightTheme(ColorScheme? dynamicColorScheme) => ThemeData( useMaterial3: true, + colorScheme: dynamicColorScheme, + snackBarTheme: SnackBarThemeData( + behavior: SnackBarBehavior.floating, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(5) + ), + elevation: 4, + ), + brightness: Brightness.light, listTileTheme: ListTileThemeData( + tileColor: Colors.transparent, + textColor: dynamicColorScheme != null ? dynamicColorScheme.onSurfaceVariant : const Color.fromRGBO(117, 117, 117, 1), + iconColor: dynamicColorScheme != null ? dynamicColorScheme.onSurfaceVariant : const Color.fromRGBO(117, 117, 117, 1), + ), + androidOverscrollIndicator: AndroidOverscrollIndicator.stretch, +); + +ThemeData darkTheme(ColorScheme? dynamicColorScheme) => ThemeData( + useMaterial3: true, + colorScheme: dynamicColorScheme, + snackBarTheme: SnackBarThemeData( + behavior: SnackBarBehavior.floating, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(5) + ), + elevation: 4, + ), + brightness: Brightness.dark, + listTileTheme: ListTileThemeData( + tileColor: Colors.transparent, + textColor: dynamicColorScheme != null ? dynamicColorScheme.onSurfaceVariant : const Color.fromRGBO(187, 187, 187, 1), + iconColor: dynamicColorScheme != null ? dynamicColorScheme.onSurfaceVariant : const Color.fromRGBO(187, 187, 187, 1), + ), + androidOverscrollIndicator: AndroidOverscrollIndicator.stretch, +); + +ThemeData lightThemeOldVersions(MaterialColor primaryColor) => ThemeData( + useMaterial3: true, + colorSchemeSeed: primaryColor, + snackBarTheme: SnackBarThemeData( + behavior: SnackBarBehavior.floating, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(5) + ), + elevation: 4, + ), + listTileTheme: const ListTileThemeData( + tileColor: Colors.transparent, + textColor: Color.fromRGBO(117, 117, 117, 1), + iconColor: Color.fromRGBO(117, 117, 117, 1), + ), + brightness: Brightness.light, + androidOverscrollIndicator: AndroidOverscrollIndicator.stretch +); + +ThemeData darkThemeOldVersions(MaterialColor primaryColor) => ThemeData( + useMaterial3: true, + colorSchemeSeed: primaryColor, snackBarTheme: SnackBarThemeData( contentTextStyle: const TextStyle( color: Colors.white @@ -12,44 +69,11 @@ final baseTheme = ThemeData( ), elevation: 4, ), -); - -ThemeData lightTheme(ColorScheme? dynamicColorScheme) => baseTheme.copyWith( - colorScheme: dynamicColorScheme, - brightness: Brightness.light, - listTileTheme: ListTileThemeData( - tileColor: Colors.transparent, - textColor: dynamicColorScheme != null ? dynamicColorScheme.onSurfaceVariant : const Color.fromRGBO(117, 117, 117, 1), - iconColor: dynamicColorScheme != null ? dynamicColorScheme.onSurfaceVariant : const Color.fromRGBO(117, 117, 117, 1), - ), -); - -ThemeData darkTheme(ColorScheme? dynamicColorScheme) => baseTheme.copyWith( - colorScheme: dynamicColorScheme, - brightness: Brightness.dark, - listTileTheme: ListTileThemeData( - tileColor: Colors.transparent, - textColor: dynamicColorScheme != null ? dynamicColorScheme.onSurfaceVariant : const Color.fromRGBO(187, 187, 187, 1), - iconColor: dynamicColorScheme != null ? dynamicColorScheme.onSurfaceVariant : const Color.fromRGBO(187, 187, 187, 1), - ), -); - -ThemeData lightThemeOldVersions(MaterialColor primaryColor) => baseTheme.copyWith( - colorScheme: ColorScheme.fromSeed(seedColor: primaryColor), - listTileTheme: const ListTileThemeData( - tileColor: Colors.transparent, - textColor: Color.fromRGBO(117, 117, 117, 1), - iconColor: Color.fromRGBO(117, 117, 117, 1), - ), - brightness: Brightness.light, -); - -ThemeData darkThemeOldVersions(MaterialColor primaryColor) => baseTheme.copyWith( - colorScheme: ColorScheme.fromSeed(seedColor: primaryColor), listTileTheme: const ListTileThemeData( tileColor: Colors.transparent, textColor: Color.fromRGBO(187, 187, 187, 1), iconColor: Color.fromRGBO(187, 187, 187, 1), ), brightness: Brightness.dark, + androidOverscrollIndicator: AndroidOverscrollIndicator.stretch ); \ No newline at end of file From e5a971f3a3afadac3b199ccbe03845d663ad5568 Mon Sep 17 00:00:00 2001 From: Juan Gilsanz Polo Date: Thu, 2 Nov 2023 18:26:58 +0100 Subject: [PATCH 3/3] 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 }) );