mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-05-22 01:34:25 +00:00
Added option to hide charts with zero value
This commit is contained in:
parent
5fc90615f1
commit
786b14e9ba
8 changed files with 223 additions and 99 deletions
|
@ -1,7 +1,10 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:adguard_home_manager/widgets/line_chart.dart';
|
||||
|
||||
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
||||
|
||||
class HomeChart extends StatelessWidget {
|
||||
final List<int> data;
|
||||
final String label;
|
||||
|
@ -20,6 +23,8 @@ class HomeChart extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
||||
|
||||
bool isEmpty = true;
|
||||
for (int item in data) {
|
||||
if (item > 0) {
|
||||
|
@ -28,79 +33,95 @@ class HomeChart extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Column(
|
||||
if (!(appConfigProvider.hideZeroValues == true && isEmpty == true)) {
|
||||
return Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: !isEmpty ? 10 : 15
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: !isEmpty ? 10 : 15
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500
|
||||
),
|
||||
),
|
||||
!isEmpty
|
||||
? Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
primaryValue,
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500
|
||||
),
|
||||
),
|
||||
Text(
|
||||
secondaryValue,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: color
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
: Row(
|
||||
children: [
|
||||
Text(
|
||||
primaryValue,
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
"($secondaryValue)",
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: color
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
!isEmpty
|
||||
? Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
primaryValue,
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500
|
||||
),
|
||||
),
|
||||
Text(
|
||||
secondaryValue,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: color
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
: Row(
|
||||
children: [
|
||||
Text(
|
||||
primaryValue,
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
"($secondaryValue)",
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: color
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
if (!isEmpty) SizedBox(
|
||||
width: double.maxFinite,
|
||||
height: 150,
|
||||
child: CustomLineChart(
|
||||
data: data,
|
||||
color: color,
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (!isEmpty) SizedBox(
|
||||
width: double.maxFinite,
|
||||
height: 150,
|
||||
child: CustomLineChart(
|
||||
data: data,
|
||||
color: color,
|
||||
)
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Divider(
|
||||
thickness: 1,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
);
|
||||
);
|
||||
}
|
||||
else {
|
||||
return const SizedBox();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -65,13 +65,6 @@ class Home extends StatelessWidget {
|
|||
secondaryValue: "${doubleFormat(serversProvider.serverStatus.data!.stats.avgProcessingTime*1000, Platform.localeName)} ms",
|
||||
color: Colors.blue,
|
||||
),
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Divider(
|
||||
thickness: 1,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
HomeChart(
|
||||
data: serversProvider.serverStatus.data!.stats.blockedFiltering,
|
||||
|
@ -80,13 +73,6 @@ class Home extends StatelessWidget {
|
|||
secondaryValue: "${doubleFormat((serversProvider.serverStatus.data!.stats.numBlockedFiltering/serversProvider.serverStatus.data!.stats.numDnsQueries)*100, Platform.localeName)}%",
|
||||
color: Colors.red,
|
||||
),
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Divider(
|
||||
thickness: 1,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
HomeChart(
|
||||
data: serversProvider.serverStatus.data!.stats.replacedSafebrowsing,
|
||||
|
@ -95,13 +81,6 @@ class Home extends StatelessWidget {
|
|||
secondaryValue: "${doubleFormat((serversProvider.serverStatus.data!.stats.numReplacedSafebrowsing/serversProvider.serverStatus.data!.stats.numDnsQueries)*100, Platform.localeName)}%",
|
||||
color: Colors.green,
|
||||
),
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Divider(
|
||||
thickness: 1,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
HomeChart(
|
||||
data: serversProvider.serverStatus.data!.stats.replacedParental,
|
||||
|
@ -110,13 +89,6 @@ class Home extends StatelessWidget {
|
|||
secondaryValue: "${doubleFormat((serversProvider.serverStatus.data!.stats.numReplacedParental/serversProvider.serverStatus.data!.stats.numDnsQueries)*100, Platform.localeName)}%",
|
||||
color: Colors.orange,
|
||||
),
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Divider(
|
||||
thickness: 1,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
TopItems(
|
||||
label: AppLocalizations.of(context)!.topQueriedDomains,
|
||||
|
|
65
lib/screens/settings/general_settings.dart
Normal file
65
lib/screens/settings/general_settings.dart
Normal file
|
@ -0,0 +1,65 @@
|
|||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
import 'package:adguard_home_manager/screens/settings/custom_list_tile.dart';
|
||||
|
||||
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
||||
|
||||
class GeneralSettings extends StatelessWidget {
|
||||
const GeneralSettings({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
||||
|
||||
Future updateHideZeroValues(bool newStatus) async {
|
||||
final result = await appConfigProvider.setHideZeroValues(newStatus);
|
||||
if (result == true) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.settingsUpdatedSuccessfully),
|
||||
backgroundColor: Colors.green,
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.cannotUpdateSettings),
|
||||
backgroundColor: Colors.red,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(AppLocalizations.of(context)!.generalSettings) ,
|
||||
),
|
||||
body: ListView(
|
||||
children: [
|
||||
CustomListTile(
|
||||
leadingIcon: Icons.exposure_zero_rounded,
|
||||
label: AppLocalizations.of(context)!.hideZeroValues,
|
||||
description: AppLocalizations.of(context)!.hideZeroValuesDescription,
|
||||
trailing: Switch(
|
||||
value: appConfigProvider.hideZeroValues,
|
||||
onChanged: updateHideZeroValues,
|
||||
activeColor: Theme.of(context).primaryColor,
|
||||
),
|
||||
onTap: () => updateHideZeroValues(!appConfigProvider.hideZeroValues),
|
||||
padding: const EdgeInsets.only(
|
||||
top: 10,
|
||||
bottom: 10,
|
||||
left: 20,
|
||||
right: 10
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
import 'package:adguard_home_manager/screens/settings/advanced_setings.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
@ -7,7 +6,8 @@ import 'package:adguard_home_manager/screens/settings/theme_modal.dart';
|
|||
import 'package:adguard_home_manager/screens/settings/custom_list_tile.dart';
|
||||
import 'package:adguard_home_manager/screens/settings/section_label.dart';
|
||||
import 'package:adguard_home_manager/screens/servers/servers.dart';
|
||||
import 'package:adguard_home_manager/screens/app_logs/app_logs.dart';
|
||||
import 'package:adguard_home_manager/screens/settings/advanced_setings.dart';
|
||||
import 'package:adguard_home_manager/screens/settings/general_settings.dart';
|
||||
|
||||
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
||||
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
||||
|
@ -79,6 +79,18 @@ class Settings extends StatelessWidget {
|
|||
),
|
||||
CustomListTile(
|
||||
leadingIcon: Icons.settings,
|
||||
label: AppLocalizations.of(context)!.generalSettings,
|
||||
description: AppLocalizations.of(context)!.generalSettingsDescription,
|
||||
onTap: () => {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const GeneralSettings()
|
||||
)
|
||||
)
|
||||
},
|
||||
),
|
||||
CustomListTile(
|
||||
leadingIcon: Icons.build_outlined,
|
||||
label: AppLocalizations.of(context)!.advancedSettings,
|
||||
description: AppLocalizations.of(context)!.advancedSetupDescription,
|
||||
onTap: () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue